﻿var theTimer;
var width;
var height;
var bottom;
var textStyle = "flash_text";
var textLinkStyle = "flash_text";
var buttonLineOn = "#f60";
var buttonLineOff = "#000";
var TimeOut = 5000;
var pics = new Array(); 
var links = new Array();
var texts = new Array();
var adNum;
var count;
function ChangeImg(n){
    adNum = n;
    window.clearInterval(theTimer);
    adNum = adNum-1;
    nextAd();
}

function nextAd(){         
    if(adNum < count){
        adNum++;
    }else{
        adNum = 1;
    } 
    theTimer = setTimeout("nextAd()", TimeOut); 
    document.images.imgInit.src = pics[adNum - 1];
    document.images.imgInit.alt = texts[adNum - 1];	
    document.getElementById('link' + adNum).style.background = buttonLineOn;
    for (var i = 1; i <= count; i++)
    {
        if(i != adNum){
            document.getElementById('link'+i).style.background = buttonLineOff;
        }
    }	
    document.getElementById('focustext').innerHTML = '<a href="' + links[adNum - 1] + '" target="_blank">' + texts[adNum - 1] + '</a>';
    document.getElementById('imgLink').href = links[adNum - 1];
}

function RotateFlash(w, h, b){
   
    width = w;
    height = h;
    bottom = b;
    adNum = 0;
    
    this.add = Add;
    this.play = Play;
   
    function Add(pic, link, text){
        var index = pics.length;
        pics[index] = pic;
        links[index] = link;
        texts[index] = text; 
    }
    
    function Play(){
        count = pics.length;

        document.write('<style type="text/css">');
        document.write('#focuseFrom{width:' + width + 'px;margin:0px auto; padding:0px; height:' + (height + bottom) + 'px; overflow:hidden;}');
        document.write('#txtFrom{height:' + bottom + 'px;line-height:' + bottom + 'px;width:' + width + 'px;overflow:hidden;}');
        document.write('#imgTitle{width:' + width + ';top:-' + (bottom + 14) + 'px;height:18px;}');
        document.write('</style>');
        document.write('<div id="focuseFrom">');       

        document.write('<a id="imgLink" href="' + links[0] + '" target="_blank"><img src="' + pics[0] + '" onerror="this.src=\'/Global/images/nopic.gif\'" name="imgInit" width="' + width + '" height="' + height + '" border="1" alt="' + texts[0] + '" class="imgClass"></a><div id="txtFrom"><span id="focustext" class="' + textStyle + '">' + texts[0] + '</span></div>')
        document.write('<div id="imgTitle"><div id="imgTitle_down">');

        for(var i = 0; i < count; i++){
            document.write('<a id="link' + (i + 1) + '" href="javascript:ChangeImg(' + (i + 1) +')" class="linkButton" style="cursor:pointer" title="' + texts[i] + '">' + (i + 1) + '</a>');
        }
        
        document.write('</div></div></div>');
        nextAd(); 
    } 
}