var globalImageURL	= '/Skins/Corporate/Resources/Images/';

function getElementsByClassName(className,tag,elm)
{
	var testClass = new RegExp("(^|\\s)" + className + "(\\s|$)");
	var tag = tag || "*";
	var elm = elm || document;
	var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
	var returnElements = [];
	var current;
	var length = elements.length;
	for(var i=0; i<length; i++)
	{
		current = elements[i];
		if(testClass.test(current.className))
		{
			returnElements.push(current);
		}
	}
	return returnElements;
}

function addLoadEvent(func)
{
	var oldonload = window.onload;
	if (typeof window.onload != 'function')
	{
		window.onload = func;
	}
	else
	{
		window.onload = function()
		{
			oldonload();
			func();
		}
	}
}

function getStyle(oElm,strCssRule)
{
	var strValue = "";
	if(document.defaultView && document.defaultView.getComputedStyle)
	{
		strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
	}
	else if(oElm.currentStyle)
	{
		strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){
			return p1.toUpperCase();
		});
		strValue = oElm.currentStyle[strCssRule];
	}
	return strValue;
}

function createCSS(selector,declaration,media)
{
	// test for IE
	var ua		= navigator.userAgent.toLowerCase();
	var isIE	= (/msie/.test(ua)) && !(/opera/.test(ua)) && (/win/.test(ua));

	// create the style node for all browsers
	var style_node = document.createElement("style");
	style_node.setAttribute("type","text/css");
	style_node.setAttribute("media",media);

	// append a rule for good browsers
	if(!isIE) style_node.appendChild(document.createTextNode(selector + " {" + declaration + "}"));

	// append the style node
	document.getElementsByTagName("head")[0].appendChild(style_node);

	// use alternative methods for IE
	if (isIE && document.styleSheets && document.styleSheets.length > 0)
	{
		var last_style_node = document.styleSheets[document.styleSheets.length - 1];
		if(typeof(last_style_node.addRule) == "object") last_style_node.addRule(selector,declaration);
	}
}

function arrowOn(element_id,dir)
{
	$(element_id).src = ( dir == 'next' ? globalImageURL + 'arrow.right.hover.gif' : globalImageURL + 'arrow.left.hover.gif' );
}
function arrowOff(element_id,dir)
{
	$(element_id).src = ( dir == 'next' ? globalImageURL + 'arrow.right.gif' : globalImageURL + 'arrow.left.gif' );
}

function arrowBlueToBlack()
{
	var arr_blues	= getElementsByClassName('arrowBlue');
	var arr_blacks	= getElementsByClassName('arrowBlack');

	for(var i=0; i<arr_blues.length; i++)
	{
		arr_blues[i].onmouseover = function()
		{
			this.className = 'arrowBlack';	
		}
		arr_blues[i].onmouseout = function()
		{
			this.className = 'arrowBlue';	
		}
		// Set new background position if on mac :/
		if(navigator.platform.indexOf("Mac") != -1)
		{
			arr_blues[i].style.backgroundPosition = '0px 4px';
		}
	}
	for(var j=0; j<arr_blacks.length; j++)
	{
		arr_blacks[j].onmouseover = function()
		{
			this.className = 'arrowBlue';	
		}
		arr_blacks[j].onmouseout = function()
		{
			this.className = 'arrowBlack';	
		}
		// Set new background position if on mac :/
		if(navigator.platform.indexOf("Mac") != -1)
		{
			arr_blacks[j].style.backgroundPosition = '0px 4px';
		}
	}
}

function coverBottomRepos()
{
	var arrCover	= getElementsByClassName('coverBottom');
	if(arrCover.length > 0)
	{
		for(var i=0; i<arrCover.length; i++)
		{
			arrCover[i].style.bottom = 2 + 'px';
		}
	}	
}

// Turn blue to black on hover...
addLoadEvent(arrowBlueToBlack);

// Reposition bottomCovers for the 3rd level menu if on mac
if(navigator.platform.indexOf("Mac") != -1)
{
	addLoadEvent(coverBottomRepos);
}
