$(function() {
	/*
	number of fieldsets
	*/
	var fieldsetCount = $('#formElem').children().length;
	
	/*
	
	current position of fieldset / navigation link
	*/
	var current 	= 1;
    
	/*
	sum and save the widths of each one of the fieldsets
	set the final sum as the total width of the steps element
	*/
	var stepsWidth	= 0;
    var widths 		= new Array();
	$('#steps .step').each(function(i){
        var $step 		= $(this);
		widths[i]  		= stepsWidth;
        stepsWidth	 	+= $step.width();
    });
	$('#steps').width(stepsWidth);
	
	/*
	to avoid problems in IE, focus the first input of the form
	*/
	$('#formElem').children(':first').find(':input:first').focus();	
	
	/*
	show the navigation bar
	*/
	$('#navigation').show();
	
	/*
	when clicking on a navigation link 
	the form slides to the corresponding fieldset
	*/
    $('#navigation a').bind('click',function(e){
		var $this	= $(this);
		var prev	= current;
		$this.closest('ul').find('li').removeClass('selected');
        $this.parent().addClass('selected');
		/*
		we store the position of the link
		in the current variable	
		*/
		current = $this.parent().index() + 1;
		/*
		animate / slide to the next or to the corresponding
		fieldset. The order of the links in the navigation
		is the order of the fieldsets.
		Also, after sliding, we trigger the focus on the first 
		input element of the new fieldset
		If we clicked on the last link (confirmation), then we validate
		all the fieldsets, otherwise we validate the previous one
		before the form slided
		*/
        $('#steps').stop().animate({
            marginLeft: '-' + widths[current-1] + 'px'
        },550);
        e.preventDefault();
    });
	
	/*
	clicking on the tab (on the last input of each fieldset), makes the form
	slide to the next step
	*/
	$('#formElem > fieldset').each(function(){
		var $fieldset = $(this);
		$fieldset.children(':last').find(':input').keydown(function(e){
			if (e.which == 9){
				$('#navigation li:nth-child(' + (parseInt(current)+1) + ') a').click();
				/* force the blur for validation */
				$(this).blur();
				e.preventDefault();
			}
		});
	});
	
	/*
	validates errors on all the fieldsets
	records if the Form has errors in $('#formElem').data()
	*/
});


    $(function() {
        $("#desSlideshow1").desSlideshow({
            autoplay: 'enable',//option:enable,disable
            slideshow_width: '750',//slideshow window width
            slideshow_height: '249',//slideshow window height
            thumbnail_width: '315',//thumbnail width
            time_Interval: '4000',//Milliseconds
            directory: 'images/'// flash-on.gif and flashtext-bg.jpg directory
        });
        $("#desSlideshow2").desSlideshow({
            autoplay: 'enable',//option:enable,disable
            slideshow_width: '750',//slideshow window width
            slideshow_height: '249',//slideshow window height
            thumbnail_width: '315',//thumbnail width
            time_Interval: '4000',//Milliseconds
            directory: 'images/'// flash-on.gif and flashtext-bg.jpg directory
        });
		$("#desSlideshow3").desSlideshow({
            autoplay: 'enable',//option:enable,disable
            slideshow_width: '750',//slideshow window width
            slideshow_height: '249',//slideshow window height
            thumbnail_width: '315',//thumbnail width
            time_Interval: '4000',//Milliseconds
            directory: 'images/'// flash-on.gif and flashtext-bg.jpg directory
        });
		$("#desSlideshow4").desSlideshow({
            autoplay: 'enable',//option:enable,disable
            slideshow_width: '750',//slideshow window width
            slideshow_height: '249',//slideshow window height
            thumbnail_width: '315',//thumbnail width
            time_Interval: '4000',//Milliseconds
            directory: 'images/'// flash-on.gif and flashtext-bg.jpg directory
        });
		$("#desSlideshow5").desSlideshow({
            autoplay: 'enable',//option:enable,disable
            slideshow_width: '750',//slideshow window width
            slideshow_height: '249',//slideshow window height
            thumbnail_width: '315',//thumbnail width
            time_Interval: '4000',//Milliseconds
            directory: 'images/'// flash-on.gif and flashtext-bg.jpg directory
        });
    });
		function ShowHide(shID)
		{
			var myObj=document.getElementById(shID)
			if (myObj.style.display=='')
			{
				myObj.style.display='none'
			}
			else
			{
				myObj.style.display=''
			}	
		}

(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").css("float","left");
           g.find(".nav").css("display","block").css("float","left");
            g.css("background","none");
            play();
        }else{
            g.find(".switchBigPic").css("display","block");
            g.css("background","none");
            current = 0;
            showpic();
        }
        g.find(".nav").children("div").hover(
            function(){
                var index = g.find(".nav").children("div").index($(this));
                if(index != current){
                    current = index;
                    showpic();
                }
            },
            function(){

            }
        );
        g.hover(
            function(){

            },
            function(){
                if(autoplay == "enable"){
                    v=setTimeout(play,time_Interval);
                }
            }
        );
        function init(){
            g.css("width",slideshow_width+"px").css("height",slideshow_height+"px").css("position","relative").css("font-family","Verdana,Geneva,sans-serif").css("border-top","1px solid #CCCCCC").css("overflow","hidden");
            g.find("a").css("color","#000").css("text-align","left");
            g.find("img").css("border","none");
            g.find(".switchBigPic").css("position","relative");
            g.find(".switchBigPic").children("div").css("position","absolute").css("overflow","hidden");
            g.find(".switchBigPic").children("div").children("p").css("position","absolute").css("padding","5px").css("margin","0px").css("bottom","0px").css("opacity","0.6").css("background-color","#000").css("color","#FFF").css("font-size","11px");
            g.find(".nav").css("height",slideshow_height+"px").css("position","absolute").css("right","0px");
            g.find(".nav").children("div").css("height","62px").css("background-image","url("+directory+"flashtext-bg.jpg)").css("background-position","left center").css("line-height","62px").css("border-bottom","1px solid #CCCCCC").css("display","block");
            g.find(".nav").children("div").children("a").css("text-decoration","none").css("display","block").css("padding-left","25px").css("font-size","11px").css("font-weight","bold").css("line-height","20px").css("padding-top","10px");
            g.find(".nav").children("div").children("a").children("span").css("font-size","10px").css("font-weight","normal").css("line-height","14px");
            g.find(".nav").children("div").css("margin-left","30px");
            g.find(".switchBigPic").children("div").hide();
        }
        function showpic(){
            clearTimeout(v);
            g.find(".nav").children("div").css("background-image","url("+directory+"flashtext-bg.jpg)").css("border-bottom","1px solid #CCCCCC").css("width","296px");;
            g.find(".nav").children("div").children("a").css("color","#000");
            g.find(".nav").children("div").eq(current).css("background-image","url("+directory+"flash-on.png)").css("background-position","left center").css("border-bottom","none");
            g.find(".nav").children("div").children("a").eq(current).css("color","white");
            g.find(".switchBigPic").children("div").fadeOut();
            g.find(".switchBigPic").children("div").eq(current).fadeIn();
            g.find(".nav").children("div").eq(current).animate({marginLeft: '0'}, "fast");
            g.find(".nav").children("div").eq(w).animate({marginLeft: '30px'}, "fast");
            w = current;

        }
        function play(){
            current++;
            if(current>=y){
                current=0
            }
            showpic();
            v=setTimeout(play,time_Interval);
        }
    }
})(jQuery);
