$(function() {

	$.hideMainPicture = function(){
		$("#main_picture a").hide();
	};
	
	$.dimThisThumb = function(id){
		$("img#"+id).animate({ "opacity": 0.5 });
	};
	$.lightUpAll = function(){
		$("#thumbnail_col img").css({ "opacity" : 1 });
	};
	
	$.switchMainPicture = function(id){
		$("#main_picture a:nth-child("+id+")").fadeIn('slow');
	};
	$.removeActive = function(id){
		$("img#"+id).removeClass('active');
	};
	$.setActive = function(id){
		$("img#"+id).addClass('active');
	};
	
	$.rotatingEngine = function(){
		var current_id = $(".active").attr('id');
		if(current_id<2)
		{
			var next_id = parseInt(current_id)+ parseInt(1);
		} else {
			var next_id = 1;
		}
		
		$.lightUpAll();
		$.dimThisThumb(next_id);
		$.removeActive(current_id);
		$.setActive(next_id);
		$.hideMainPicture();
		$.switchMainPicture(next_id);
	};

	$(document).ready(function(){
		$.dimThisThumb(1);
		
		$("#main_picture a").each(function(index){
			if(index > 0)
				$(this).hide();
		});
		
//		$("#main_picture a:nth-child(2)").hide();
//		$("#main_picture a:nth-child(3)").hide();
//		$("#main_picture a:nth-child(4)").hide();
//		setInterval("$.rotatingEngine()", 3000);
	});
	
	$("a.thumbnails").stop().click(function(){
		var id = $(this).find('img').attr('id');
		if(id>1)
		{
			var prev_id = id-1;
		} else {
			var prev_id = 0;
		}
		
		$.lightUpAll();
		$.dimThisThumb(id);
		$.removeActive(prev_id);
		$.setActive(id);
		$.hideMainPicture();
		$.switchMainPicture(id);
	});
});
