﻿

//WP Rotator Object
//------------------
function wpRotator() {
	//timers references
	this.t_DoTrans = null;
	this.t_DoTransFF = null;
	this.t_BefTrans = null;
	this.t_Init2 = null;
  //functions
	this.doTrans = wpRotatorDoTrans;
	this.init1 = wpRotatorInit1;
	this.init2 = wpRotatorInit2;
	this.befTrans = wpRotatorBefTrans;
	this.doTransFF = wpRotatorDoTransFF;
	this.start = wpRotatorStart;
	this.pick = wpRotatorPick;
	this.play = wpRotatorPlay;
	//settings
	this.div = "undefined";
	this.zIndexSet = 0;
	this.interim = 1000;
	this.interim_play = 1000;
	this.transition = 1000;
	this.imgstr = new Array();
  this.linkstr = new Array(); //optional: anchor link open tag (if linkable)
  this.clslinkstr = new Array(); //optional: anchor link close tag (if linkable)
	//
	//Variables for setTimeout Accessing...
	vdiv = this.div;
	//alert(vdiv.id)
	zIndexSet = this.zIndexSet;
	interim = this.interim;
	interim_play = this.interim_play;
	transition = this.transition;
  imgstr = this.imgstr;
  linkstr = this.linkstr;
  clslinkstr = this.clslinkstr;
  //
  imgarr = new Array();
	//
  fademi = 1;
  //
  vcurr = 0;
  vnext = 0;
  vssdiv = null;
  //
  stepc = 20 * (transition / 1000);
  dif = 0.00;
  op = 1.00;
  dif = (1.00 / stepc);
  //
  uagent = window.navigator.userAgent.toLowerCase();
  IEB = (uagent.indexOf('msie') != -1) ? true : false;
  //
  dstr1 = '<div id="';
  dstr2 = '">';
  dstr3 = '<img id="' + vdiv + '' + '_img';
  dstr4 = '" src="';
  dstr5 = '" alt="Banner" title="Banner"></img>';
  dstr6 = '</div>';
}

function wpRotatorPick(set_vnext){
	window.clearTimeout(this.t_DoTrans);
	window.clearTimeout(this.t_DoTransFF);
	window.clearTimeout(this.t_BefTrans);
	window.clearTimeout(this.t_Init2);

  if (IEB == true) {
		objc = document.getElementById(vdiv + '' + vcurr);
		objn = document.getElementById(vdiv + '' + set_vnext);
		objc.style.visibility = "hidden";
		objn.style.visibility = "visible";
		//
		vcurr = set_vnext;
		vnext = set_vnext + 1;
	}
	else{
		objc = document.getElementById(vdiv + '' + vcurr);
		objn = document.getElementById(vdiv + '' + set_vnext);
		objc.style.visibility = "visible";
		objn.style.visibility = "visible";
		objc.style.opacity = 0.00;
		objn.style.opacity = 1.00;
		objc.style.zIndex = zIndexSet+2;
		objn.style.zIndex = zIndexSet+3;
		//
		vcurr = set_vnext;
		vnext = set_vnext;
	}
}

function wpRotatorPlay(){
    if (imgarr.length > 1) {
        if ((IEB == true) || (fademi == 0)) {
            this.t_DoTrans = setTimeout('wpRotatorDoTrans()', interim_play);
        } else {
            this.t_BefTrans = setTimeout('wpRotatorBefTrans()', interim_play);
        }
    }
		if (vnext >= imgarr.length) {
				vnext = 0;
  }
}

function wpRotatorDoTrans() {
    if (IEB == true) {
        vssdiv.filters[0].apply();
    }
    objc = document.getElementById(vdiv + '' + vcurr);
    //alert(vdiv.id)
    objn = document.getElementById(vdiv + '' + vnext);
    objc.style.visibility = "hidden";
    objn.style.visibility = "visible";
    if (IEB == true) {
        vssdiv.filters[0].play();
    }
    vcurr = vnext;
    vnext = vnext + 1;
    if (vnext >= imgarr.length) {
        vnext = 0;
    }
    this.t_DoTrans = setTimeout('wpRotatorDoTrans()', (transition + interim));
}

function wpRotatorDoTransFF() {
    op = op - dif;
    objc = document.getElementById(vdiv + '' + vcurr);
    objn = document.getElementById(vdiv + '' + vnext);
    if (op < (0.00)) {
        op = 0.00;
    }
    objc.style.opacity = op;
    objn.style.opacity = 1.00;
    if (op > (0.00)) {
        this.t_DoTransFF = setTimeout('wpRotatorDoTransFF()', 50);
    } else {
        objc.style.zIndex = zIndexSet+2;
        objn.style.zIndex = zIndexSet+3;
        this.t_BefTrans = setTimeout('wpRotatorBefTrans()', interim);
    }
}

function wpRotatorBefTrans() {
	//alert(imgarr.length);
    vcurr = vnext;
    vnext = vnext + 1;
    if (vnext >= imgarr.length) {
        vnext = 0;
    }
    op = 1.00;
    objc = document.getElementById(vdiv + '' + vcurr);
    objn = document.getElementById(vdiv + '' + vnext);
    objc.style.visibility = "visible";
    objn.style.visibility = "visible";
    objc.style.zIndex = zIndexSet+3;
    objn.style.zIndex = zIndexSet+2;
    objc.style.opacity = 1.00;
    objn.style.opacity = 1.00;
    wpRotatorDoTransFF();
}

function wpRotatorInit2() {
	//alert(imgarr.length);
	//alert(transition)
    if (imgarr.length > 0) {
        objc = document.getElementById(vdiv + '' + 0);
        objc.style.visibility = "visible";
    }
    if (imgarr.length > 1) {
        if ((IEB == true) || (fademi == 0)) {
            vcurr = 0;
            vnext = 1;
            this.t_DoTrans = setTimeout('wpRotatorDoTrans()', interim);
        } else {
            vcurr = 0;
            vnext = 0;
            this.t_BefTrans = setTimeout('wpRotatorBefTrans()', interim);
        }
    }
}

function wpRotatorInit1() {
    i = 0;
    innertxt = '';
    //alert(linkstr.length)
    for (i = 0; i < imgarr.length; i++) {
        innertxt = innertxt + 
			dstr1 + vdiv + '' + i + 
			dstr2 + (linkstr.length==0 ? '':linkstr[i]) + 
			dstr3 + i + 
			dstr4 + imgstr[i] + 
			dstr5 + (clslinkstr.length==0 ? '':clslinkstr[i]) + 
			dstr6;
    }
    vssdiv.innerHTML = '' + innertxt;
    //alert(vssdiv.innerHTML);
    this.t_Init2 = setTimeout('wpRotatorInit2()', 200);
}

function wpRotatorStart()
{	
	vdiv = this.div;
	zIndexSet = this.zIndexSet;
	interim = this.interim;
	transition = this.transition;
    imgstr = this.imgstr;
    linkstr = this.linkstr;
    clslinkstr = this.clslinkstr;
	//
    for(var i=0;i<imgstr.length;i++){
		imgarr[i] = new Image();
		imgarr[i].src = imgstr[i];
		//alert(imgstr[i]);
    }
	//alert(imgarr.length);
    //
    dstr3 = '<img id="' + this.div + '_img';
    //
    stepc = 20 * (transition / 1000);
    dif = 0.00;
    op = 1.00;
    dif = (1.00 / stepc);
	//
	vssdiv = document.getElementById(vdiv);
	vssdiv.style.zIndex = zIndexSet;
	vssdiv.style.filter = "progid:DXImageTransform.Microsoft.Fade(Overlap=1.00,duration=" + (transition/1000) + ")"
//
	this.init1();
}



