$j(function() {
	
	var totalPanels			= $j(".scrollContainerMovingBoxes").children().size();
		
	var regWidth			= $j(".panelMovingBoxes").css("width");
	var regImgWidth			= $j(".panelMovingBoxes img").css("width");
	var regTitleSize		= $j(".panelMovingBoxes h2").css("font-size");
	var regParSize			= $j(".panelMovingBoxes p").css("font-size");
	
	var movingDistance	    = 298;
	
	var curWidth			= 350;
	var curImgWidth			= 326;
	var curTitleSize		= "25px";
	var curParSize			= "15px";
	
	var onButton            = false;
	var direction           = true;
	var first               = true;
	var t;

	var $jpanels				= $j('#sliderMovingBoxes .scrollContainerMovingBoxes > div');
	var $jcontainer			= $j('#sliderMovingBoxes .scrollContainerMovingBoxes');

	$jpanels.css({'float' : 'left','position' : 'relative'});
    
	$j("#sliderMovingBoxes").data("currentlyMoving", false);

	$jcontainer
		.css('width', ($jpanels[0].offsetWidth * $jpanels.length) + 100 )
		.css('left', "+282px");

	var scroll = $j('#sliderMovingBoxes .scrollMovingBoxes').css('overflow', 'hidden');

	function returnToNormal(element) {
		$j(element)
			.animate({ width: regWidth })
			.find("img")
			.animate({ width: regImgWidth })
		    .end()
			.find("h2")
			.animate({ fontSize: regTitleSize })
			.end()
			//.find("p")
			//.animate({ fontSize: regParSize });
	};
	
	function growBigger(element) {
		$j(element)
			.animate({ width: curWidth })
			.find("img")
			.animate({ width: curImgWidth })
		    .end()
			.find("h2")
			.animate({ fontSize: curTitleSize })
			.end()
			//.find("p")
			//.animate({ fontSize: curParSize });
	}
	
	//direction true = right, false = left
	function change(){
	   
	    //if not at the first or last panel
		if((direction && !(curPanel < totalPanels)) || (!direction && (curPanel <= 1))) { return false; }	
        
        //if not currently moving
        if (($j("#sliderMovingBoxes").data("currentlyMoving") == false) && onButton) {
            
			$j("#sliderMovingBoxes").data("currentlyMoving", true);
			
			var next         = direction ? curPanel + 1 : curPanel - 1;
			var leftValue    = $j(".scrollContainerMovingBoxes").css("left");
			var movement	 = direction ? parseFloat(leftValue, 10) - movingDistance : parseFloat(leftValue, 10) + movingDistance;
		
			$j(".scrollContainerMovingBoxes")
				.stop()
				.animate({
					"left": movement
				}, function() {
					$j("#sliderMovingBoxes").data("currentlyMoving", false);
				});
			
			returnToNormal("#panel_"+curPanel);
			growBigger("#panel_"+next);
			
			curPanel = next;
		}
	}
	
	function callChange(direction)
	{
		change(true);
		//alert('bob');
		t = setTimeout("callChange(true);", 200);
	}
	
	// Set up "Current" panel and next and prev
	growBigger("#panel_1");	
	var curPanel = 1;
	
	$j(".rightMovingBoxes").mouseenter(function(){ onButton = true; direction = true; });	
	$j(".rightMovingBoxes").mouseleave(function(){ onButton = false; });
	$j(".leftMovingBoxes").mouseenter(function(){ onButton = true; direction = false; });	
	$j(".leftMovingBoxes").mouseleave(function(){ onButton = false; });
	setInterval(change, 250);
	
});
