$(document).ready(function(){

	init();					   

	$('#thumbgallery .thumb').click(function() {

		loadThumb(this);
		return false;
	});						

	$('#thumbgallery .thumb:first-child').click();	

	return false;

});



function errorHandling() {

		//$('.prodpic a img').remove();

		$('#loader p').wait(1500).fadeIn();

}





function loadThumb(mc) {					 
	$('#loader').fadeIn();
		$("#thumbgallery .thumb").each(function(index) {

                	$(this).removeClass('highlight');
					if(this == mc){
						$(this).addClass('highlight');
						window.currentHighlightNum = index;
					}
        });					
	$('#loader').fadeOut();
	$('.prodpic a').each(function(index) {	
		$(this).css('display', 'none');
		if(window.currentHighlightNum == index){
			$(this).fadeIn();
			$('#zoomicon a').attr('href', $(this).attr('href'));
		}
    });
	
	
	
}

function init() {

	$('#thumbgallery .thumb').each(function(index) {
		tmpString = '<a href="'+$('>a', this).attr('href')+'" rel="prettyPhoto[prod_img]" style="display: none;" id="bigimage_'+index+'"><img src="'+$('>a', this).attr('rev')+'" /></a>';
		$('.prodpic').append(tmpString);
	 });


	$('#zoomicon').fadeTo(1000,.5);

	//$('#thumbgallery .thumb:first-child').addClass('highlight').click();

	$('#addons #labels img').mouseover(function () {

			$(this).stop();

			$(this).fadeTo(500,1);					 

		});

	$('#addons #labels img').mouseout(function () {

			$(this).stop();									

			$(this).fadeTo(500,.2);					 

		});	

	$('#addons #labels').mouseenter(function() {

			$('#addons #labels img').stop();

			$('#addons #labels img').fadeTo(500,.2);	

		});

	$('#addons #labels').mouseleave(function() {

			$('#addons #labels img').stop();

			$('#addons #labels img').fadeTo(500,1);	

		});	

	$('.prodpic').mouseover(function () {

		$('#zoomicon').stop();

		$('#zoomicon').fadeTo(500,1);								  

	});

	$('.prodpic').mouseleave(function () {

		$('#zoomicon').stop();									 

		$('#zoomicon').fadeTo(1000,.2);								  

	});	

	$('#zoomicon').mouseover(function () {

		$(this).stop();

		$(this).fadeTo(500,1);								  

	});

	$('#zoomicon').mouseleave(function () {

		$(this).stop();									 

		$(this).fadeTo(1000,.2);								  

	});		

}


