(function($){
	$.fn.LoadImage=function(removeDOM){ 
		return $("#imageSlide_images li").ADSlide({
			speed : "normal",
			timer : 2500,
			leftspeed : 200,
			leftspeed2 : 1
		});
	}
		  
		  
	$.fn.ADSlide=function(settings){
		
		$.fn.ADSlide.init();
		
		settings = jQuery.extend({
        	speed : "normal",
			timer : 2500,
			leftspeed : 200,
			leftspeed2 : 200
    	}, settings);
		//return this.each(function() {
			$.fn.ADSlide.scllor( $(this), settings );
    	//});
	};
	
	$.fn.ADSlide.scllor=function($this,settings){
		var index=0;
		var li=$("#imageSlide_cycles li");
		var showImg=$("#imageSlide_images li");
		
		var imageSlide=$("#imageSlide");
		var headers=$("#imageSlide_headers");
		var content=$("#imageSlide_content");
		
		var headersLi=$("#imageSlide_headers li");
		var contentLi=$("#imageSlide_content .list");
		liLength=li.length;


		headersLi.hover(function(){
			headerIndex = headersLi.index(this);				   
			headersLi.eq(headerIndex).addClass("active").siblings().removeClass("active");
			content.show(1,function(){
				contentLi.eq(headerIndex).animate({opacity:1},settings.leftspeed2).css({"z-index":"10"}).siblings().animate({opacity: 0},settings.leftspeed2).css({"z-index":"-10"});
			});
			
		},function(){
			
			imageSlide.hover(function(){
			},function(){
				headersLi.eq(headerIndex).removeClass("active");
				content.hide(1);
			});
		});

		var intervalTime= setInterval(function(){
			ShowAD(index);
			index++;
			if(index >= liLength){
				index=0;
			}
		}, settings.timer);
		
		li.hover(function(){
			if(intervalTime){
				clearInterval(intervalTime);
			}
			index=li.index(this);
			intervalTime=setTimeout(function(){
				ShowAD(index);
			}, settings.leftspeed );

		},function(){
			clearInterval(intervalTime);
			intervalTime=setInterval(function(){
				ShowAD(index);
				index++;
				if (index >= liLength) {
					index = 0;
				}
			}, settings.timer);
		});
		showImg.hover(function(){
			if(intervalTime){
				clearInterval(intervalTime);
			}
		},function(){
			clearInterval(intervalTime);
			intervalTime=setInterval(function(){
				ShowAD(index);
				index++;
				if (index >= liLength) {
					index = 0;
				}
			}, settings.timer);
		});

		var ShowAD=function(i){
			showImg.stop();
			li.stop();
			li.eq(i).children("a").css({"color":"#aaa","background":"url(/includes/imageSlide/images/number-border3.gif) no-repeat left -20px"});
			li.eq(i).siblings().children("a").css({"color":"#666","background":"url(/includes/imageSlide/images/number-border3.gif) no-repeat"});
			return showImg.eq(i).animate({opacity:1},settings.speed).css({"z-index": "1"}).siblings().animate({opacity: 0},settings.speed).css({"z-index":"0"});
			
		};
	};
	
	$.fn.ADSlide.init=function(){
		$("#imageSlide_cycles li:first-child").children("a").css({"color":"#aaa","background":"url(/includes/imageSlide/images/number-border3.gif) no-repeat left -20px"});
	};
	
	
	

	
})(jQuery);


