

//when doc is ready
$(document).ready(function(){

  //fade in content
  $("#content").hide().fadeIn(500);

  //hilite current link in navbar
  $("*").find("a").each(function(){
		if(window.location.href==this.href ){
			$(this).addClass("current")
		}
	});
  
  //make rollovers rollable
  $(".rollme").hover(
		function() {
  			this.src = this.src.replace(".png","_roll.png");
  			this.src = this.src.replace(".jpg","_roll.jpg");
 		},
 		function(){
  			this.src = this.src.replace("_roll.png",".png");
  			this.src = this.src.replace("_roll.jpg",".jpg");
 		}
);
  
  // make FAQ questions expandable
  $("*").find("a.question").click( faqOpen ) ;
  
  
});


//expand FAQ question
function faqOpen(eventObject){
	
	//find next 
	$(this).next().toggle();
	
	return false;
}


// map / wheel highlight function
 var sectionName = null;
 var timeOut=null;
 function maphilite(button, hilite){
		
	if(savedSrc==null){
		var savedSrc = $("#bigwheeldiv").css("background-image");
		sectionName = savedSrc.split('/').pop().split('.')[0];
	}
	
 	if(hilite){
		clearTimeout(timeOut);
		if (sectionName != button){ //don't highlight button we're on
			var imgUrl = 'url(common/bigwheel/roll_'+ button +'.png)';
			$("#bigwheeldiv ul").css('background-image',imgUrl);
		}
 	}
	else{
	//restore old image source on rollout
		timeOut = setTimeout(restoreSrc, 100);
	}
	
 }
 
function restoreSrc(){
	$("#bigwheeldiv ul").css('background-image','none');
 }
 
//preload images 
$(document).ready(function(){
	setTimeout(function(){
		imageList = new Array('roll_green.png','roll_managed.png',
							  'roll_savings.png','roll_buy.png',
							  'roll_products.png','roll_calculator.png');
		for (i=0;i<imageList.length;i++){
			image = new Image();
			image.src = "common/bigwheel/"+imageList[i];
		}
	},1000);
});


//set calculator links to open js instead
$(document).ready(function(){
  $("*").find("a,area").each(function(){
		//alert(this.href);
		if(this.href.indexOf('savings_calculator.php')>-1)
			$(this).click(openCalculator);
		if(this.href.indexOf('video.php')>-1)
			$(this).click(openVideo);
		if(this.href.indexOf('videoaib.php')>-1)
			$(this).click(openVideoaib);

	})
});

//open modal calculator form
function openCalculator() {
		url='savings_calculator.php';
		
		// http://www.ericmmartin.com/projects/simplemodal/
		$.modal('<iframe src="' + url + '" width="630" height="530" style="border:0" scrolling="no">', {
			position: ["10%","20%"],
			closeHTML: "",
			overlayId: 'calculator-overlay',
			containerId: 'calculator-container'
		});
		
	return false;
}

function openVideo() {
		url='video.php?video=gen';
		
		// http://www.ericmmartin.com/projects/simplemodal/
		$.modal('<iframe src="' + url + '" width="720" height="406" style="border:0" scrolling="no">', {
			overlayId: 'calculator-overlay',
			containerId: 'video-container'
		});
		
	return false;
}
function openVideoaib() {
		url='videoaib.php?video=aib';
		
		// http://www.ericmmartin.com/projects/simplemodal/
		$.modal('<iframe src="' + url + '" width="720" height="406" style="border:0" scrolling="no">', {
			overlayId: 'calculator-overlay',
			containerId: 'video-container'
		});
		
	return false;
}
