$(document).ready(function(){
	$('#slider UL').cycle({ 
		fx:     'scrollHorz',
		delay:  2000, 
		speed:  0, 
		prev:   '#left', 
		next:   '#right'
	});
	
	$(".lightbox").fancybox({
		'titlePosition' 	: 'inside',
		'titleFormat' : function(title, currentArray, currentIndex, currentOpts) 
			{return '<span id="fancybox-title-over">' +  (currentIndex + 1) + ' / ' + currentArray.length +'</span>';}
	});
	
	LoadImageProduct($('#slider UL LI'));
	SetSliderHeight ();

});

function LoadImageProduct(obj){
	if (obj.hasClass('img-loaded')) return true;
	obj.find('SPAN').each(function(){
		var imgsrc = $(this).html();
		var imgalt = $(this).attr('title');
		var parent = $(this).parent();
		var img = new Image();
		
		$(img).load(function () {
			$(this).hide();
			parent.prepend(this);
			$(this).fadeIn();
		}).error(function () {
		}).attr('src', imgsrc).attr('alt', imgalt);
	});
	obj.addClass('img-loaded');
	return true;
}

function SetSliderHeight () {
	var header = $('#header').height();
	var footer = $('#footer').height();
	var bottom = $('.wrapper-page').height();
	var content = $('.content').height();
//	console.log($(window).height()+' - '+header+' - '+footer+' - '+bottom+' - 25');
	var height = $(window).height() - header - footer - bottom - 25;
	if (height > 600) $('.home #content #slider UL').height(600);
	else $('.home #content #slider UL').height(height);
}
