/***********************************************************************************************************************
DOCUMENT: includes/javascript.js
DEVELOPED BY: Ryan Stemkoski
COMPANY: Zipline Interactive
EMAIL: ryan@gozipline.com
PHONE: 509-321-2849
DATE: 5/12/2009
DESCRIPTION: This document contains general javascript functionality used within the site.  Requires jQuery library
************************************************************************************************************************/
$(document).ready(function() {	
	
	
	$(".presentationButton").mouseover(function(){
		
		//SET THE CURRENT INDEX
		current = $(".presentationButton").index(this);
	
		//IF THE CURRENT ITEM IS NOT ACTIVE UPDATE IT OTHERWISE IGNORE
		if(active != current) {
			image = getOnImage(basedir,current);
			$(".presentationImage:eq(" + current + ")").attr("src",image); 
    		$(this).addClass("presentationButtonOn");
		}
		
    }).mouseout(function(){
	
		//SET THE CURRENT INDEX
		current = $(".presentationButton").index(this);
 
		
		//IF THE CURRENT ITEM IS NOT ACTIVE UPDATE IT OTHERWISE IGNORE
		if(active != current) {
				image = getOffImage(basedir,current);	
			$(".presentationImage:eq(" + current + ")").attr("src",image); 
    		$(this).removeClass("presentationButtonOn");	
	
		}	
		
	});
	
		
	//FUNCTION TO GET ON IMAGE BASED ON ORDER
	function getOnImage(basedir,current) {
		if(current == 0) {
			image = basedir + "images/" + 	"project-and-risk-management-on.gif";
		} else if(current == 1) {
			image = basedir + "images/" + 	"power-on.gif";
		} else if(current == 2) {
			image = basedir + "images/" + 	"automation-on.gif";
		} else if(current == 3) {
			image = basedir + "images/" + 	"instrumentation-and-controls-on.gif";
		} else if(current == 4) {
			image = basedir + "images/" + 	"energy-management-on.gif";
		} else {
			image = null;
		}
		
		return image;
	}
	
	//FUNCTION TO GET OFF IMAGE BASED ON ORDER
	function getOffImage(basedir,current) {
		if(current == 0) {
			image = basedir + "images/" + 	"project-and-risk-management-off.gif";
		} else if(current == 1) {
			image = basedir + "images/" + 	"power-off.gif";
		} else if(current == 2) {
			image = basedir + "images/" + 	"automation-off.gif";
		} else if(current == 3) {
			image = basedir + "images/" + 	"instrumentation-and-controls-off.gif";
		} else if(current == 4) {
			image = basedir + "images/" + 	"energy-management-off.gif";
		} else {
			image = null;
		}
	
		return image;
	}

	
	/********************************************************************************************************************
	HANDLE LOGIN BOX LABELS
	********************************************************************************************************************/	
	$(".presentationButton").click(function() {
	
		//GET THE INDEX OF THE CURRENT SLIDE
		current = $(".presentationButton").index(this);
		
		//IF THE CURRENT ITEM IS NOT OPEN THEN PROCEED
		if(active != current) {
		
			//IF A SLIDE IS ON TURN IT OFF
			if($(this).is(':visible')) {
				$(".presentationSlide").animate({width: 0},200);
				$(".presentationButton").removeClass("presentationButtonOn");
				$(".presentationText").hide();
				
			}
			
			//OPEN THE REQUESTED SLIDE
			$(".presentationSlide").animate({width: 300},200);
			$(this).addClass("presentationButtonOn");
			$("#presentation").css('background-image', 'url(../images/' + current + '.jpg)');
			$(".presentationText:eq("+ current +")").show();
			
			//TOGGLE ON/OFF IMAGES
			if(active != null) {
				image = getOffImage(basedir,active);	
				$(".presentationImage:eq(" + active + ")").attr("src",image); 
			} 
			
			image = getOnImage(basedir,current);
			$(".presentationImage:eq(" + current + ")").attr("src",image); 
	
			
			active = current;
		
		//IF THE CURRENT ITEM IS OPEN THEN CLOSE IT AND RESET ACTIVE
		} else {
			if ($.browser.msie && $.browser.version.substr(0,1)<7) {
				$(".presentationSlide").hide();
			} else {
				$(".presentationSlide").animate({width: 0},200);
			}
			active = null;
			$(".presentationText").hide();
		}

	});

	/********************************************************************************************************************
	PRELOAD IMAGES
	********************************************************************************************************************/	
	jQuery.preloadImages = function()
	{
	  for(var i = 0; i<arguments.length; i++)
	  {
		jQuery("<img>").attr("src", arguments[i]);
	  }
	}
	
	//PRELOAD IMAGES
	$.preloadImages("images/project-and-risk-management-on.gif","images/power-on.gif","images/automation-on.gif","images/instrumentation-and-controls-on.gif","images/energy-management-on.gif");
	$.preloadCssImages();

	/********************************************************************************************************************
	INDEX / HOME SPECIFIC STYLES
	********************************************************************************************************************/	
	var closed = true;
	var active = null;
	$(".presentationText").fadeOut();
	$(".presentationSlide").hide();

});


