﻿//<!-- working with IE, NS6+, Opera7.1+
// tickerservices.GetTickerDataAsXML;
var MWJScrollers = new Array();
var gtimer = 100;
function Ticker(thisName, msgArrayName, whichdiv, imgSeparatorPath, imgFillDivPath, width, height, bgColor, onColor, offColor, speed, timer, isView)
{
	if (!isView)
		return;

	this.MWJ_isOpera6 = ( navigator.userAgent.toLowerCase().indexOf( 'opera' ) + 1 && !document.childNodes ) || ( window.ScriptEngine && ScriptEngine().indexOf( 'InScript' ) + 1 );
	this.operbr=navigator.userAgent.toLowerCase().indexOf('opera');
	this.MWJ_isOpera6 = ((this.MWJ_isOpera6 || this.operbr>=0))
	//alert(this.MWJ_isOpera6);
	// this script is working in Opera7.1+
	// parametar tickera
/*	if ((this.MWJ_isOpera6 || this.operbr)>0)
		this.tickerVar = 2;
	else
*/
	this.tickerVar = 2;
	this.thisName = thisName;
	this.whichdiv = whichdiv;
	this.wwidth = width; //scroller width: change to your own;
	this.wheight = height; //scroller height: change to your own;
	this.wbcolor = bgColor; //background color: change to your own;
	this.sspeed = speed; //scroller's speed: change to your own;
	this.timer = timer;
	this.restart = speed;
	this.rspeed = speed;
	this.imgRazmak = imgSeparatorPath; // space between msgs
	this.sWidth = "3px";
	this.sHeight = "1px";
	
	this.wwholemessage = fillTicker(this, msgArrayName, height, imgFillDivPath,onColor, offColor, height);
	writeTicker(this, imgFillDivPath);

	this.iedivw = eval(document.getElementById(whichdiv)); //eval(whichdiv); 
	if (this.iedivw=='undefined' || !this.iedivw)
		return;
		
	this.cell = eval(document.getElementById('IEcell')); //getElement('IEcell'); //document.getElementById('IEcell'); //eval('IEcell'); // wslider
	if (this.cell=='undefined' || !this.cell)
		return;

	this.sizeupw = 0;
	this.nDivLen = 0;

	this.StartTicker = StartTicker;
	this.goup = goup;
	this.godown = godown;
	
	if(document.all)
		this.iemarqueew = iemarqueew;
	else  // NS6
		this.iemarqueew = ns6marqueew;
	//this.ieslidew = ieslidew;
			
	var index = 0;
	index = MWJScrollers.length;
	MWJScrollers[index] = this;
	this.index = index;
	this.StartTicker();
}


function fillTicker(obj, msgTicker, wheight, imgRazmak, onColor, offColor, height){
	var i, byBrowser;
		
	var txt = ''; 
/*	if(document.all)
		byBrowser = "padding:0px;";
	else  // NS6
		byBrowser = "padding:0px;";
*/
	var separator = "";
	if (obj.imgRazmak == "" && imgRazmak!="")
	    if(obj.sHeight > wheight)
	        separator = '<img src="'+ imgRazmak + '" border="0" height="'+wheight+'"/>' ;
	    else
		    separator = '<img src="'+ imgRazmak + '" border="0" width="'+obj.sWidth+'" height="'+obj.sHeight+'"/>' ;
	else
		separator = obj.imgRazmak;
	var tekstualnih = 0;
	txt += '<table border="0" cellspacing="0" cellpadding="0" height="100%"><tr>';
	for(var i=0;i<msgTicker.length;i++){
		var flagic = msgTicker[i].toString();
		if (msgTicker[i]!=""){


			if(flagic.indexOf("<img") > -1){
				txt += '<td valign="top" rowspan="2" style="height:'+wheight+'px;background-color: '+ offColor + 
				    ';" onmouseover=\'this.style.backgroundColor="' + onColor + '";\' onmouseout=\'this.style.backgroundColor="' + 
				    offColor + '";\'><nobr>' + msgTicker[i] + '</nobr></td><td>' + separator + '</td>';
			}
			else{
				txt += '<td valign="top" style="padding-top:3px;height:'+wheight+'px;background-color: '+ offColor + 
				    ';" onmouseover=\'this.style.backgroundColor="' + onColor + '";\' onmouseout=\'this.style.backgroundColor="' + 
				    offColor + '";\'><nobr>' + msgTicker[i] + '</nobr></td><td>' + separator + '</td>';
				tekstualnih = tekstualnih + 1;
			}
		}
	}
	txt += '</tr><tr>'
	for(var i=0;i<tekstualnih;i++){
		txt += '<td>&nbsp;</td>'
	}


	txt +='</tr></table>';
	return txt;
}

function goup(){
	if(this.sspeed != this.rspeed*8){
		this.sspeed = this.sspeed*2;
		this.restart = this.sspeed;
	}
}
function godown(){
	if(this.sspeed > this.rspeed){
		this.sspeed = this.sspeed/2;
		this.restart = this.sspeed;
	}
}

function StartTicker(){
	if (this.wwholemessage=="")
		return;
		
	this.iemarqueew();
}

function getWidth(obj, ww)
{
	var w = ww;
	if (obj=='undefined'){
		w += obj.offsetWidth;
		alert(obj.tagName);
		getWidth(obj.Parent, w);
	}
	return w + 4;
}
	
function iemarqueew(){
	// IE
	if (this.iedivw=='undefined' || !this.iedivw)
		return;
	this.iedivw.innerHTML = '<nobr>'+ this.wwholemessage +'</nobr>';
	var nD = this.iedivw.cloneNode(true);
	if(this.cell.childNodes.length==0)
		this.cell.appendChild(nD);
	else{
		var ch = this.cell.childNodes[0];
		this.cell.replaceChild(nD, ch);
	}

	if (this.MWJ_isOpera6)  // to delay loading images in OPERA!!!
		for(var x=0; x<1000000;x++);			// to get true value!

	this.nDivLen = getWidth(this.cell, this.cell.offsetWidth); //this.cell.offsetWidth;
	var w = this.nDivLen;
	// clear cell
	this.cell.innerHTML = "";
	
	var i=1;
	if (this.wwidth==0)
		return;
	var tekst = this.wwholemessage;
	this.wwholemessage = "<td>" + this.wwholemessage + "</td>";
	while((this.wwidth*2)>w || ((this.wwidth*2)<w && i<this.tickerVar)){
		this.wwholemessage += "<td>" + tekst + "</td>";
		w += this.nDivLen; i++;
	}
	this.wwholemessage = '<table border="0" cellspacing="0" cellpadding="0" height="100%"><tr>' + this.wwholemessage + '</tr></table>';
	this.iedivw.innerHTML = this.wwholemessage;
	this.sizeupw = - this.nDivLen; //-w / 2; //-w / i;//- this.nDivLen;
	this.iedivw.style.pixelLeft = this.sizeupw;
	if (this.sspeed<0){
		this.iedivw.style.pixelLeft = 0;
	}
	ieslidewIndex(this.index);
}

//**************************************************************************** NS6+
function ns6marqueew(){
	if (this.iedivw=='undefined')
		return;
		
	this.iedivw.innerHTML = '<nobr>'+ this.wwholemessage +'</nobr>';
	var nD = this.iedivw.cloneNode(true);
	nD.innerHTML = '<table border="0" cellspacing="0" cellpadding="0" height="100%"><tr><td>' + nD.innerHTML + '</td></tr></table>'
	if(this.cell.childNodes.length==0)
		this.cell.appendChild(nD);
	else{
		var ch = this.cell.childNodes[0];
		this.cell.replaceChild(nD, ch);
	}
		
	for(var x=0; x<1000000;x++);			// to get true value!
		
	this.nDivLen = this.cell.offsetWidth + 6; // - 8;  // 8 is empiric comparison of NS7+ and IE to avoid hoping !!! if imgSeparator doesn't exist
	var w = this.nDivLen;
	// clear cell
	this.cell.innerHTML = "";
	
	var i=1;
	this.wwholemessage = "<td>" + this.wwholemessage + "</td>";
	var tekst = this.wwholemessage;
	while((this.wwidth*2)>w || ((this.wwidth*2)<w && i<this.tickerVar)){
		this.wwholemessage += tekst;
		w += this.nDivLen; i++;
	}
	this.wwholemessage = '<table border="0" cellspacing="0" cellpadding="0" height="100%"><tr>' + this.wwholemessage; + '</tr></table>';
	
	this.iedivw.style.width = w;
	this.iedivw.innerHTML = this.wwholemessage;
	this.sizeupw = -this.nDivLen; //-w / i;//-this.nDivLen;
	this.iedivw.style.pixelLeft = this.sizeupw;
	if (this.sspeed<0){
		this.iedivw.style.left = "0px";
	}
	ns6slidewIndex(this.index);
}

// *************************************************************************** GLOBALS
//IE
function ieslidewIndex(index){
	var obj = MWJScrollers[index];
	
	if (obj.sspeed!=0){
		if((obj.iedivw.style.pixelLeft<=0 && obj.sspeed>0) || (obj.iedivw.style.pixelLeft>=obj.sizeupw && obj.sspeed<0)){
			obj.iedivw.style.pixelLeft += obj.sspeed;
		}else{
			if (obj.sspeed<0){
				obj.iedivw.style.pixelLeft = 0 + obj.sspeed;
			}
			else{
				obj.iedivw.style.pixelLeft = obj.sizeupw + obj.sspeed;
				}
		}
	}
	setTimeout("ieslidewIndex(" + obj.index + ")", obj.timer);
}

// NS6+
function ns6slidewIndex(index){
	var obj = MWJScrollers[index];

	if (obj.sspeed!=0){
		var leftVal = parseInt(obj.iedivw.style.left);
		var newPosition;
		if((leftVal<=0 && obj.sspeed>0) || (leftVal>=obj.sizeupw && obj.sspeed<0)){
			newPosition = leftVal + obj.sspeed;
		}else{
			if (obj.sspeed<0){
				newPosition = obj.sspeed;
			}
			else{
				newPosition = obj.sizeupw + obj.sspeed;
			}
		}
		obj.iedivw.style.left = newPosition.toString() + "px";
	}
	setTimeout("ns6slidewIndex(" + obj.index + ")", obj.timer);
}

function writeTicker(obj, imgSrc){
	if (obj.wwholemessage.length==0){
		document.write('<img src="'+ imgSrc + '" border="0" width="' + obj.wwidth + '" height="1"/>');
		return;
	}
	
	if(document.getElementById || document.all){
		
/*		if (obj.MWJ_isOpera6)
		{
			//alert(obj.MWJ_isOpera6);
  //			ifrm = new mFrame(wwidth,wheight,msgTicker);
  //			ifrm.buildScroller();
		}
		else{
*/			// IE, Opera 7.1+ i NS6+
			document.write('<div style="border:0px solid green;padding:0px; position:relative;overflow:hidden;width:'+ obj.wwidth+'px;height:'+ obj.wheight +'px;clip:rect(0px '+ obj.wwidth+'px '+ obj.wheight+'px 0px);background-color:'+ obj.wbcolor+';">');
		 	document.write('<div id="'+ obj.whichdiv +'" name="'+ obj.whichdiv +'" style="vertical-align:middle; border:0px solid green; padding:0px;position:relative;height:'+ obj.wheight+'px;"></div>');
			document.write('</div>');
//		}
	}else{ // NS4
		document.write('<ilayer width='+ obj.wwidth +'px height='+ obj.wheight+'px name="wslider1" bgcolor='+ obj.wbcolor+'>');
	 	document.write('<layer id="'+ obj.whichdiv +'" width='+ obj.wwidth+'px height='+ obj.wheight+'px></layer>');
		document.write('</ilayer>');
	}
}

function GoToURL(url){
	window.location = url;
}
//-->