// JavaScript Document

var dwzTickerInstances = new Array();

var dwzTicker = function(_type, _name, _swidth, _sheight, _bspeed, _pause, _classItem){
	this.operbr = navigator.userAgent.toLowerCase().indexOf('opera');
	this.singleb = new Array();
	this.type = _type;
	this.name = _name;
	this.wholem = '';	
	this.swidth = _swidth;
	this.bheight = _sheight; 
	this.classItem = _classItem;
	this.bspeed = _bspeed;
	this.restartb = 1;
	this.congr = 0;
	this.scrollerspause = _pause;
	this.firstrun = 0;
	
	this.jpj = -1;
	this.ipj = 0;
	this.ftt = 0;
	
	this.fst = new Array();
	this.fstns = 0;

	this.bslider = null;
	this.hidbslider = null;
	
	if(this.type ==	'h'){
		if(!document.layers)this.fst[0] = this.swidth;
	}else{
		if(this.operbr != -1)this.fst[0] = this.bheight - 4;
		else this.fst[0] = this.bheight + 1;
		if(document.layers)this.fstns = this.bheight + 5;
	}
			
	this.SetText = function(_text){
		this.singleb = _text;
		if(this.type ==	'h' && _text.length != 0){
			this.singleb.push(_text[0]);
		}
		for(x=0;x<this.singleb.length;x++){
			this.singleb[x] = this.singleb[x].replace(/@_apex2_@/gi, '"').replace(/@_apex_@/gi, "'")
		}
		this.ftt = this.singleb.length;
	}
	
	this.Start = function(){
		if(this.singleb.length == 0){
			return;		
		}
		
		this.wholem = '';
		var startSpace = '';
		var endSpace = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
		var startTag = '<table border="0" cellpadding="0" cellspacing="0" align="center"><tr><td><div class="'+this.classItem+'" >';
		var endTag = '</div></td></tr></table>';
		
		if(this.type == 'h'){
			for(var x=0; x<this.singleb.length; x++)
			{	
				this.wholem += '<td nowrap class="'+this.classItem+'" >' + startSpace + this.singleb[x] + endSpace + '</td>';
				this.singleb[x] = '' + startSpace + this.singleb[x] + endSpace + '';
			}
			
			if(!document.layers){
				this.wholem = '<nobr align="center" ><table border="0" cellpadding="0" cellspacing="0" ><tr>' + this.wholem + '</tr></td></nobr>';
			}
		}else{			
			for(var x=0;x<this.singleb.length;x++){
				this.singleb[x] = '<table border="0" cellpadding="0" cellspacing="0" height="' + this.bheight + '" ' +
								'align="center"><tr><td><div style="height:'+this.bheight+'px;" class="'+this.classItem+'">' + 
								this.singleb[x] + 
								'</div></td></tr></table>';
				this.wholem += this.singleb[x];
			}
			this.wholem += this.singleb[0];
		}
		
		var startIndex = 1;
		var subtractIndex = 1;
		if(this.type == 'v'){
			startIndex = 0;
			subtractIndex = 0;
		}
				
		if(document.all && this.operbr == -1){
			this.bslider = document.getElementById(this.name + "_bslider");
			this.hidbslider = document.getElementById(this.name + "_hidbslider");
			
			for(pp = startIndex;pp<this.singleb.length;pp++){
				if(this.type == 'h'){
					this.hidbslider.innerHTML = this.singleb[pp - subtractIndex];
					this.fst[pp] = this.hidbslider.offsetWidth;
				}else{
					this.hidbslider.innerHTML = this.singleb[pp - subtractIndex];
					this.fst[pp] = this.hidbslider.offsetHeight;
				}
			}	
			this.IeIni();			
		}else if(document.getElementById){
			this.bslider = document.getElementById(this.name + "_bslider");
			this.hidbslider = document.getElementById(this.name + "_hidbslider");
			
			for(pp=startIndex;pp<this.singleb.length;pp++){
				this.hidbslider.innerHTML = this.singleb[pp - subtractIndex];
				if(this.type == 'h'){
					this.fst[pp] = this.hidbslider.offsetWidth;
				}else{
					this.fst[pp] = this.hidbslider.offsetHeight;
				}
			}
			this.ns6ini();
		}
	}
		
	this.IeIni = function(){
		this.jpj = 0;		
		if(this.type == 'h'){
			this.bslider.style.pixelLeft = this.swidth;
			this.bslider.innerHTML = '<nobr>'+this.wholem+'</nobr>';
			this.IeScroll();
		}else{
			this.bslider.style.pixelTop = 0;
			this.bslider.innerHTML = this.wholem;
			setTimeout(this.name+".IeScroll()", this.scrollerspause);
		}		
	}
		
	this.ns6ini = function(){
		this.jpj = 0;
		if(this.type == 'h'){
			this.bslider.style.left = this.swidth;
			this.bslider.innerHTML = '<nobr>'+this.wholem+'</nobr>';
			this.ns6scroll();
		}else{
			this.bslider.style.top = 0;
			this.bslider.innerHTML = this.wholem;
			setTimeout(this.name+".ns6scroll()", this.scrollerspause);
		}
	}
	
	this.IeScroll = function(){
		if(this.ipj >= this.fst[this.jpj]){
			this.ipj = 0;
			this.jpj++;
			setTimeout(this.name+".IeScroll()", this.scrollerspause);
			return;
		}else if(this.jpj < this.ftt){
			if(this.bspeed > 0){
				this.congr = (this.fst[this.jpj] - this.ipj) % this.bspeed;
				if(this.congr == 0){
					if(this.type == 'h'){
						this.bslider.style.pixelLeft -= this.bspeed;
					}else{
						this.bslider.style.pixelTop -= this.bspeed;
					}
					this.ipj += this.bspeed;
				}else {
					if(this.type == 'h'){
						this.bslider.style.pixelLeft -= this.congr;
					}else{
						this.bslider.style.pixelTop -= this.congr;
					}
					this.ipj += this.congr;
					this.congr = 0;
				}
			}
			setTimeout(this.name+".IeScroll()",20);
			
		}else if(this.jpj == this.ftt){
			if(this.type == 'h'){
				if(this.ftt == this.singleb.length){
					for(pp=0;pp<this.singleb.length-1;pp++)
						this.fst[pp] = this.fst[pp + 1];
				}
				this.ftt = this.singleb.length - 1;
				this.bslider.style.pixelLeft = 0;
				this.bslider.innerHTML = '<nobr>'+this.wholem+'</nobr>';
			}else{
				this.bslider.style.pixelTop = 0;
			}
			this.jpj = 0;
			this.ipj = 0;
			this.IeScroll();
		}
	}

	this.ns6scroll = function(){
		if(this.ipj >= this.fst[this.jpj]){
			this.ipj = 0;
			this.jpj++;
			setTimeout(this.name+".ns6scroll()", this.scrollerspause);
			return;
		}else if(this.jpj < this.ftt){
			if(this.bspeed > 0){				
				this.congr = (this.fst[this.jpj] - this.ipj) % this.bspeed;				
				if(this.congr == 0){
					if(this.type == 'h'){
						this.bslider.style.left = parseInt(this.bslider.style.left) - this.bspeed;
					}else{
						this.bslider.style.top=parseInt(this.bslider.style.top) - this.bspeed;
					}
					this.ipj += this.bspeed;
				}else {
					if(this.type == 'h'){
						this.bslider.style.left = parseInt(this.bslider.style.left) - this.congr;
					}else{
						this.bslider.style.top = parseInt(this.bslider.style.top) - this.congr;						
					}
					this.ipj += this.congr;
					this.congr = 0;
				}
			}
			setTimeout(this.name+".ns6scroll()",20);
		}else if(this.jpj == this.ftt){
			if(this.type == 'h'){
				if(this.ftt == this.singleb.length){
					for(pp=0;pp<this.singleb.length-1;pp++){
						this.fst[pp] = this.fst[pp + 1];
					}
				}
				this.ftt = this.singleb.length - 1;
				this.bslider.style.left = 0;
				this.bslider.innerHTML = '<nobr>'+this.wholem+'</nobr>';
			}else{
				this.bslider.style.top = 0;
			}
			this.jpj = 0;
			this.ipj = 0;			
			this.ns6scroll();
		}
	}		
	
	this.GoUp = function(){
		if(this.congr == 0 && this.bspeed > 0 && this.bspeed < 16){
			this.bspeed *= 2;
			this.restartb = this.bspeed;
		}
		if(this.congr == 0 && this.bspeed == 0){
			this.bspeed = this.restartb;
		}
		return;
	}
	
	this.GoStop = function(){
		if(this.congr == 0 && this.bspeed > 0){
			this.bspeed = 0;
		}else if(this.bspeed == 0){
			this.bspeed = this.restartb;
		}
		return;
	}
	
	this.GoDown = function(){
		if(this.congr == 0 && this.bspeed > 1){
			this.bspeed /= 2;
			this.restartb = this.bspeed;
		}
		if(this.congr == 0 && this.bspeed == 0){
			this.bspeed = 1;
			this.restartb = this.bspeed;
		}
		return;
	}
		
	this.InsertHtmlCode = function(){
		var html = '';
		if(this.type == 'h'){
	  		html += '<div style="position:relative;overflow:hidden;width:'+this.swidth+'px;height:'+this.bheight+'px;clip:rect(0 '+this.swidth+' '+this.bheight+' 0);" onMouseover="'+this.name+'.bspeed=0;" onMouseout="'+this.name+'.bspeed='+this.name+'.restartb;"><div id="'+this.name+'_bslider" style="position:relative;height:'+this.bheight+'px;"></div></div><div id="'+this.name+'_hidbslider" style="position:absolute;visibility:hidden;height:'+this.bheight+'px;"></div>';
		}else{
			html += '<div style="position:relative;overflow:hidden;width:'+this.swidth+'px;height:'+this.bheight+'px;clip:rect(0 '+this.swidth+' '+this.bheight+' 0);" onMouseover="'+this.name+'.bspeed=0;" onMouseout="'+this.name+'.bspeed='+this.name+'.restartb;"><div id="'+this.name+'_bslider" style="position:relative;width:'+this.swidth+'px;"></div></div><div id="'+this.name+'_hidbslider" style="position:absolute;visibility:hidden;width:'+this.swidth+'px;"></div>';
		}
		document.getElementById(this.name+"_Container").innerHTML = html;
	}
}


var dwzTypeWriter = function(_name, _width, _height, _speed, _pause, _classItem){
	this.name = _name;
	this.dwidth = _width; 
	this.dheight = _height;
	this.dspeed = _speed; 
	this.pause = _pause;
	this.expclass = _classItem;
	this.mesaj = '';
	this.jj = 0;
	this.div = null;
	this.messages = new Array();
	this.curMsgIndex = 0;
		
	this.SetText = function(_text){
		this.messages = _text;
		for(x=0;x<this.messages.length;x++){
			this.messages[x] = this.messages[x].replace(/@_apex2_@/gi, '"').replace(/@_apex_@/gi, "'")
		}
		this.curMsgIndex = 0;
	}
	
	this.InsertHtmlCode = function(){
		var html = '';		
		html += '<div class="' + this.expclass + '" style="position:relative;width:' + this.width + ';';
		html += 'height:' + this.height + ';"><span id="'+this.name+'_expdiv"></span></div>';		
		document.getElementById(this.name + "_Container").innerHTML = html;
	}
	
	this.iens6exp = function(){
		this.jj++;
		if(this.jj <= this.mesaj.length){
			this.div.innerHTML = this.mesaj.substring(0,this.jj) + "_";
			setTimeout(this.name+".iens6exp()", this.dspeed);
		}else{
			this.curMsgIndex++;
			this.jj = 0;
			if(this.curMsgIndex >= this.messages.length){
				this.curMsgIndex = 0;				
			}
			this.mesaj = this.messages[this.curMsgIndex];
			setTimeout(this.name+".iens6exp()", this.pause);
		}
	}
	
	this.Start = function(){
		if(this.messages.length == 0){
			return;		
		}		
		this.mesaj = this.messages[0];		
		if(document.getElementById){
			this.div = document.getElementById(this.name+'_expdiv');
			this.div.innerHTML = '';
			this.iens6exp();
		}else if(document.all){
			this.div = document.getElementById(this.name+'_expdiv');
			this.div.innerHTML = '';
			this.iens6exp();
		}
	}
}



var dwzTwinkler = function(_name, _width, _height, _speed, _pause, _classItem){
	
	this.div = null;
	this.name = _name;
	this.width = _width; 
	this.height = _height; 
	this.speed = _speed; 
	this.pause = _pause;
	this.className = _classItem;
	this.mesaj = '';
	this.messages = new Array();
	this.curMsgIndex = 0;
	
	this.kk = 0;
	this.scant = '';
	
	this.SetText = function(_text){
		this.messages = _text;
		for(x=0;x<this.messages.length;x++){
			this.messages[x] = this.messages[x].replace(/@_apex2_@/gi, '"').replace(/@_apex_@/gi, "'")
		}
		this.curMsgIndex = 0;
	}
	
	this.InsertHtmlCode = function(){
		var html = '';
		html += '<div class="'+this.className+'" style="position:relative;width:'+this.width+';';
		html += 'height:'+this.height+';"><span id="'+this.name+'_scandiv"></span></div>';				
		document.getElementById(this.name + "_Container").innerHTML = html;
	}
	
	this.Scanner = function(){
		if(this.kk <= this.mesaj.length){
			this.scant = '';
			for(var jk=0;jk<this.mesaj.length;jk++){
				if(jk == this.kk)
					this.scant += '<font color="red">'+this.mesaj.charAt(this.kk)+'</font>';
				else 
					this.scant += this.mesaj.charAt(jk);
			}
			if(document.getElementById||document.all)
				this.div.innerHTML = this.scant;
			else{
				this.div.document.write('<div '+this.className+'>'+this.scant+'</div>');
				this.div.document.close();
			}
			
			if(this.kk < this.mesaj.length){
				this.kk++;
				setTimeout(this.name+".Scanner()", this.speed);
			}else{
				if(document.getElementById||document.all){
					this.div.innerHTML = '<u>'+this.scant+'</u>';
					this.kk++
					setTimeout(this.name+".Scanner()", this.speed);
				}else{
					this.div.document.write('<div '+this.className+'><u>'+this.scant+'</u></div>');
					this.div.document.close();
					this.kk++;
					setTimeout(this.name+".Scanner()", this.speed);
				}
			}
		}else{
			this.curMsgIndex++;
			this.kk = 0;
			if(this.curMsgIndex >= this.messages.length){
				this.curMsgIndex = 0;				
			}
			this.mesaj = this.messages[this.curMsgIndex];
			setTimeout(this.name+".Scanner()", this.pause);			
		}
	}
	
	this.Start = function(){
		if(document.getElementById)
			this.div = document.getElementById(this.name+'_scandiv');
		else if(document.all)
			this.div = eval(this.name+'_scandiv');
		
		if(this.messages.length == 0){
			return;		
		}
		this.mesaj = this.messages[this.curMsgIndex];
		this.Scanner();
	}
}


var dwzBlinker = function(_name, _width, _height, _speed, _pause, _blinks){
	this.name = _name;
	this.div = null;
	this.width = _width;
	this.height = _height;
	this.pause = _pause;
	this.speed = _speed;
	this.blinks = _blinks;
	this.messages = new Array();
	this.curMsgIndex = 0;
	this.stopRequest = false;
	
	this.resumesmsb = this.blinks;
		
	this.SetText = function(_messages){
		this.messages = _messages;
		for(x=0;x<this.messages.length;x++){
			this.messages[x] = this.messages[x].replace(/@_apex2_@/gi, '"').replace(/@_apex_@/gi, "'")
		}
		this.curMsgIndex = 0;
		if(this.messages.length == 1){
			this.blinks = 0;
			this.resumesmsb = this.blinks;
		}
	}
	
	this.Blink = function(){
		this.div.innerHTML = this.messages[this.curMsgIndex];
		
		if(this.stopRequest){
			this.div.style.top = 0;
			setTimeout(this.name+".Blink()", 50);
			return;
		}
		
		if(this.blinks > 0 || this.messages.length == 1){
			if(!this.div.style.top ||
			    this.div.style.top.toString().substring(0, 1) == '0'){				
				this.div.style.top = this.height;
			}else{
				this.div.style.top = 0;	
				this.blinks--;
			}
			setTimeout(this.name+".Blink()", this.speed);
		}else{
			
			this.blinks = this.resumesmsb;
			if(this.curMsgIndex == this.messages.length - 1) 
				this.curMsgIndex = 0;
			else 
				this.curMsgIndex++;
				
			setTimeout(this.name+".Blink()", this.pause);
		}	
	}
		
	this.onMouseover = function(){
		this.stopRequest = true;		
	}
	
	this.onMouseout = function(){
		this.stopRequest = false;
	}
	
	this.InsertHtmlCode = function(){
		var html = '';
			
		html += '<div style="position:relative;overflow:hidden;width:'+this.width+';height:'+this.height+';clip:rect(0 '+this.width+' '+this.height+' 0);"  onMouseover="'+this.name+'.onMouseover()" onMouseout="'+this.name+'.onMouseout()" ><div id="'+this.name+'_blinkingdiv" style="position:relative;width:'+this.width+';height:'+this.height+';"></div></div>';
		
		document.getElementById(this.name+"_Container").innerHTML = html;
	}
	
	this.Start = function(){
		if(document.getElementById){
			this.div = document.getElementById(this.name+'_blinkingdiv');
			this.Blink();
		}else if(document.all){
			this.div = eval(this.name+'_blinkingdiv');
			this.Blink();
		}
	}

}


var dwzTickerFade =
{	
	rotate:function(config){
		if (config.$ticker.get(0)._hoverstate=="over"){
			setTimeout(function(){dwzTickerFade.rotate(config)}, config.rotatespeed);
		}
		else{
			config.$messages.eq(config.currentmsg).fadeOut(config.animateduration, function(){
				config.currentmsg=(config.currentmsg < config.$messages.length-1)? config.currentmsg + 1 : 0;
				config.$messages.eq(config.currentmsg).fadeIn(config.animateduration, function(){
					setTimeout(function(){dwzTickerFade.rotate(config)}, config.rotatespeed);
				})
			})
		}
	},
	
	setupticker:function(config){
		config.$messages = config.$ticker.find('div.'+config.msgclass).hide();
		config.currentmsg = Math.min(0, config.$messages.length - 1);
		config.$messages.hide().eq(config.currentmsg).fadeIn(config.animateduration);
		setTimeout(function(){dwzTickerFade.rotate(config)}, config.rotatespeed);
	},
	
	define:function(config){
	  jQuery(document).ready(function($){									  
			config.$ticker=$('#'+config.id);
			if (config.$ticker.length==0)
				return;
			config.$ticker.css({overflow:'hidden'}).hover(
				function(){this._hoverstate="over"},
				function(){this._hoverstate="out"}
			)
			dwzTickerFade.setupticker(config);
		})
	}
} 





function dwzTickerCreate(){
	for(var x=0; x<dwzTickerInstances.length; x++){	
		if(dwzTickerInstances[x].type == 'fade'){
			var html = "";
			for(i=0; i<dwzTickerInstances[x].texts.length; i++){
				html += '<div class="' + dwzTickerInstances[x].classItem + '">' 
				html += (dwzTickerInstances[x].texts[i].replace(/@_apex2_@/gi, '"').replace(/@_apex_@/gi, "'") + '</div>');
			}
			var el = document.getElementById(dwzTickerInstances[x].name+"_Container");
			el.innerHTML = html;	
			
			dwzTickerFade.define({
				id: 				dwzTickerInstances[x].name+"_Container",
				msgclass: 			dwzTickerInstances[x].classItem, 
				msgsource: 			"inline",
				rotatespeed: 		dwzTickerInstances[x].pause,
				animateduration: 	dwzTickerInstances[x].duration
			})
		}else{			
			if(dwzTickerInstances[x].type == 'h' || dwzTickerInstances[x].type == 'v'){			
				eval(dwzTickerInstances[x].name + " = new dwzTicker('" + 
											dwzTickerInstances[x].type + "', '" + 
											dwzTickerInstances[x].name + "', " + 
											dwzTickerInstances[x].width + ", " + 
											dwzTickerInstances[x].height + ", " + 
											dwzTickerInstances[x].speed + ", "+
											dwzTickerInstances[x].pause + ", " +
											"'" + dwzTickerInstances[x].classItem + "'" +
											")");	
			
			}else if(dwzTickerInstances[x].type == 'typewriter'){			
				eval(dwzTickerInstances[x].name + " = new dwzTypeWriter('" + 
												dwzTickerInstances[x].name + "', " + 
												dwzTickerInstances[x].width + ", " + 
												dwzTickerInstances[x].height + ", " + 
												dwzTickerInstances[x].speed + ", "+
												dwzTickerInstances[x].pause + ", " +
												"'" + dwzTickerInstances[x].classItem + "'" +
												")");	
				
			}else if(dwzTickerInstances[x].type == 'twinkler'){			
				eval(dwzTickerInstances[x].name + " = new dwzTwinkler('" + 
												dwzTickerInstances[x].name + "', " + 
												dwzTickerInstances[x].width + ", " + 
												dwzTickerInstances[x].height + ", " + 
												dwzTickerInstances[x].speed + ", "+
												dwzTickerInstances[x].pause + ", " +
												"'" + dwzTickerInstances[x].classItem + "'" +
												")");	
				
			}else if(dwzTickerInstances[x].type == 'blinker'){
				eval(dwzTickerInstances[x].name + " = new dwzBlinker('" + 
												dwzTickerInstances[x].name + "', " + 
												dwzTickerInstances[x].width + ", " + 
												dwzTickerInstances[x].height + ", " + 
												dwzTickerInstances[x].speed + ", "+
												dwzTickerInstances[x].pause + ", " +
												dwzTickerInstances[x].blinks +
												")");	
				
			}
		
			var el = eval(dwzTickerInstances[x].name);
			el.SetText(dwzTickerInstances[x].texts);
			el.InsertHtmlCode();
			el.Start();
		}
	}
}

