//ComWeb JavaScript file - 5Aug05
//06Jul07 DM menuListLG1
//08Aug07 AP Fix news ticker scroll


//This function is used by subscribe footer link
function SmallerWindow(url) {
	var iHeight=(window.screen.height - 50)/2;
	var iWidth=(window.screen.width)/2 + 50;
	iHeight=500;
	iWidth=700;
	var iTop = 50;//200
	var iLeft = 90;//200
	var winDetails = 'toolbar=no,menubar=no,scrollbars=yes,titlebar=no,left=' + iLeft + ',top=' + iTop + ',width=' + iWidth + ',height=' + iHeight;
	//alert(winDetails)
	var win3=window.open(url,'',winDetails); 
	win3.focus();
};

function externalAnchors()
{
	var anchors = document.getElementsByTagName("A");
	for (var i = 0; i<anchors.length; i++)
	{
		if ((anchors[i].className.indexOf('external')>-1) && (anchors[i].target==''))
		{
			anchors[i].target='_blank';
		}
	}
}


var bPaused = false, iTickerItem = 1, bItemPause = false, iLastScrollTop = -1, bFirstTime = true, oTicker, oTickerItems, oAllDivs, iPause = 6000;

function removeStyles(oTag)
{
	if (oTag.className)
		oTag.className = oTag.className.replace("cwInformation","").replace("cwContainer","").replace("cwNumber","");
	for (var iTag = 0; iTag < oTag.childNodes.length; iTag++){
		removeStyles(oTag.childNodes[iTag]);
	}
}

function scrollDown()
{
	if (bFirstTime){
		bFirstTime = false;
		var iTag = 0, oTickerDivs;
		oAllDivs = document.getElementsByTagName('DIV')
		for (var iFindTicker = 0; iFindTicker < oAllDivs.length; iFindTicker++){
			if ((oAllDivs[iFindTicker].className.indexOf('NewsTicker')>-1) && (oAllDivs[iFindTicker].className.indexOf('cwContainer')>-1)){
				oTicker = oAllDivs[iFindTicker].childNodes[0].childNodes[1];
				//oTickerItems = oAllDivs[iFindTicker].childNodes[0].childNodes[1];

				oTickerDivs = oAllDivs[iFindTicker].getElementsByTagName("DIV");
				if (false) {
					oTicker.className+=' NewsTickerContainer';
					
	//				removeStyles(oAllDivs[iFindTicker]);
					oAllDivs[iFindTicker].className = oAllDivs[iFindTicker].className.replace("cwInformation","").replace("cwContainer","").replace("cwNumber","");
					for (iTag = 0; iTag < oTickerDivs.length; iTag++)
						if (oTickerDivs[iTag].className)
							oTickerDivs[iTag].className = oTickerDivs[iTag].className.replace("cwInformation","").replace("cwContainer","").replace("cwNumber","");
				}

				iFindTicker = oAllDivs.length;
				oTicker.onmouseover = function() {bPaused=true};
				oTicker.onmouseout  = function() {bPaused=false};
			}
		}
	}
	if (oTicker)
		setTimeout('scrollDownAction();', iPause);
}

var bReset = true;
function scrollDownAction()
{
//	alert('BEFORE')
//	alert(oTicker.outerHTML)
//	oTicker.scrollTop=10;
//	alert('AFTER')
var iScrollLeft = 0, iItemNum = 0;
	if (!bPaused){
		if (bReset) {bReset = false; oTicker.scrollTop=1;}
		//alert(oTicker.scrollTop + " != " + iLastScrollTop)
		if (oTicker.scrollTop != iLastScrollTop){
			for (iTickerItem = 0; iTickerItem < oTicker.childNodes.length; iTickerItem++)
				if (oTicker.childNodes[iTickerItem].nodeType==1){
					//alert(oTicker.childNodes[iTickerItem].offsetParent.outerHTML)
					if (oTicker.scrollTop == (oTicker.childNodes[iTickerItem].offsetTop-1)){
						bItemPause = oTicker.childNodes[iTickerItem].className.toLowerCase().indexOf('tickeritem')>=0;
	//					alert(oTicker.childNodes[iTickerItem].className.toLowerCase().indexOf('tickeritem'));
						}
				}
			if (bItemPause){
				bItemPause = false;
				iLastScrollTop=oTicker.scrollTop;
				try{
					oTicker.scrollTop++;
				}catch (e){}
				setTimeout('scrollDownAction();', iPause);
			}
			else{
				iLastScrollTop=oTicker.scrollTop;
				try{
					oTicker.scrollTop++;
				}catch (e){}
				setTimeout('scrollDownAction();', 50);
			}
		}
		else{
			iLastScrollTop=0;
			bReset = true
			bItemPause = true
			setTimeout('scrollDownAction();', iPause);
		}
	}
	else{
		setTimeout('scrollDownAction();', 50);
	}
}

function ieHovers()
{
	var IE5 = "MSIE 5", IE6 = "MSIE 6", IE7 = "MSIE 7";
	var ver = navigator.appVersion;
	if (!((document.body.className.indexOf("menu-1")>-1) && (document.body.className.indexOf("framed2")>-1))){
		if ((ver.indexOf(IE5)>-1) || (ver.indexOf(IE6)>-1) || (ver.indexOf(IE7)>-1))
		{	
			processDivHovers("menuList");
			processDivHovers("menuListLG1");
			processDivHovers("instanceNav");
		}
	}
}

function processDivHovers(sDiv){
	var sCurrentClass, oMenuLIs, sApplyToClass, iMenuLI;
	sApplyToClass = 'bullet_closed';
	var oMenuDiv = document.getElementById(sDiv);
	if (oMenuDiv){
		oMenuLIs = oMenuDiv.getElementsByTagName("LI");
		for (iMenuLI = 0; iMenuLI < oMenuLIs.length; iMenuLI++)
		{
			//alert(oMenuLIs[iMenuLI].innerHTML);
			sCurrentClass = oMenuLIs[iMenuLI].className;
			//if (sCurrentClass.indexOf(sApplyToClass)>1)
			{
				oMenuLIs[iMenuLI].origClassName=oMenuLIs[iMenuLI].className;
				oMenuLIs[iMenuLI].hoverClassName=oMenuLIs[iMenuLI].className + " "+(oMenuLIs[iMenuLI].className+' ').replace(/ /g, 'iehover ')+" iehover";
				oMenuLIs[iMenuLI].onmouseover = function() {this.className = this.hoverClassName;};
				oMenuLIs[iMenuLI].onmouseout  = function() {this.className = this.origClassName;};
			}
		}
	}
}

/*
//see Bullet Fix in the right column at http://support.microsoft.com/kb/257819
function fixBulletPosition(e,all){
	if(!all)
		bullets.push(e);
	else{
		try{
			for(var i=bullets.length-1;i>=0;i--){
				e=bullets[i];
				var o=e.currentStyle.direction;
				var w=e.offsetWidth;
				if(o==document.getElementById("mainColumn").currentStyle.direction){
					e.style.position="relative";
					e.style.zIndex="9";
				}
				if(o!="rtl")
					e.style.marginLeft="-"+w+"px";

				var p=getParentByTagName(e,"UL");
				if(p){
					if(o!="rtl"){
						var pl=parseInt(p.style.marginLeft,10);
						if(!pl)
							pl=parseInt(p.currentStyle.marginLeft,10);
						if(!pl||w>pl)
							p.style.marginLeft=w+"px";
					}
				}
			}
		}
		catch(e){}
	}
}
*/
