/* Onload Functions 
---------------------------*/

$(function(){
		   
	$("label:has(:text) :text").each(function() {
		var $this = $(this);
		if($this.val() != "") {
			$this.parent().addClass("hide")
		}
	});

	$("#search input, #quick-enquiry input, #quick-enquiry textarea, .text").bind("click", function(){
     		
		var id = $(this).attr("id");
		$("[for='"+ id +"']").addClass('hide');
   		
	  	$(this).bind("blur", function(){
  			if ($(this).val() == "") $("[for='"+id+"']").removeClass('hide');
  		});
   });
	if($("#search input").val() == "") 
	{
		hidelabel($(this));
	}
	if($("#quick-enquiry input").val() == "") 
	{
		hidelabel($(this));
	}
	if($("#quick-enquiry textarea").val() == "") 
	{
		hidelabel($(this));
	}
	
	var timer, hidepanel = function() { 
		$("#navigation a.active").removeClass("active");
		$(".nav-panel").hide().parent().hide();
		$("#flash").css("visibility", "visible");
	};
	
	if($("#ctl00_ContentPlaceHolder1_SearchBy_txtKeywordSearch").val() != "") {
		$(this).prev().hide();
	}
	/*
	$("#ctl00_ContentPlaceHolder1_SearchBy_txtKeywordSearch").bind("keydown", function(e) {
		var $this = $(this);
		if($this != "" && e.keyCode == 13) {
			$("form:eq(0)").submit();
			$this.prev().hide();
		}
		
	});
	*/
	$("#navigation a").hover(function() {
			clearTimeout(timer);			
			$(".nav-panel").hide();
			$("#navigation a.active").removeClass("active");
			
			var $this = $(this).addClass("active");
			var rel = $this.attr("rel");
			
			$("#flash").css("visibility", "hidden");			
			$("#"+ rel).show().parent().show();
			
		}, function() {
			
			timer = setTimeout(hidepanel, 500);
	});
	
	$("#masthead").bind("mouseover", function() {
		hidepanel();
	});
	
	$(".nav-panel").hover(function() {
		clearTimeout(timer);
	}, function() {
		hidepanel();
	});
	
	$("#tabs a").click(function(e) {
		var $this = $(this);
		var index = $("#tabs a").removeClass("active").index(this);
		
		e.preventDefault();
		$this.addClass("active");
		$(".feat .row").hide().eq(index).show();
	});
	
	$(".new").click(function() {
		var href = $(this).next().find("a").attr("href");
		window.location = href;
	});
	
	$("#bookmark").click(function(e) {
		e.preventDefault();
		title = document.title;
		url = window.location.href;
		
		if (window.sidebar) { // Mozilla Firefox Bookmark
			window.sidebar.addPanel(title, url,"");
		} else if( window.external ) { // IE Favorite
			window.external.AddFavorite( url, title); }
		else {
			alert("Please press ctrl + D/cmd + D to bookmark this page!");
		}
	});
	
});

var flashvars = {};
var params = {
  menu: "false"
};
var attributes = {
  id: "flash",
  name: "flash"
};

$(document).ready(function() {
Cufon.replace('h2,h3,#welcome p,.search-result #content h2');

});

