/*
* Banner Slideshow 
* www.DealerFire.com team
*/
(function($) {
$.fn.df_slideshow = function(params) {
	
	var obj = $(this[0]);
	var banners = obj.find(".images-list").children();
	var thumbs = obj.find(".thumbs-list").children();
	var currIndex = banners.index(banners.filter(".active"));
	var totalItems = banners.length;
	var timer = false;
	var curr_item = null;
	var dir_next = null;
	var count = 0;
	
	//Default options
	var options = {
        autorotate: false,
        interval: 5000,
        animationSpeed: 700,
        animationType: "fadeIn"
    };
    
    //initialize
    for (var i in params)
	{
		options[i] = params[i];
	}

   var transform = function transform (index){

   	   	if(index >= totalItems){
			index = 0;
   	   	}
   	   
   		if(options["animationType"] == "fadeIn"){
   			banners.hide();
			banners.eq(currIndex).show().css("z-index", 1).fadeOut(options["animationSpeed"]);
   			banners.eq(index).css("z-index", 2).fadeIn(options["animationSpeed"]);
   		}
   		else if(options["animationType"] == "slideDown"){
   			banners.hide();
			banners.eq(currIndex).show().css("z-index", 1).animate({top: banners.eq(currIndex).outerHeight(), opacity: 0}, {duration: options["animationSpeed"]});
			banners.eq(index).css({"z-index": 2, top: -100, opacity: 0}).show();                
        	banners.eq(index).stop().animate({top: 0, opacity: 1}, {duration: options["animationSpeed"]});
   		}
   		else if(options["animationType"] == "slideRight"){
   			banners.hide();
			banners.eq(currIndex).show().css("z-index", 1).animate({left: banners.eq(currIndex).outerWidth(), opacity: 0}, {duration: options["animationSpeed"]});
			banners.eq(index).css({"z-index": 2, left: -100, opacity: "0"}).show();                
        	banners.eq(index).stop().animate({left: 0, opacity: "1"}, {duration: options["animationSpeed"]});
   		}
   		else {
			
   		}
   		
   		banners.removeClass("active");
   		banners.eq(index).addClass("active");
   		thumbs.removeClass("active");
   		thumbs.eq(index).addClass("active");
   		currIndex = index;
   		
   }
    
	if(options["autorotate"]){
		timer = setInterval(function() { transform(currIndex+1); }, options["interval"]);
	}
	
	thumbs.find(".thumb").click(function(){
		clearInterval(timer);
		var index = thumbs.index($(this).parent());
		transform(index);
		return false;
	});
    
    
};
})(jQuery);