//////////////////////////////////////////////////////////////
//SlideBanner script . Progamming by Pham Duy (duy120779@yahoo.com)
//Copyright(c) 2006
//////////////////////////////////////////////////////////////
function SlideBanner(id , container , docking)
{
	this.ClassID = id ;
	this.ID = container;
	this.Width = 0;
	this.Height = 0;	
	this.Docking = docking;
	this.HtmlImages = new Array();	
	this.SlideStep = 5;
	//////////////////////////////	
}

SlideBanner.prototype.AddImage = function(img , url , tooltips)
{
	var sHTML = '<a href="' + url +'" target="_blank"><img src="' + img +'" border="0" alt="' + tooltips +'"></a>';
	this.HtmlImages[this.HtmlImages.length] = sHTML;
}

SlideBanner.prototype.AddFlash = function(swf , w , h)
{
	var sHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0"'
	sHTML += " width='" + w + "' height='" + h + "'>";
	sHTML += "<param name=movie value='" + swf + "'>";
	sHTML += "<param name=quality value=high>";
	sHTML += "<embed src='" + swf + "' quality='high' pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width='" + w + "' height='" + h + "'></embed></object>";
	
	this.HtmlImages[this.HtmlImages.length] = sHTML;
}

SlideBanner.prototype.AddHtml = function(html)
{
	this.HtmlImages[this.HtmlImages.length] = html;
}

SlideBanner.prototype.Init = function()
{
	var obj = document.getElementById(this.ID);
	if(!obj) return;
	
	if(!document.all) {
		obj.style.display = 'none';
		return;//IE only
	}
	
	if(obj)
	{
		obj.style.position = 'absolute';
		
		obj.innerHTML = '';
		for(var i = 0;i < this.HtmlImages.length; i ++)
		{
			obj.innerHTML += this.HtmlImages[i];
		}

		this.Width = parseInt(obj.offsetWidth);
		this.Height = parseInt(obj.offsetHeight);
	}	
}

SlideBanner.prototype.UpdatePosition = function()
{
	var obj = document.getElementById(this.ID);
	if(!obj) return;
	
	this.Width = parseInt(obj.offsetWidth);
	this.Height = parseInt(obj.offsetHeight);
	
	if(!document.all) {
		obj.style.display = 'none';
		return;//IE only
	}
	if(window.screen.width <= 800) {
		obj.style.display = 'none';
		return;//Width 800px only
	}

	var nScrollLeft = parseInt(document.body.scrollLeft);
	var nScrollTop = parseInt(document.body.scrollTop);
	var nWinWidth = parseInt(document.body.clientWidth);
	var nWinHeight = parseInt(document.body.clientHeight);	
	
	if(this.Docking == 'left') //
		obj.style.left = 0;
	else
		obj.style.left = nScrollLeft + nWinWidth - this.Width - 5;

	var currTop = parseInt(obj.style.top);
	if(isNaN(currTop)) currTop = 0;
	
	if(currTop < nScrollTop) 
	{
		currTop += this.SlideStep;
		if(currTop > nScrollTop) currTop = nScrollTop;
	}
	else if(currTop > nScrollTop) 
	{
		currTop -= this.SlideStep;
		if(currTop < 0) currTop = 0;
	}
	
	obj.style.top = currTop + "px";
	
	setTimeout(this.ClassID + ".UpdatePosition()" , 1);
}
