$(document).ready(function(){

	// fade out loader
	$(".combiGalleryLoader").hide();
	
	// fade in gallery
	$(".combiGallery").fadeIn("fast");

	var itemsWrapWidth = $(".combiGallery .itemsWrap").outerWidth()+9;	
	var itemsOuterWidth = $(".combiGallery UL").outerWidth();		
	var itemsSections =  itemsOuterWidth / itemsWrapWidth;
	var easing = "swing";
						
	// click on thumb
	$(".combiThumb").click(function(){		
		var id=$(this).attr("id").split("_")[1];
		$(".combiPresentation").stop().css("position", "absolute");
		$(".combiPresentation").stop().fadeOut('fast');
		$("#combiPresentation_"+id).animate({"opacity":"1.0"}, 500).fadeIn('fast');
		$(".combiPresentation").css("position", "relative");
	});
	
	// click arrows
	$(".itemsMoveLeft").click(function(){				
		var posCounter = $(this.parentNode).children(".posCounter").html()*1;
		var posCounterNew = posCounter-1;
		var newLeft = (posCounterNew)*itemsWrapWidth*(-1);
		if (posCounterNew>=0){
			$(this.parentNode).children(".posCounter").html(posCounterNew);			
			$(this.parentNode).children("ul.items").animate({"left" : newLeft+"px"}, 2000, easing);
		}		
	});
	$(".itemsMoveRight").click(function(){				
		var posCounter = $(this.parentNode).children(".posCounter").html()*1;
		var posCounterNew = posCounter+1;
		var newLeft = (posCounterNew)*(itemsWrapWidth)*(-1);		
		if (posCounterNew<itemsSections){	
			$(this.parentNode).children(".posCounter").html(posCounterNew);		
			$(this.parentNode).children("ul.items").animate({"left" : newLeft+"px"}, 2000, easing);
		}		
	});	
	
});

jQuery.fn.fadeIn = function(speed, callback) { 
    return this.animate({opacity: 'show'}, speed, function() { 
        if (jQuery.browser.msie)  
            this.style.removeAttribute('filter');  
        if (jQuery.isFunction(callback)) 
            callback();  
    }); 
}; 
 
jQuery.fn.fadeOut = function(speed, callback) { 
    return this.animate({opacity: 'hide'}, speed, function() { 
        if (jQuery.browser.msie)  
            this.style.removeAttribute('filter');  
        if (jQuery.isFunction(callback)) 
            callback();  
    }); 
}; 
 
jQuery.fn.fadeTo = function(speed,to,callback) { 
    return this.animate({opacity: to}, speed, function() { 
        if (to == 1 && jQuery.browser.msie)  
            this.style.removeAttribute('filter');  
        if (jQuery.isFunction(callback)) 
            callback();  
    }); 
}; 
