﻿// JavaScript Document

(function(a){
	a.fn.desSlideshow=function(p){
        var p=p||{};

        var autoplay=p&&p.autoplay?p.autoplay:"enable";
        var slideshow_width=p&&p.slideshow_width?p.slideshow_width:"600";
        var slideshow_height=p&&p.slideshow_height?p.slideshow_height:"250";
        var thumbnail_width=p&&p.thumbnail_width?p.thumbnail_width:"200";
        var time_Interval = p&&p.time_Interval?p.time_Interval:"4000";
        var directory=p&&p.directory?p.directory:"images";
        slideshow_height = parseInt(slideshow_height);
        slideshow_width = parseInt(slideshow_width);
        time_Interval = parseInt(time_Interval);
        var g=a(this);
        var current = -1;
        var y=g.children(".switchBigPic").children("div").length;
        var v;
        var w;
		
        if(y==0){
            g.append("Require content");
            return null
        }
        init();
        if(autoplay == "enable"){
            g.find(".switchBigPic").css("display","block");
            g.find(".slidenavi").css("display","block");
            g.css("background","none");
            play();
        }else{
            g.find(".switchBigPic").css("display","block");
            g.find(".slidenavi").css("display","block");
            g.css("background","none");
            current = 0;
            showpic();
        }
        g.find(".slidenavi").children("li").hover(
            function(){
                var index = g.find(".slidenavi").children("li").index($(this));
                if(index != current){
                    current = index;
                    showpic();
                }
            },
            function(){

            }
        );
        g.hover(
            function(){

            },
            function(){
                if(autoplay == "enable"){
                    v=setTimeout(play,time_Interval);
                }
            }
        );


        function init(){
			g.find(".switchBigPic").css("height",slideshow_height + "px");

			g.find(".switchBigPic").children("div").css("position","absolute");
			
			g.find(".slidenavi").css("list-style","none");
			g.find(".slidenavi").css("margin","0");
			g.find(".slidenavi").css("width",slideshow_width + "px");
        }

		function showpic(){
            clearTimeout(v);
			g.find(".slidenavi").children("li").css("background-image","url("+directory+"slide_bg.jpg)");
			g.find(".slidenavi").children("li").css("background-position","left top");
			g.find(".slidenavi").children("li").css("background-repeat","no-repeat");
			g.find(".slidenavi").children("li").css("float","left");
			g.find(".slidenavi").children("li").css("margin","0");
			g.find(".slidenavi").children("li").css("padding","0");
			g.find(".slidenavi").children("li").css("list-style","none");
			
			g.find(".slidenavi").children("li").children("p").css("padding","0");
			
			g.find(".slidenavi").children("li").children("img").css("margin","0");
			g.find(".slidenavi").children("li").children("img").css("padding","0");

            g.find(".slidenavi").children("li").eq(current).css("background-image","url("+directory+"slide_bg_select.jpg)");

            g.find(".switchBigPic").children("div").children("p").css("padding","0");
            g.find(".switchBigPic").children("div").fadeOut();
            g.find(".switchBigPic").children("div").eq(current).fadeIn();
            w = current;
        }

		function play(){
            current++;
            if(current>=y){
                current=0
            }
            showpic();
            v=setTimeout(play,time_Interval);
        }
    }
})(jQuery);

