(function(a){
    a.fn.webwidget_slideshow_dot=function(p){
        var p=p||{};

        var m=p&&p.slideshow_time_interval?p.slideshow_time_interval:"2000";
        var q=p&&p.slideshow_window_width?p.slideshow_window_width:"400";
        var r=p&&p.slideshow_window_height?p.slideshow_window_height:"400";
        var sf=p&&p.soldeshow_foreColor?p.soldeshow_foreColor:"#000";
        var stc=p&&p.slideshow_title_color?p.slideshow_title_color:"#17CCCC";
        var d=p&&p.directory?p.directory:"images/carousel/";
        q += "px";
        r += "px";
        var v;
        var w=-1;
        var target=a(this);
        var y=target.find("ul:first").children("li").length;
        if(target.find("ul").length==0||target.find("li").length==0){
            target.append("Require content");
            return null
        }
        init();
        play();
        function init(){
            with (target) {
	        	find("ul:first").wrap('<div class="slides_box"></div>');
	            css("width",q).css("height",r);
	            find(".slides_box").css("width",q).css("height",r);
	            find("ul:first").width(parseInt(q)*y);
	            find("ul:first").children("li").css("width",q).css("height",r).show();
	            find("ul:first").children("li").children("a").children("img").css("width",q).css("height",r);
	            find(".slides_box").after('<div class="title_thumb_box"></div>');
	            find(".title_thumb_box").append('<div class="title_box"></div>');
	            find(".title_thumb_box").append('<div class="thumb_box"></div>');
	
	            for (i = 0; i <= y -1; i++)
	            {
	            	var num = i + 1;
	                find(".thumb_box").append('<span><img src="' + d + 'inactive/' + num + '.png" class="thumb_num" alt="'+ num +'" /></span>');
	            }
	            
	            find(".thumb_box").append('<span><img src="'+d+'inactive/pause.png" alt="pause" class="thumb_p" /></span>');
	
	            
	            find('.thumb_box').children('span').children('img.thumb_p')
		            .click(function() {
		            	var action = $(this).attr("alt");
		            	
		            	if (action == 'pause') {
		            		clearTimeout(v);
		            		$(this).attr('alt', 'play');
		            		$(this).attr('src', d + 'active/play.png');
		            	} else {
		            		play();
		            		$(this).attr('alt', 'pause');
		            		$(this).attr('src', d + 'active/pause.png');
		            	}
		            })
		            .hover(function() {
	            		var action = $(this).attr("alt");
		            	
		            	if (action == 'pause') {
	            			$(this).attr('src', d + 'active/pause.png');
		            	} else {
	            			$(this).attr('src', d + 'active/play.png');
		            	}
		            }, function() {
	        			var action = $(this).attr("alt");
		            	
		            	if (action == 'pause') {
		            		$(this).attr('src', d + 'inactive/pause.png');
		            	} else {
		            		$(this).attr('src', d + 'inactive/play.png');
		            	}
		            });
	            
	            find('.thumb_box').children('span').children('img.thumb_num')
	            	.click(function(){
		            	var alt = $(this).attr('alt');
		            	var index = parseInt(alt, 10) - 1;
		            	
		            	if (index == 0) {
		            		w = y - 1;
		            	} else {
		            		w = parseInt(alt, 10) - 2;
		            	}
		            	
		            	play();
		            	
		            	find('.thumb_box').children('span').children('img.thumb_p').attr('alt', 'pause');
		            	find('.thumb_box').children('span').children('img.thumb_p').attr('src', d + 'inactive/pause.png');
		            })
		            .hover(function(){
		                var index = $(this).attr('alt');
		                if (index == (w + 1)) return;
	                    
	                    var index = parseInt(index, 10);
	                    var file = 'active/' + index + '.png';
	                    $(this).attr('src', d+file);      
		            }, function(){
					   var index = $(this).attr('alt');
					   if (index == (w + 1)) return;
					   
					   var index = parseInt(index, 10);
					   var file = 'inactive/' + index + '.png';
					   $(this).attr('src', d+file);      
		            });
            }
        }
        function previous(){
            if(w==0){
                w=y-2
            }else{
                if(w==1){
                    w=y-1
                }else{
                    w-=2
                }
            }
            play()
        }
        function next(){
            play()
        }
        function play(){
        	clearTimeout(v);
            w++;
            if(w>=y){
                w=0
            }
            target.find(".slides_box").children("ul").animate({
                left:-(w*parseInt(q))
            },600);
            
            target.find(".thumb_box").children("span").children("img[class='thumb_num']").each(function(){
                var index = $(this).attr('alt');
                if (index == (w + 1)) return;
                
                var index = parseInt(index, 10);
                var file = 'inactive/' + index + '.png';
                $(this).attr('src', d+file);     
            	
            })
            target.find(".thumb_box").children("span").children("img[class='thumb_num']").eq(w).attr("src",d+"active/"+(w+1)+".png");
            v=setTimeout(play,m)
        }
        function stop(){
            clearTimeout(v);
        }
    }
})(jQuery);
