/*-----------------------------------------------
BLASTMedia ourClient JS
Author: Andy Sherman
Created: 07/05/09
Description: JS functionality for client slider
-------------------------------------------------*/

/*my References
alert($(cCols[0]).css("width"));

*/

jQuery(document).ready(function() {	
	
	//show prev/next buttons now js loaded
	$("p#sliderBtns").css("display","block");
	
	//create array of .cCols [allow to get number of cols etc from .length]
	var cCols = $('div#clientContainer .cCol');
	
	var clientContainer = $("div#clientContainer");

	//set width of #clientContainer onload
	clientContainer
	.css("width", (parseInt($(cCols[0]).css("width")) * parseInt(cCols.length)));
	//alert(parseInt($(cCols[0]).css("width")) * parseInt(cCols.length));
	//alert("widthNow:"+$("div#clientContainer").css("width"));
	
	//set #content height=330px -> so can put buttons at bottom
	$("#content").css("height","330px");
	
	//set #content : overflow:hidden
	$("#content").css("overflow","hidden");
	
	//variable to hold the highest value allowed (+) when using NEXT
 	var maxNextVal = ( parseInt($(clientContainer).css("width")) - (parseInt($(cCols[0]).css("width")))*2);
	//variable to hold lowest value allowed (-) when using PREV

 	


	/*-----------------------------------------------------
	logic for buttons -> animte cCols
	+/- [+=prev][-=next/neg numbers move to next]
	-------------------------------------------------------*/
	
	//assign button functionality to nextBtn [not prev until move fwd]
	activeNextBtn();
	//activePrevBtn();

	/*--------------
	button functions
	---------------*/
	function nextBtnClick() {
		//-neg margin
		
		//get current clientContainer value
		var curVal = $(clientContainer).css("marginLeft");
		curVal = parseInt(curVal);
		//increment negative
		curVal += -300;
		
		//animate
		$(clientContainer).animate({"marginLeft": curVal}, "fast");
		
		/*check if this is second from last col -> if so disable button so can't go further after next*/
		//curVal converted to positive val
		var curValPos = (parseInt($(clientContainer).css("marginLeft")) * -1);
		
		if(curValPos == maxNextVal) {
			//alert("you have reached the end.");
			deactivateBtn("nextBtn");
		}
		
		//re-enable prev button if not at the start
		if(curVal != 0) {
			activePrevBtn();
		}
	}
	
	function prevBtnClick() {
		//+pos margin
			//get current clientContainer value
			var curVal = $(clientContainer).css("marginLeft");
			curVal = parseInt(curVal);
			//increment positive
			curVal += 300;
			
			//animate
			$(clientContainer).animate({"marginLeft": curVal}, "fast");
			
			/*check if this start of the content-> if so disable button so can't go further after next*/
			if(curVal == 0) {
				//alert("you have reached the start");
				deactivateBtn("prevBtn");
			}
			
			
			//re-enable next button if not at end
			if(curVal != maxNextVal) {
				activeNextBtn();
			}
	}
	
	function activeNextBtn() {
		$("p#sliderBtns a#nextBtn").bind('click',function(){
		    nextBtnClick();
		    return false;
		 })
		//remove inactive class
		.removeClass('inactive');
	}
	
	function activePrevBtn() {
		//activate
		$("p#sliderBtns a#prevBtn").bind('click',function(){
		    prevBtnClick();
		    return false;
		 })
		//remove inactive class
		.removeClass('inactive');
	}
	
	function deactivateBtn(id) {
		//deactivate
		$("p#sliderBtns a#"+id)
			.unbind()
			.addClass('inactive');
			
		//add inactive class
		
	}

	//deactivate buttons whilst animating

//end jquery ready	
});
