var preload=new Array();
var preHref=new Array();
var rollDelay=5;
var rollTimer=null;
var imgNav=null;
var tempcount=1;

/*
var photoarray=[
	//[contextPath+"/images/ad/bi556.jpg","",contextPath+"/tracert.jhtml?link=http://www.51bi.com/activities/merryChristmas.html",contextPath+"/images/store/bi556.jpg","",""],
	[contextPath+"/images/ad/51bi_r_556.jpg","","http://www.51bi.com/space/biuser/register.jsp","","",""],
	[contextPath+"/images/store/u1382556.gif","",contextPath+"/redirect.jhtml?link=http://www.u1382.com/services/templatesaleadv.aspx?sysno=9","","",""],
	[contextPath+"/images/store/lukigo556.jpg","",contextPath+"/redirect.jhtml?link=http://www.luckigo.com/christmas.php","","",""],
	[contextPath+"/images/store/cozzy556.jpg","",contextPath+"/redirect.jhtml?link=http://www.cozzy.cn",contextPath+"/images/store/cosme776.jpg","","http://www.cosme-de.com/gb/category/bestvalue.html"],
	[contextPath+"/images/store/likeface556.jpg","",contextPath+"/redirect.jhtml?link=http://www.likeface.com/action/xmasgift.shtml?from=51bi&name=1","","",""],
	//[contextPath+"/images/store/immy556.jpg","",contextPath+"/redirect.jhtml?link=http://www.immyhome.com/index.php","","",""]	
	[contextPath+"/images/store/xinzhan556.jpg","",contextPath+"/redirect.jhtml?link=http://www.xzuan.com/zhuanti/christmas/","","",""]
	
];
*/
function initpic(){
	var swidth = screen.width;
	for (var i=0;i<photoarray.length;i++){
		preload[i]=new Image();
		//if (swidth < 1220){
			preload[i].src=photoarray[i][0];
			preload[i].alt=photoarray[i][1];
			preHref[i]=photoarray[i][2];
		//}
		//else{
		//	preload[i].src=photoarray[i][3];
		//	preload[i].alt=photoarray[i][4];
		//	preHref[i]=photoarray[i][5];
		//}
		
	}
}

function generateslider(){
	
	if(photoarray.length == 0)
		return ;
	
	var navBarHTML="";
	navBarHTML+="<ul id='navBar'>";
	for (var i=0;i<photoarray.length;i++){
		navBarHTML+="<li id='i"+ i +"'><a href='"+ preHref[i] +"' target='_blank'>"+ (i+1) +"</a></li>"
	}
	navBarHTML+="</ul>";

	document.getElementById("barnnerImg").innerHTML+=navBarHTML;
	document.getElementById("currBarnnerimage").innerHTML="<a href='"+ preHref[0] +"' target='_blank'><img src='"+ preload[0].src +"' alt='"+ preload[0].alt +"' class='bannerpic' border='0' style='filter:revealtrans(duration=2,transition=23);CURSOR: pointer;' /></a>";
	document.getElementById("navBar").childNodes[0].className="curr";
	if(photoarray.length > 1){
		
		imgNav=document.getElementById("currBarnnerimage").childNodes[0].childNodes[0];
		rollTimer=setTimeout("goNextSlider(1)",rollDelay*1000);
		for (var i=0;i<photoarray.length;i++){
			document.getElementById("navBar").childNodes[i].onmouseover=function(){
				clearTimeout(rollTimer);goNextSlider(this.id.substr(1,1));clearTimeout(rollTimer);
			};
			document.getElementById("navBar").childNodes[i].onmouseout=function(){
				rollTimer=setTimeout("goNextSlider("+tempcount+")",rollDelay*1000);
			};
		};
		imgNav.onmouseover=function(){
			clearTimeout(rollTimer)
		};
		imgNav.onmouseout=function(){
			rollTimer=setTimeout("goNextSlider("+tempcount+")",rollDelay*1000);
		};
	}
}
function goNextSlider(navIndex){
	clearTimeout(rollTimer);
	if (window.navigator.userAgent.indexOf("MSIE") >= 1 && window.navigator.appVersion<="7.0"){
		imgNav.filters.revealtrans.transition=23;
		imgNav.filters.revealtrans.Apply();
	}
	imgNav.src=preload[navIndex].src;

	if (window.navigator.userAgent.indexOf("MSIE") >= 1 && window.navigator.appVersion<="7.0"){
		imgNav.filters.revealtrans.Play();
	}
	imgNav.alt=preload[navIndex].alt;
	document.getElementById("currBarnnerimage").childNodes[0].href=preHref[navIndex];
	for (var i=0;i<photoarray.length;i++){
		document.getElementById("navBar").childNodes[i].className="";
	}
	document.getElementById("navBar").childNodes[navIndex].className="curr";
	if (++navIndex==photoarray.length){
		navIndex=0;
	}
	rollTimer=setTimeout("goNextSlider("+navIndex+")",rollDelay*1000);
	tempcount=navIndex;
}

//initpic();


(function($) {
    $.fn.ADRoll = function(settings) {
        settings = jQuery.extend({
            speed: "normal",
            num: 4,
            timer: 1000,
            direction: "top",
            imgHeight: "206"
        }, settings);
        return this.each(function() {
            $.fn.ADRoll.scllor($(this), settings);
        });
    };

    $.fn.ADRoll.scllor = function($this, settings) {
        var index = 0;
        var li = $(".flash_item li");
        var showBox = $(".img-box");
         li.hover(function() {
            if (intervalTime) {
                clearInterval(intervalTime);
            }
            index = li.index(this);
            intervalTime = setTimeout(function() {
                ShowText(index);
                ShowAD(index);
               
            }, 100);
        }, function() {
            clearInterval(intervalTime);
            intervalTime = setInterval(function() {
                ShowText(index);
                ShowAD(index); 
               
                index++;
                if (index == settings.num) {
                    index = 0;
                }
            }, settings.timer)
        });
        showBox.hover(function() {
            if (intervalTime) {
                clearInterval(intervalTime);
            }
        }, function() {
            clearInterval(intervalTime);
            intervalTime = setInterval(function() {
                ShowText(index);
                ShowAD(index);
                index++;
                if (index == settings.num) {
                    index = 0;
                }
            }, settings.timer);
        });
        var intervalTime = setInterval(function() {
            ShowText(index);
            ShowAD(index);
            index++;
            if (index == settings.num) {
                index = 0;
            }
        }, settings.timer);
        var ShowAD = function(i) {
           showBox.animate({ "top": -i * settings.imgHeight }, settings.speed);
           $(".flash_item li").eq(i).addClass("on").siblings().removeClass("on");  
        };
        var ShowText = function(i){
        	$("#flashText")[0].style.marginTop = -30*i+'px';
        }
    };
})(jQuery);


