$(function() {
	
	var totalPanels    = $(".scrollContainer").children().size();
	var regWidth	   = $(".panel").css("width");
	var regImgWidth    = $(".panel img").css("width");	
	
	var curWidth			= 230;
	var curImgWidth			= 242;

	var $panels			= $('#slider .scrollContainer > div');
	var $container			= $('#slider .scrollContainer');

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

	$container
		.css('width', ($panels[0].offsetWidth * $panels.length) + 100 )
		.css('right', "80px");
	
	var scroll = $('#slider .scroll').css('overflow', 'hidden');	

	$("#panel_1").click(function(){ change($("#panel_1")); });
	$("#panel_2").click(function(){ change($("#panel_2")); });
	$("#panel_3").click(function(){ change($("#panel_3")); });
	$("#panel_4").click(function(){ change($("#panel_4")); });
	$("#panel_5").click(function(){ change($("#panel_5")); });

	$("#leftClick").click(function(){ changeFlag(false); });
	$("#rightClick").click(function(){ changeFlag(true); });

	function changeFlag(orientation) {
		for (i = 1; i <= 5; i++) {
			if ( $("#panel_" + i).find("img").css("width") == curImgWidth + "px" ) {
				if (orientation) {
					if ( i <= 4 ) {
						change($("#panel_" + (i + 1)));
					}
				} else {
					if ( i >= 2 ) {
						change($("#panel_" + (i - 1)));
					}
				}
			}
		}
	}

	function change(panel_object) {		
		for (i = 1; i <= 5; i++) {
			if (panel_object.get(0).id.replace("panel_", "") == i) {
				$("#panel_" + i).animate({ width: curWidth }).find("img").animate({ width: curImgWidth });
				$(".scrollContainer").stop().animate({ "left": i + 220 - panel_object.get(0).id.replace("panel_", "") * 100 }, function() { $("#slider").data("currentlyMoving", false); });
			} else {
				$("#panel_" + i).animate({ width: regWidth }).find("img").animate({ width: regImgWidth });
			}		
		}
	}

	change($("#panel_3"));
});
