// JavaScript Document

//Play file format : swf, flv, wma, wmv, avi, mp3, wav, dat
function playfile(file, width, height, autoplay, image, slink, flashvars){
	file=file.toLowerCase();
	if (Right(file,3)=="swf" || Right(file,3)=="xml"){
		EmbedFlash(file, width, height, flashvars);
	}
	if (Right(file,3)=="flv"){
		PlayFlash(file, width, height, autoplay, image, slink, flashvars)
	}
	if (Right(file,3)=="mp3" || Right(file,3)=="wma" || Right(file,3)=="wmv" || Right(file,3)=="avi" || Right(file,3)=="wav" || Right(file,3)=="dat"){
		PlayVideo(file, width, height, autoplay, flashvars);
	}
}


function PlayFlash(path, width, height, autoplay, image, slink, flashvars){
	auto=false; if (autoplay == true){auto=true;} var str_link=""; if(slink.length > 0){str_link="&link=" + slink + "&linktarget=_blank";} var str="<embed name=\"PlayerVideo\" id=\"PlayerVideo\" wmode=\"transparent\" type=\"application/x-shockwave-flash\" src=\"js/player.swf\" bgcolor=\"#FFFFFF\" quality=\"high\" allowscriptaccess=\"always\" allowfullscreen=\"true\" flashvars=\"file=" + path + "&image=" + image + str_link + "&autostart=" + auto + "&volume=100&overstretch=fit&showeq=true&linkfromdisplay=true\" width=\"" + width + "\" height=\"" + height + " wmode=\"transparent\"\"></embed>"; if(flashvars != ""){ $Get(flashvars).innerHTML=str;} else{document.write(str);} }

function PlayVideo(path, width, height, autoplay, flashvars){
	auto=false; if (autoplay == true){auto = true;} str="<object id=\"MediaPlayer\" classid=\"CLSID:6BF52A52-394A-11D3-B153-00C04F79FAA6\"  codeBase=\"http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715\" width=\"" + width + "\" height=\"" + height + "\"> <param name=\"autoplay\" value=\"" + auto + "\"/> <param name=\"autostart\" value=\"" + auto + "\"/> <param name=\"showcontrols\" value=\"true\">  <param name=\"EnableContextMenu\" value=\"true\"/> <param name=\"showstatusbar\" value=\"false\"/> <param name=\"URL\" value=\"" + path + "\"/><param name=\"wmode\" value=\"transparent\"><embed name=\"MediaPlayer\" type=\"application/x-mplayer2\" src=\"" + path + "\" autoplay=\"" + auto + "\" autostart=\"" + auto + "\" showcontrols=\"true\" enablecontextmenu=\"true\" showstatusbar=\"false\" pluginspage=\"http://www.microsoft.com/windows/windowsmedia/download\" wmode=\"transparent\" width=\"" + width + "\" height=\"" + height + "\"></embed> </object>"; if(flashvars != ""){ $Get(flashvars).innerHTML=str;} else{document.write(str);} }

function EmbedFlash(path, width, height, flashvars){if(height.length == 0){height="100%";} if(width.length == 0){width="100%";}str="<object id=\"FlashContent\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"  codeBase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0\" quality=\"high\" width=\"" + width + "\" height=\"" + height + "\"> <param name=\"flashvars\" value=\"" + flashvars + "\"/> <param name=\"allowScriptAccess\" value=\"always\">  <param name=\"allowFullScreen\" value=\"true\"/> <param name=\"movie\" value=\"" + path + "\"/> <param name=\"src\" value=\"" + path + "\"/> <param name=\"quality\" value=\"high\"/> <param name=\"wmode\" value=\"transparent\"/> <param name=\"bgcolor\" value=\"#000000\"/> <embed name=\"FlashContent\" src=\"" + path + "\" quality=\"high\" flashvars=\"" + flashvars + "\" allowFullScreen=\"true\"  allowScriptAccess=\"always\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"" + width + "\" height=\"" + height + "\"></embed> </object>"; document.write(str);}

function ChangeImage(path, pic_width, swf_height, flashvars){document.write('<object id="FlashContent" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="'+ pic_width +'" height="'+ swf_height +'" style="margin: 0px 0px 0px 0px;"> <param name="movie" value="'+ path +'"> <param name="quality" value="high"> <param name="wmode" value="transparent"> <param name="FlashVars" value="'+flashvars+'"> <embed style="margin: 0px 0px 0px 0px;" src="'+ path +'" FlashVars="'+flashvars+'" quality="high" width="'+ pic_width +'" height="'+ swf_height +'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer"> </object>');}

function $Get(idname) {
	if (document.getElementById) {
		return document.getElementById(idname);
	}
	//else if (document.getElementsByTagName) {
//		return document.getElementsByTagName(idname);
//	}
	else if (document.all) {
		return document.all[idname];
	}
	else if (document.layers) {
		return document.layers[idname];
	}
	else{
		return null;
	}
}

function Trim(iStr){
    while (iStr.charCodeAt(0) <= 32){iStr = iStr.substr(1);} while (iStr.charCodeAt(iStr.length - 1) <= 32) {iStr = iStr.substr(0, iStr.length - 1);} return iStr;
}

function Left(str, n) {
    if (n <= 0) {return "";} else if (n > String(str).length) {return str;} else {return String(str).substring(0, n);}
}

function Right(str, n) {if (n <= 0) return "";else if (n > String(str).length) return str;else {var iLen = String(str).length; return String(str).substring(iLen, iLen - n);}
}
function addAD(list, index, frame, source, link, tooltip, target)
{
    if(!list)
		list = new Array();
    if(!list[index]) list[index] = new Array();
    var newAd = new Object();
    newAd.source = source;
    newAd.link = link;
    newAd.tooltip = tooltip;
    newAd.target = target;
    list[index][frame] = newAd;
}

function showAd(list, id)
{
    if(document.body.clientWidth < 1000) return;
    var html = "";
    var adHTML = "<a href=\"{link}\" target='{target}' title='{tooltip}'><img src='{source}' alt='' style='border: none'/>";
    
    html += "<table border='0' cellpadding='0' cellspacing='0'>";
    for(var i in list)
    {
        html += "<tr><td style='border: 1px solid #ccc;'>";
        for(var j in list[i])
        {
            var ad = list[i][j];
            html += adHTML.replace("{link}", (ad.link)).replace("{target}", ad.target).replace("{source}", ad.source).replace("{tooltip}", ad.tooltip);
        }
        html += "</td></tr>";
    }
    html += "</table>";
    var divAd = document.createElement("DIV");
    divAd.style.position = "absolute";
    divAd.id = id;
    divAd.innerHTML = html;
    document.body.appendChild(divAd);
    return divAd;
}

function initAd(container)
{
    container.style.top = 0;
    container.style.display = "none";
}

function scrollAd()
{
	var floatLeft, floatRight;
	var scrollTop;
	var offsetLeft;
	var theWidth;
	var centerX = document.body.clientWidth / 2;
	
	floatLeft = window.floatLeft;
	floatRight = window.floatRight;
	
	floatLeft.style.display = "";
	floatRight.style.display = "";
	
	floatLeft.style.left = centerX - (982 / 2) - floatLeft.offsetWidth - 2+'px';
	floatRight.style.left = centerX + (982 / 2) + 2+'px';
	var offset;
	var pixelAmount;
	if (window.pageYOffset)
		scrollTop = window.pageYOffset
	else if (document.documentElement && document.documentElement.scrollTop)
		scrollTop = document.documentElement.scrollTop
	else if (document.body)
		scrollTop = document.body.scrollTop
	if(scrollTop < minTop) scrollTop = minTop;
	offset = scrollTop - parseInt(floatLeft.style.top);

	pixelAmount = Math.round(Math.abs(offset) / 8);

	if(offset < 0)
	{
		if(parseInt(floatLeft.style.top) - pixelAmount > scrollTop)
		{
			floatLeft.style.top = parseInt(floatLeft.style.top) - pixelAmount+'px';
			floatRight.style.top = parseInt(floatRight.style.top) - pixelAmount+'px';
		}
		else
		{
			floatLeft.style.top = scrollTop+'px';
			floatRight.style.top = scrollTop+'px';
		}
	}
	if(offset > 0)
	{
		if(parseInt(floatLeft.style.top) + pixelAmount < scrollTop)
		{
			floatLeft.style.top = parseInt(floatLeft.style.top) + pixelAmount+'px';
			floatRight.style.top = parseInt(floatRight.style.top) + pixelAmount+'px';
		}
		else
		{
			floatLeft.style.top = scrollTop+'px';
			floatRight.style.top = scrollTop+'px';
		}
	}
}

function startScroll()
{
    if(document.body.clienWidth < 1000) return;
    if(window.floatLeft == null && window.floatRight == null) return;
    window.setInterval("scrollAd()", delayTime);
}
