$(document).ready(function(){
    $("ul.thumb li").hover(function() {
	$(this).css({'z-index' : '10'});
	$(this).find('img').addClass("hover").stop()
		.animate({
			marginTop: '-110px', 
			marginLeft: '-110px', 
			top: '50%', 
			left: '50%', 
			width: '175px', 
			height: '175px',
			padding: '20px' 
		}, 400);
	
	} , function() {
	$(this).css({'z-index' : '0'});
	$(this).find('img').removeClass("hover").stop()
		.animate({
			marginTop: '0', 
			marginLeft: '0',
			top: '0', 
			left: '0', 
			width: '150px', 
			height: '95px', 
			padding: '5px'
		}, 1000);
    });

	$("ul.thumb li a").click(function() {
		var mainImage = $(this).attr("href");
		$("#main_view img").attr({ src: mainImage });
		return false;		
	});
    
    $(".paging").show();
	$(".paging a:first").addClass("active");

	var imageWidth = $(".showbox-content").width();
	var imageSum = $(".image_reel img").size();
	var imageReelWidth = imageWidth * imageSum;

	$(".image_reel").css({'width' : imageReelWidth});

	rotate = function(){	
		var triggerID = $active.attr("rel") - 1;
		var image_reelPosition = triggerID * imageWidth;

		$(".paging a").removeClass('active');
		$active.addClass('active');

		$(".image_reel").animate({ 
			left: -image_reelPosition
		}, 500 );
		
	}; 

	rotateSwitch = function(){		
		play = setInterval(function(){
			$active = $('.paging a.active').next();
			if ( $active.length === 0) {
				$active = $('.paging a:first');
			}
			rotate();
		}, 5000);
	};
	
	rotateSwitch();

	$(".image_reel a").hover(function() {
		clearInterval(play);
	}, function() {
		rotateSwitch();
	});	

	$(".paging a").click(function() {	
		$active = $(this);

		clearInterval(play);
		rotate();
		rotateSwitch();
		return false;
	});
 
});
