/**
 * Base Javascripts
 *
 * Base Javascripts for Yourchoice
 *
 * jQuery 1.2.6
 *
 * @author		Vincent Lu <vincent@enke.com.au>
 * @copyright	2006-2009 Enke Design
 * @since		2008-11-25 10:51
 * @version		1.1
 */

jQuery(document).ready(function(){
	bindNewWindow();
	formatBreadCrumb();
	hoverFixForIe6();
	bindPrintButton();
	menuHasChildren();
	initiateSearchBox();
    formatHeader();
    formatFooter();
    safariFix();
    openMeterPopUp();
});

function bindNewWindow() {
	jQuery("a[rel='external']").attr("target", "_blank");
}

function formatBreadCrumb() {
	jQuery("#breadcrumb a:not(:last)").after(" > ");
	jQuery("#breadcrumb a:last:not(.keep)").replaceWith(jQuery("#breadcrumb a:last").html());
}

function hoverFixForIe6() {
	if (jQuery.browser.msie && jQuery.browser.version.substr(0,1) == "6") {
		//for navigation menu
		jQuery("#menu ul li").hover(function() {
			jQuery(this).addClass("hover");
		},function(){
			jQuery(this).removeClass("hover");
		});
		//for choice sidebar
		jQuery("#meter-pop-up").hover(function() {
			jQuery("#meter-pop-up dt").show();
			jQuery("#meter-pop-up dd").show();
		},function(){
			jQuery("#meter-pop-up dt").hide();
			jQuery("#meter-pop-up dd").hide();
		});
	}
}

function bindPrintButton() {
	jQuery("#button_print").click(function () {
		window.print();
	});
}

function menuHasChildren() {
	jQuery("#menu ul ul").parent().addClass("has_children");
}

function initiateSearchBox() {
	jQuery("#search #search_text").
		val("Keyword").
		css("color", "#a6a5a7").
		click(function () {
			jQuery(this).
			val((jQuery(this).val()=="Keyword")?"":jQuery(this).val()).
			css("color", "#000");
		})
		.blur(function () {
			jQuery(this).
			val((jQuery(this).val()=="")?"Keyword":jQuery(this).val()).
			css("color", "#a6a5a7");
		});
}

function formatHeader() {
    jQuery("#sitelink ul li").not(":last").after(" | ");
}

function formatFooter() {
    jQuery("#footer_text ul li").not(":last").after(" <span class=\"darkblue\">|</span> ");
}

function safariFix() {
    if (jQuery.browser.safari) {
        jQuery("#search").css("bottom", "2px");
    }
}

// Fix ie6 flicker of background image
try {
  document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}

function openMeterPopUp() {
	jQuery("#meter-pop-up").click(function () {
		jQuery("#meter-pop-up dt").toggleClass("show");
		jQuery("#meter-pop-up dd").toggleClass("show");
	});
}

function hideMeter() {
    jQuery("#meter-pop-up dt").hide();
    jQuery("#meter-pop-up dd").hide();
}