/*
 * @description global code, main execution bliock
 */
 var $j = $j || jQuery.noConflict();
//Main  execution block
$j(document).ready(function(){
	
	var emailHref="mailto:?subject=Thought this might interest you&body=Hi there,%0D%0A%0D%0AI was looking at savings accounts on the HiSAVE website (www.hisave.co.uk) and found a page that might be of interest to you:%0D%0A%0D%0A" + location.href + "%0D%0A%0D%0AHope you find it useful.%0D%0A%0D%0AWarm regards,";
	
	$j("#emailPage").attr("href", emailHref);
	
	selectNavigator();
							
	function selectNavigator(){
		if(document.getElementById("siteNavSelector")){
			$j("#" + (($j("#siteNavSelector").val()).split(",")[0])).addClass("selected");
			if((($j("#siteNavSelector").val()).split(",")).length != 3){
				$j("#" + (($j("#siteNavSelector").val()).split(",")[0]) + "Sub").show();
				$j("#" + (($j("#siteNavSelector").val()).split(",")[1])).addClass("selected");			
			}
		}
	}	
	
	$j("#rollOverLinks a").each(function(){
		var $rlink = $j(this);
		var linkid=$j($rlink).attr("id");
		var contentObj= $j("#" + linkid + "_content");
		$rlink.bind("mouseover", function(){
			$j(contentObj).show();
		}).bind("mouseout", function(){
			$j(contentObj).hide();
		});		
	});
	
	$j(".tabbedProducts").bind("click", function(){
		$j(".tabbedProducts").each(function(){
			$j(this).removeClass("selected");
		});
		$j(".tabbedDetailsSection").each(function(){
			$j(this).hide();
		});
		$j(this).addClass("selected");
		$j("#" + $j(this).attr("id") + "Details").show();
	});
	
	$j(".tabSubLink").bind("click", function(){
		$j("#" + $j(this).attr("id").split("_")[0]).trigger("click");
	});
	
	
	$j("#seeRates").bind("mouseover", function(){
			$j("#rateListModal").show();
		}).bind("mouseout", function(){
			$j("#rateListModal").hide();
		});
	$j("#seeSavingsRates").bind("mouseover", function(){
			$j("#rateListSavingModal").show();
		}).bind("mouseout", function(){
			$j("#rateListSavingModal").hide();
		});
	
	reposition();
	var isProduct = document.getElementById('productBody');
	if(isProduct){
		$j(function() {
			$j('#container > ul').tabs();
		});
	}

	//hide the all of the element with class msg_body
	$j(".msg_body").hide();
		var currentState=1;
		//toggle the componenet with class msg_body
		$j(".msg_head").click(function(){
			$j(this).hasClass("collapsed") ? $j(this).addClass("expanded").removeClass("collapsed") : $j(this).addClass("collapsed").removeClass("expanded");
			$j("#" + $j(this).attr("id") + "Details").slideToggle(50);
		});

	
	//hide the all of the element with class faq_body
	$j(".faq_body").hide();
	var stateClass="";
	$j(".faq_head").click(function(){
		$j(this).hasClass("collapsed") ? $j(this).addClass("expanded").removeClass("collapsed") : $j(this).addClass("collapsed").removeClass("expanded");
		$j(this).next(".faq_body").slideToggle(50);		   	
	});

	if(document.getElementById('faqSection')){
		$j(".faq_body").hide();
		if(location.href.split("#").length>1){
				$j("#" + location.href.split("#")[1]).trigger("click");
		}
	}
	//IE6 background flicker fix
	try {
		if ($j.browser.msie && $j.browser.version < 7) {
			document.execCommand("BackgroundImageCache", false, true);
		}
	} catch(e){}		
});

function reposition(){
	var el = document.getElementById('fixme');
	if(el){
		if( window.XMLHttpRequest) { // IE 6 doesn't implement position fixed nicely...
			if (document.documentElement.scrollTop > 318) {
				el.style.position = 'fixed'; 
				el.style.top = '0';
			} else {
				el.style.position = 'absolute'; 
				el.style.top = 'auto';
			}
		}
		else{
			if (document.body.scrollTop > 318) {
				el.style.top = document.body.scrollTop+10;
			}
			else{
				el.style.top = 'auto';
			}
		}
		
		if(navigator.userAgent.toLowerCase().indexOf('chrome') > -1){
			var offset = 415; 
			var element = document.getElementById('fixme');
			
			if(element) {
				var top = "415";
				try {
					if(document.body.scrollTop > 0) {
						var difference = (document.body.scrollTop + offset);
					} else if(document.documentElement.scrollTop > 0) {
						var difference = (document.documentElement.scrollTop + offset);
					} else {
						var difference = offset;
					}
				} catch(e) {
					var difference = offset;
				}
				difference = difference - top;
				
				if(difference >= 300) {
					element.style.marginTop = difference - 250 + "px";
				} else{
					element.style.marginTop = 0;
				}
			}
		}	
	}
}

