/*
	Community Health Charities 2010
	global js
*/



/*
var chooseFrom = ['image1.png', 'image2.png', 'image3.png'];

function shuffle(a) {
    for (var i = a.length; i > 0; i--) {
		var j = Math.floor(Math.random() * i);
		var temp = a[i - 1];
		a[i - 1] = a[j];
		a[j] = temp;
	}
	return a;
}
*/

		// Clear Search Box
function checkSearchAutocomplete() {
	if ($("#site-search input#search").val().length != 0) {
		$("#site-search label").removeClass("light").hide();
	}
}

$(document).ready(function() {
	
			// active navagation
	$('ul#navigation li a[href^=/'+window.location.href.split('/')[3]+"/"+window.location.href.split('/')[4]+']').addClass('active');
	
			// Adds the class .has-js to <html> if javascript is enabled
	$("html").addClass("has-js");
	
		 	// Adds the class .mac to <html> if OS is Mac OS X
	if ($.client.os == "Mac") {
		$("html").addClass("mac");
	}
		// Adds the class .win to <html> if OS is Windows
	if ($.client.os == "Windows") {
		$("html").addClass("win");
	}
			// Adds the class .moz to <html> if user-agent is mozilla
	if ($.browser.mozilla) {
		$("html").addClass("moz");
	}
			// Adds the class .chrome to <html> if user-agent is chrome
	if ($.client.browser == "Chrome") {
		$("html").addClass("chrome");
	}
		
		 		// Adds the class .safari to <html> if user-agent is safari
	if ($.client.browser == "Safari") {
		$("html").addClass("safari");
	}
		
		  	// Adds the class .webkit to <html> if user-agent is webkit
	if ($.browser.webkit) {
		$("html").addClass("webkit");
	}
			// Adds the class .ipad to <html> if OS is iPad 
	if ($.client.os == "iPad") {
		$("html").addClass("ipad");
	}
			// Adds the class .iphone to <html> if OS is iPhone/iPod Touch 
	if ($.client.os == "iPhone") {
		$("html").addClass("iphone");
	}
	
	 // Adds the class .ie9 to <html> if broswer is MSIE version 9
 	if ($.browser.msie && $.browser.version == 9 ) {
		$("html").addClass("ie9");
	}
	
 	 	// Adds the class .ie8 to <html> if broswer is MSIE version 8
 	if ($.browser.msie && $.browser.version == 8 ) {
		$("html").addClass("ie8");
	}
		
		// Open links in new blank window
	$("a[rel*=external], a[rel*=nofollow]").live("click", function() {
		window.open(this.href);
		return false;
	});
	

/*		// shuffle images
	shuffle(chooseFrom);
	for (var i = 1; i <= 3; i++) {
		$('#shuffle-image' + i).attr('src', chooseFrom[i - 1]);
	}
*/
	
	
		// Close Colorbox
	$(".close-colorbox").live("click", function() {
		$.fn.colorbox.close();
		return false;
  	});
	
	$("a[rel*=youtube-modal]").colorbox({iframe:true, innerWidth:800, innerHeight:480});
		

		// navigation hover transition
	$("ul#navigation li a").hover(function() {
		$(this).stop().animate({backgroundColor: "#a49160"}, 200);
	}, function() {
		$(this).stop().animate({backgroundColor: "#97824a"}, 200);
	});

		// promo list hover transition
	$("ul#promo-list li a").hover(function() {
		$(this).stop().animate({backgroundColor: "#eb403d"}, 200);
	}, function() {
		$(this).stop().animate({backgroundColor: "#e51a38"}, 200);
	});
	
		/* site search */
	if ($("#site-search input#search").length > 0) {
		checkSearchAutocomplete();
		setTimeout ("checkSearchAutocomplete()", 250);
	}
		
	$("#site-search input#search").val() == "";
	$("#site-search input#search").focus(function() {
		if($("#site-search input#search").val() == "") {
			$("#site-search input#search").caret(0,0);
			$("#site-search label").addClass("light");
		}
	});
	
	$("#site-search input#search").keydown(function() {
		if($("#site-search input#search").val() == "") {
			$("#site-search input#search").caret(0,0);
			$("#site-search label").removeClass("light").hide();
		}
	});

	$("#site-search input#search").keyup(function() {
		if($("#site-search input#search").val() == "") {
			$("#site-search input#search").caret(0,0);
			$("#site-search label").addClass("light").fadeIn(150);
		}
	});
	
	$("#site-search input#search").blur(function() {
		if($("#site-search input#search").val() == "") {
			$("#site-search label").removeClass("light").show();
		}
	});
		/* site search - end */

		// hide Safari Mobile address bar
	if ($.client.os == "iPhone") {
		addEventListener("load", function() {
			setTimeout(hideURLbar, 0);
		}, false);

		function hideURLbar() {
			window.scrollTo(0,1);
		}
	}

});

