// JavaScript Functions for DBDnet.com - Case Studies //

var currentPanel = 1;

var thisStudy = "";
var thisAnchor = "";
if(location.hash != null){
	thisStudy = location.hash.substring(1);
}

var haveResetRollovers = false;

$(document).ready(function(){
	setButtonNavClicks();
	
	//check for specific case study request
	if(thisStudy != null && thisStudy.length > 0){
		switch(thisStudy){
			case "goalrilla-basketball":
				showPanel(2);
				$('#casestudytwo').jScrollPane({scrollbarOnLeft:true});
				break;
			case "atlas-moving":
				showPanel(3);
				$('#casestudythree').jScrollPane({scrollbarOnLeft:true});
				break;
			case "trophy-ridge-archery":
				showPanel(4);
				$('#casestudyfour').jScrollPane({scrollbarOnLeft:true});
				break;
			default:
				showPanel(1);
				location.hash = "woodplay-playsets";
				$('#casestudyone').jScrollPane({scrollbarOnLeft:true});
				break;
		}
	}else{
		showPanel(1);
		location.hash = "woodplay-playsets";
		$('#casestudyone').jScrollPane({scrollbarOnLeft:true});
	}	
});



function setButtonNavClicks(){
	$(".nowmenu a").eq(0).click(function(){
		//case study 1
		if (currentPanel != 1){
			showPanel(1);
			$('#casestudyone').jScrollPane({scrollbarOnLeft:true});
			location.hash = "woodplay-playsets";
			resetRollovers();
		}
	
	});

	$(".nowmenu a").eq(1).click(function(){
		//case study 2
		if (currentPanel != 2){
			showPanel(2);
			$('#casestudytwo').jScrollPane({scrollbarOnLeft:true});
	        location.hash = "goalrilla-basketball";
			resetRollovers();
		}
	});
	$(".nowmenu a").eq(2).click(function(){
		//case study 3
		if (currentPanel != 3){
			showPanel(3);
			$('#casestudythree').jScrollPane({scrollbarOnLeft:true});
			location.hash = "atlas-moving";
			resetRollovers();
		}
	});
	$(".nowmenu a").eq(3).click(function(){
		//case study 4
		if (currentPanel != 4){
			showPanel(4,true); //true for non-image links
			$('#casestudyfour').jScrollPane({scrollbarOnLeft:true});
			location.hash = "trophy-ridge-archery";
			resetRollovers();
		}
	});
	
}

function showPanel(pnlNum,isNotImage){
		
	//hide any active panels
	$("#nowpanelcontainer").children("div:visible").hide();
	//set new active panel
	$("#nowpanelcontainer").children("div").eq(pnlNum-1).fadeIn("slow");
	
	
	//hide all active buttons
	$(".nowmenu a img[src*=av.]").each(function(index, domElement){
		var $thisDE = $(domElement);
		var imgsrc = $thisDE.attr("src");
		var imgsrcON = imgsrc.replace(/-av/ig,"_nm");
		$thisDE.attr("src", imgsrcON);
	});
	//set this active button
	if(!isNotImage){
		var $thisActiveImage = $(".nowmenu a img").eq(pnlNum-1);
		var thisOnSRC = $thisActiveImage.attr("src").replace(/_nm/ig,"-av").replace(/_hv/ig,"-av");
		$thisActiveImage.attr("src", thisOnSRC);
	}
	
	currentPanel = pnlNum;
	
	//google track
	pageTracker._trackPageview("/case-studies/"+getResolvedName(pnlNum)+"/");
}



function getResolvedName(pnlNum){
	//this function helps resolve a panel number to the proper image button index
	var thisName = "";
	switch (pnlNum){
		case 2:
			thisName = "GoalrillaCaseStudy";
			break;
		case 3:
			thisName = "PuppyCaseStudy";
			break;
		case 4:
			thisName = "TrophyRidgeCaseStudy";
			break;
		default:
			thisName = "WoodplayCaseStudy";
			break;
	}
	return thisName;
}

function resetRollovers(){
	//image rollover code is not applied to the initially activated item
	//on the first panel change, reapply rollovers to ensure that this works
	if (!haveResetRollovers){
		setImageRollovers();
		haveResetRollovers = true;
	}
}