/**
* We use the initCallback callback
* to assign functionality to the controls
*/
//function mycarousel_initCallback(carousel) {
//
//	$('#mycarousel-next').bind('click', function() {
//		carousel.next();
//		return false;
//	});
//
//	$('#mycarousel-prev').bind('click', function() {
//		carousel.prev();
//		return false;
//	});
//	
//};
$(document).ready(function() {	
	//$('#myProductCarousel').jcarousel({
	//	scroll: 1,
	//	initCallback: mycarousel_initCallback,
	//	buttonNextHTML: null,
	//	buttonPrevHTML: null
	//});
	
	var maxnumber = $('#myProductCarousel').children('li.gallery-thumb').length;

	//$('#gallery-image').hover(function(){$('#gallery-controls').css('display', 'block');$('#gallery-controls').css('display', 'none');});

	$('#gallery-image').hover(
		function () {
		  $('#gallery-controls').css('display', 'block');
		},
		function () {
		  $('#gallery-controls').css('display', 'none');
		}
	);

	//$('#gallery-image').mouseover(function(){
	//	$('#gallery-controls').css('display', 'block');
	//});
	//
	//$('#gallery-image').mouseout(function(){
	//	$('#gallery-controls').css('display', 'none');
	//});
	
	//myProductCarousel load big image
	$("#myProductCarousel li a").click(function(){
		if($("#gallery-image img#gallery-img").attr("src") != $(this).attr("href")){
			$("#gallery-image img#gallery-img").hide();
			
			
			var nextimageli = $(this).parent().attr('id').split('gallery-thumb-');
			var nextimageid = parseInt(nextimageli[1]);
			$('#gallery_number').val(nextimageid);
			
			var nextImage = new Image();
			nextImage.src = $(this).attr("href");
			nextImage.alt= $(this).attr("title");

			if(nextImage.complete)
			{
				// fade new image in
				$('#gallery-image img#gallery-img').attr('src', nextImage.src);
				$('#gallery-image img#gallery-img').attr('alt', nextImage.alt);
				$("#gallery-image img#gallery-img").fadeIn();                             
			}
			else
			{
				nextImage.onload = function()
				{
					// fade new image in
					$('#gallery-image img#gallery-img').attr('src',nextImage.src);
					$('#gallery-image img#gallery-img').attr('alt', nextImage.alt);
					$("#gallery-image img#gallery-img").fadeIn();                             
	
				}                                                                
			}
		}
	return false;
	});
	
	$('#gallery-prev-link').click(function(){
		var current_id = parseInt($('#gallery_number').val());
		if(current_id>1) {
			prev_id = current_id-1;
			var li = $('#gallery-thumb-'+prev_id+ ' a');
			
			$("#gallery-image img#gallery-img").hide();
			var prevImage = new Image(); 
			prevImage.src = li.attr('href');
			prevImage.alt= li.attr('title');
			if(prevImage.complete)
			{
				// fade new image in
				$('#gallery-image img#gallery-img').attr('src', prevImage.src);
				$('#gallery-image img#gallery-img').attr('alt', prevImage.alt);
				$("#gallery-image img#gallery-img").fadeIn();                             
			}
			else
			{
				prevImage.onload = function()
				{
					// fade new image in
					$('#gallery-image img#gallery-img').attr('src',prevImage.src);
					$('#gallery-image img#gallery-img').attr('alt', prevImage.alt);
					$("#gallery-image img#gallery-img").fadeIn();                             
	
				}                                                                
			}
			$('#gallery_number').val(prev_id);
		}
	});
	
	$('#gallery-next-link').click(function(){
		var current_id = parseInt($('#gallery_number').val());
		
		if(current_id<maxnumber) {
			next_id = current_id+1;

			var li = $('#gallery-thumb-'+next_id+ ' a');

			$("#gallery-image img#gallery-img").hide();
			
			var nextImage = new Image(); 
			nextImage.src = li.attr('href');
			nextImage.alt= li.attr('title');
			if(nextImage.complete)
			{
				// fade new image in
				$('#gallery-image img#gallery-img').attr('src', nextImage.src);
				$('#gallery-image img#gallery-img').attr('alt', nextImage.alt);
				$("#gallery-image img#gallery-img").fadeIn();                             
			}
			else
			{
				nextImage.onload = function()
				{
					// fade new image in
					$('#gallery-image img#gallery-img').attr('src',nextImage.src);
					$('#gallery-image img#gallery-img').attr('alt', nextImage.alt);
					$("#gallery-image img#gallery-img").fadeIn();                             
	
				}                                                                
			}
			$('#gallery_number').val(next_id);
		}
	});
	
	

});
