var show_news = false;
var news = "<b>*** Testing........... ***</b>";
var bgcolor = "#ffee99";
var borderstyle = 'dashed';
var bordercolor = '#004993';
var fontcolor = "#800080";
var fontface = "Verdana";
var fontSize = 8 + 'pt';
var toppos = 155 + "px";
var leftpos = 5  + 'px';
var tickerHeight = 15 + 'px';
var isShowing = false;

isIE = !!document.uniqueID;

function addEvent (obj, type, fn) {
		if (obj.addEventListener) {
			obj.addEventListener( type, fn, false );
		}else {
			if ( obj.attachEvent ) { 
				obj['e'+type+fn] = fn; 
				obj[type+fn] = function(){ obj['e'+type+fn]( window.event ); }; 
				obj.attachEvent( 'on'+type, obj[type+fn] ); 
			}
		}
}

var newsticker = {
	
	"show_div" :function(){
		var html;
		if (isIE) {
			html = "<MARQUEE BEHAVIOR=SCROLL DIRECTION=LEFT scrolldelay='120' scrollamount='4'>" + news + "</MARQUEE>";
			
		}else{
			html = "<blink>" + news + "</blink>";
		}
		if(show_news){
		var oDiv = document.createElement('div');
		oDiv.id = 'news_box';
		oDiv.setAttribute('id', 'news_box');
		oDiv.style.width = 1 + 'px';
		oDiv.style.height = tickerHeight;
		oDiv.style.overflow = 'hidden';
		oDiv.style.backgroundColor = bgcolor;
		oDiv.style.borderStyle = borderstyle;
		oDiv.style.borderColor =  bordercolor;
		oDiv.style.color =  fontcolor;
		oDiv.style.fontFamily = fontface;
		oDiv.style.fontSize = fontSize;
		oDiv.style.borderWidth = 1 + 'px';
		oDiv.style.position = 'absolute';
		oDiv.style.top = toppos;
		oDiv.style.left = leftpos;
		oDiv.style.zIndex = 250;
		oDiv.style.textAlign = 'center';
		oDiv.style.vaerticalAlign = 'middle';
		document.body.appendChild(oDiv);
		oDiv.innerHTML = html;
		var totWidth = newsticker.getWinWidth();
		newsticker.expandWidth(oDiv, 1, totWidth, 18, 10, 0.5,newsticker.tick);
		isShowing = true;
		}
	},
    "getWinWidth" : function(){
		if(window.innerWidth){
				//for Mozilla,Netscape and Firefox
				return (window.innerWidth - 16);
			}else{
				//for IE
				return (document.body.offsetWidth);
			}
	},
	"expandWidth" : function (elem,startWidth,endWidth,steps,intervals,powr, callback) { 
		if (elem.widthChangeIntval)
			window.clearInterval(elem.widthChangeIntval);
		
		var actStep = 0;
		elem.widthChangeIntval = window.setInterval(function() { 
			elem.currentWidth = newsticker.ease(startWidth,endWidth,steps,actStep,powr);
			elem.style.width = elem.currentWidth + "px"; 
			actStep++;
			if (actStep > steps) {
				window.clearInterval(elem.widthChangeIntval);
				if(elem.currentWidth == 1 && elem.style.display == 'block') {
					elem.style.display = 'none';
				}
				elem = null;
				// callback function
				if (typeof callback == 'string') eval(callback);
				else if(typeof callback == 'function') callback();
			}
		},intervals);
	},

	// animation steps calculation
	"ease" : function (minValue,maxValue,totalSteps,actualStep,powr) { 
		var delta = maxValue - minValue; 
		var stepp = minValue+(Math.pow(((1 / totalSteps) * actualStep), 1) * delta); 
		stepp = stepp == 0 ? 1 : stepp;
		return Math.ceil(stepp);
	},
	"tick" : function(){
		
	}
};
addEvent(window,'load',newsticker.show_div);
