var d = document, imgs = new Array(), zInterval = null,activebanner=0,def_class='', current = 0, nextbanner = 1, waitbanner = 0,bn_count=0, pause = false;

var bannerTimer;
var autoTime = 4; //saniye


function as_init() {

    autoTime = autoTime * 1000;
    if (!d.getElementById || !d.createElement) return;

    imgs = d.getElementById('rotator').getElementsByTagName('a');
    
    if (document.getElementById('cb_1')){
    def_class=document.getElementById('cb_1').className;
	as_cb_change(1);
    }

    if (imgs.length > 1) {

        
        bn_count = imgs.length;
        
        for (i = 1; i < imgs.length; i++) {
            imgs[i].xOpacity = 0;
            imgs[i].style.display = 'none';
          
        }
        imgs[0].style.display = 'block';
        imgs[0].xOpacity = .99;
                    
        bannerTimer = setTimeout(as_xfade, autoTime);
    } else if (imgs.length == 1) {
        imgs[0].style.display = 'block';
       
    }
}

function as_cb_change(new_act){
if (document.getElementById('cb_'+new_act)){

if (activebanner > 0){
document.getElementById('cb_'+ activebanner).className=def_class;
}

activebanner=new_act;

document.getElementById('cb_'+ activebanner).className=def_class+ '_hover';

}
}


function as_nextbanner() {
    t_next = nextbanner + 1;
    if (t_next > bn_count) {
        t_next = 1;
    }

    as_setbanner(t_next);

}

function as_prevbanner() {
    t_prev = current;
    if (t_prev < 1) {
        t_prev = bn_count;
    }
    as_setbanner(t_prev);

}

function as_setbanner(bnrid) {
    if (waitbanner == 0 && bnrid - 1 != current) {
	
        nextbanner = bnrid - 1;
     
        clearTimeout(bannerTimer);
        //stopBanner=0;
        as_xfade();
        //stopBanner=1;
        //setTimeout(as_xfade,autoTime);
     
    }
}

function as_xfade() {
as_cb_change(nextbanner +1);

    waitbanner = 1;
    cOpacity = imgs[current].xOpacity;
    //nIndex = imgs[current+1]?current+1:0;
    nIndex = nextbanner;
    nOpacity = imgs[nIndex].xOpacity;

    cOpacity -= .05;
    nOpacity += .05;

    imgs[nIndex].style.display = 'block';
        

    imgs[current].xOpacity = cOpacity;
    imgs[nIndex].xOpacity = nOpacity;
     

    setOpacity(imgs[current]);
    setOpacity(imgs[nIndex]);
    

    if (cOpacity <= 0) {
        imgs[current].style.display = 'none';
     
        current = nIndex;
        nextbanner = imgs[current + 1] ? current + 1 : 0;
        waitbanner = 0;
        bannerTimer = setTimeout(as_xfade, autoTime);
    }
    else {
        setTimeout(as_xfade, 30);
    }

    function setOpacity(obj) {
        if (obj.xOpacity > .99) {
            obj.xOpacity = .99;
            return;
        }

        obj.style.opacity = obj.xOpacity;
        obj.style.MozOpacity = obj.xOpacity;
        obj.style.filter = 'alpha(opacity=' + (obj.xOpacity * 100) + ')';
    }


}
