﻿    var lastID = 1;
    var i=0;
    var interval;

    $(document).ready(function(){
	    $('#flashBox').append('<ul></ul>');
    	
	    $('#flashBox img').each(function(){
		    i += 1;
		    $('#flashBox ul').append('<li>'+ i +'</li>');
	    });
	    $('#flashBox li').eq(0).addClass('hover');

	    $('#flashBox').append('<a href="" id="showurl" target="_blank"><img id="showImg" style="cursor:pointer;" src="" border="0" /></a>');
	    $('#showImg').css('display','block');
	    $('#showImg').attr("src",$('#flashBox img').eq(0).attr('src'));
	    $('#showurl').attr("href",$('#flashBox a').eq(0).attr('href'));
    	
	    $('#flashBox li').click(function(){
		    $('#flashBox li').eq(lastID-1).removeClass('hover');
		    lastID = parseInt($(this).text());
		    GetPicture(lastID);
	    });
    	
	    $('#flashBox li').mouseover(function(){
		    $(this).addClass('hover');
	    });
	    $('#flashBox li').mouseout(function(){
		    if(lastID != parseInt($(this).text())){
			    $(this).removeClass("hover");
		    }
	    });
    	
	    $('#flashBox').mouseover(function(){
		    EndAutoRun();
	    });
	    $('#flashBox').mouseout(function(){
		    AutoRun();
	    });
	    
//	    $('#showImg').click(function(){
//            window.open($('#flashBox a').eq(lastID-1).attr("href"));
//	    });
	    
	    AutoRun();
    });

    function AutoRun(){
	    interval = setInterval("NextPicture()", 6000);
    }

    function EndAutoRun(){
	    clearInterval(interval);
    }
    var c = true;
    function NextPicture(){
	    $('#flashBox li').eq(lastID-1).removeClass('hover');
	    if(lastID<=1) {
		    c=true;
	    }
    	
	    if(lastID>=i) {
		    c=false;
	    }

	    if(c == true){
		    lastID++;
	    }
	    else{
	        if(lastID>=i)
	        {
	            lastID=0;
	        }
		    lastID++;
	    }
	    GetPicture(lastID);
    }

    function GetPicture(n){
        if(n<1) n=1;
        if(n>$('#flashBox li').length) n = $('#flashBox li').length;
	    $('#showImg').fadeOut("normal", function(){
		    $('#showImg').attr("src",$('#flashBox img').eq(n-1).attr('src'));
	    });
	    $('#showurl').fadeOut("normal", function(){
		    $('#showurl').attr("href",$('#flashBox a').eq(n-1).attr('href'));
	    });
	    $('#showImg').fadeIn("normal");
	    $('#showurl').fadeIn("normal");
	    $('#flashBox li').eq(n-1).addClass('hover');
    }
