$(document).ready(function() {

	//Set Default State of each portfolio piece
	$(".paging").show();
	$(".paging a:first").addClass("active1");
	$(".paging a:first").addClass("active");
	$(".numbutton").addClass('num1');
		
	//Get size of images, how many there are, then determin the size of the image reel.
	var imageWidth = $(".window").width();
	var imageSum = $(".image_reel img").size();
	var imageReelWidth = imageWidth * imageSum;
	
	//Adjust the image reel to its new size
	$(".image_reel").css({'width' : imageReelWidth});
	
	//Paging + Slider Function
	rotate = function(){	
		var triggerID = $active.attr("rel") - 1; //Get number of times to slide
		var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide

		$(".paging a").removeClass('active1'); //Remove all active class
		$(".paging a").removeClass('active2'); //Remove all active class
		$(".paging a").removeClass('active3'); //Remove all active class
		$(".paging a").removeClass('active4'); //Remove all active class
		$(".paging a").removeClass('active5'); //Remove all active class
		$(".paging a").removeClass('active6'); //Remove all active class
		$(".paging a").removeClass('active'); //Remove all active class
		$(".numbutton").removeClass('num1');
		$(".numbutton").removeClass('num2');
		$(".numbutton").removeClass('num3');
		$(".numbutton").removeClass('num4');
		$(".numbutton").removeClass('num5');
		$(".numbutton").removeClass('num6');
		$active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)
		$active.addClass('active'+$active.attr("rel"));
		$(".numbutton").addClass('num'+$active.attr("rel"));
		if($active.attr("rel") == 6)
			$(".dyskin").css("display","block");
		else
			$(".dyskin").css("display","none");
		
		//Slider Animation
		$(".image_reel").animate({ 
			left: -image_reelPosition
		}, 500 );
		
	}; 
	
	//Rotation + Timing Event
	rotateSwitch = function(){		
		play = setInterval(function(){ //Set timer - this will repeat itself every 3 seconds
			$active = $('.paging a.active').next();
			if ( $active.length === 0) { //If paging reaches the end...
				$active = $('.paging a:first'); //go back to first
			}
			rotate(); //Trigger the paging and slider function
		}, 5000); //Timer speed in milliseconds (3 seconds)
	};
	
	rotateSwitch(); //Run function on launch
	
	//On Hover
	$(".image_reel a").hover(function() {
		clearInterval(play); //Stop the rotation
	}, function() {
		rotateSwitch(); //Resume rotation
	});	
	
	//On Click
	$(".paging a").click(function() {	
		$active = $(this); //Activate the clicked paging
		//Reset Timer
		clearInterval(play); //Stop the rotation
		rotate(); //Trigger rotation immediately
		rotateSwitch(); // Resume rotation
		return false; //Prevent browser jump to link anchor
	});	
	
});
function btnclass(n,t){
	if(t==1){
		$(".btn"+n).attr("src","images/hover"+n+".png");
		$(".btn"+n).css("width","33px");
		$(".btn"+n).css("height","33px");
		$(".btn"+n).css("top","281px");
		if(n == 2)
			$(".btn"+n).css("left","146px");
		else
			$(".btn"+n).css("left","26px");
	}
	else if(t==2){
		$(".btn"+n).attr("src","images/normal"+n+".png");
		$(".btn"+n).css("width","23px");
		$(".btn"+n).css("height","24px");
		$(".btn"+n).css("top","285px");
		if(n == 2)
			$(".btn"+n).css("left","152px");
		else
			$(".btn"+n).css("left","32px");
	}
	else if(t==3){
		$(".btn"+n).attr("src","images/hover"+n+".png");
		$(".btn"+n).css("width","33px");
		$(".btn"+n).css("height","33px");
		$(".btn"+n).css("top","281px");
		if(n == 2)
			$(".btn"+n).css("left","146px");
		else
			$(".btn"+n).css("left","26px");
		$active = $('.paging a.active');
		var num = $active.attr("rel");
		num = n==1?--num:++num;
		num = num==7?1:num==0?6:num;
		$active = $('.paging'+num); //Activate the clicked paging
		//Reset Timer
		clearInterval(play); //Stop the rotation
		rotate(); //Trigger rotation immediately
		rotateSwitch(); // Resume rotation
		return false; //Prevent browser jump to link anchor
	}	
	else if(t==4){
		$(".btn"+n).attr("src","images/down"+n+".png");
		$(".btn"+n).css("width","23px");
		$(".btn"+n).css("height","24px");
		$(".btn"+n).css("top","285px");
		if(n == 2)
			$(".btn"+n).css("left","152px");
		else
			$(".btn"+n).css("left","32px");
	}
}

