function hasClassName( obj, objClass ) {

	return new RegExp( '\\b'+objClass+'\\b' ).test( obj.className )

}





function setCaseStudies( index ) {

	if ( caseStudies.length <= 0 ) return;

	for (var i = 0; i < caseStudies.length; i++) {

		if ( i != index ) {

			if ( !hasClassName( caseStudies[i], 'hidden' ) ) {

				caseStudies[i].className += ' hidden';

			}

		} else {

			if ( hasClassName( caseStudies[i], 'hidden' ) ) {

				caseStudies[i].className = caseStudies[i].className.replace( 'hidden', '' );

			}

		}

	}

}



var caseStudies = [];

var currentSelectedLinkName="";

function initCaseStudy() {

	
	var allDivs = document.getElementsByTagName( 'div' );

	if ( allDivs.length <= 0 ) return;

	for ( var i = 0; i < allDivs.length; i++ ) {

		// get the case study DIVs

		if ( hasClassName( allDivs[i], 'item' ) ) {

			caseStudies[caseStudies.length] = allDivs[i];

		}



		// set the menu onclick event

		if ( hasClassName( allDivs[i], 'detailMenu' ) ) {

			var _oRoot = allDivs[i];

			var arrLinks = _oRoot.getElementsByTagName( 'a' );
			var menuItems = _oRoot.getElementsByTagName( 'li' );

			var len = arrLinks.length;
			
			for ( var j = 0; j < arrLinks.length; j++ ) {
				
				if ( hasClassName( arrLinks[j], 'toggle' ) ) {

										
					arrLinks[j].linkindex = j;
										
					if ( hasClassName( menuItems[j], 'selected' ) ) {
						
						currentSelectedLinkName=arrLinks[j].name;
					}

					arrLinks[j].onclick = function() {
						
						currentSelectedLinkName=this.name;
						
						setCaseStudies( this.linkindex );
						
						resetInactiveLinks( _oRoot, 'li', this.linkindex );

						return false;

					};

				} else {

					arrLinks[j].onclick = function() {
						
						//setCaseStudies( this.linkindex );
												
						currentSelectedLinkName=this.name;
						resetInactiveLinks( _oRoot, 'li', this.linkindex );

						return false;

					};

				}

			}

		}

	}


	// hide case studies

	 setCaseStudies( 0 );

}



function resetInactiveLinks( oRoot, subElem, oIndex ) {

	var menuItems = oRoot.getElementsByTagName( subElem );

	for ( var i = 0; i < menuItems.length; i++ ) {

		if ( i != oIndex ) {

			if ( hasClassName( menuItems[i], 'selected' ) ) {

				menuItems[i].className = menuItems[i].className.replace('selected', '');

			}

		} else {

			if ( !hasClassName( menuItems[i], 'selected' ) ) {

				menuItems[i].className += ' selected';

			}

		}

	}

}

function getElementsByClassName(oElm, strTagName, strClassName){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++){
		oElement = arrElements[i];		
		if(oRegExp.test(oElement.className)){
			arrReturnElements.push(oElement);
		}	
	}
	return (arrReturnElements);
}
// returns array of element objects for any fragment of classname which matches strFuzzyClass
function fuzzyClassName(strTagName,strFuzzyClass)	{
	var el=document.getElementsByTagName(strTagName);var o=new Array();var oC=0;
	for (var i=0;i<el.length;i++)	{
		if (el[i].className.indexOf(strFuzzyClass)!=-1)	{
			o[oC]=el[i];
			oC++;
		}
	}
	return o;
}

function dimensions(){
	var dimensionContainers=getElementsByClassName(document,"div","columnContainer");
	if(dimensionContainers.length==0){return;}
	var dimensionContainer=dimensionContainers[0];
	var columns=getElementsByClassName(dimensionContainer,"div","column");
	for(var i=0;i<columns.length;i++){
		columns[i].arrLength=columns.length;
		columns[i].onmouseover=function(){
			for(var j=0;j<this.arrLength;j++){
				if(columns[j]==this){continue;}
				var transDiv=document.createElement("div");
				transDiv.className="transDiv";
				transDiv.style.background="url(../img/bg.col.hover.png)";
				//transDiv.style.background="#ff9900";
				/* png fix for IE 6 and below*/
				/*@cc_on @*/
				/*@if (@_jscript_version <= 5.6)
					transDiv.style.background="none";
					transDiv.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../img/bg.col.hover.png', sizingMethod='scale')";
				/*@end @*/
				
				transDiv.style.position="absolute";
				transDiv.style.left="0";
				transDiv.style.top="0";
				transDiv.style.width=columns[j].offsetWidth;
				transDiv.style.height=columns[j].offsetHeight;
				columns[j].appendChild(transDiv);
			}
		}
		columns[i].onmouseout=function(){
			var transDivs=getElementsByClassName(dimensionContainer,"div","transDiv");
			for(var k=0;k<transDivs.length;k++){
				transDivs[k].parentNode.removeChild(transDivs[k]);
			}
		}
	}
	
}
function closeAreas(){
	var closeLinks=fuzzyClassName("a","closeArea");
	if(closeLinks.length==0){return;}
	for(var i=0;i<closeLinks.length;i++){
		var regx=new RegExp(/closeArea\(([\w]+?)\)/);
		closeLinks[i].classToClose=closeLinks[i].className.match(regx)[1];
		closeLinks[i].onclick=function(){
			var action = (this.firstChild.nodeValue.indexOf("Close")!=-1) ? "close" : "open";
			var closeElems=getElementsByClassName(document,"*",this.classToClose);
			if(closeElems.length==0){return;}
			if(action=="close"){
				this.firstChild.nodeValue=this.firstChild.nodeValue.replace("Close","Open");
				for(var j=0;j<closeElems.length;j++){
					closeElems[j].style.display="none";
					var showElem=closeElems[j].parentNode.firstChild;
					showElem.toShow=closeElems[j];
					while(typeof showElem.nextSibling != "undefined"){
						if(showElem.className==this.classToClose+"Show"){
							break;
						}
						if(typeof showElem.nextSibling == "undefined"){
							showElem=false;
							break;
						}
						showElem=showElem.nextSibling;
					}
					if(showElem!=false){
						showElem.onmouseover=function(){
							this.toShow.style.display="block";
							this.toShow.style.position="absolute";
							this.toShow.style.left="0";
							this.toShow.style.padding="10px";
							this.toShow.style.width="199px";
						}
						showElem.onmouseout=function(){
							this.toShow.style.display="none";
							this.toShow.style.position="static";
							this.toShow.style.width="auto";
							this.toShow.style.padding="0";
						}
					}
					closeElems[j].onmouseover=function(){
						this.style.display="block";
						this.style.position="absolute";
						this.style.width="199px";
						this.style.padding="10px";					}
					closeElems[j].onmouseout=function(){
						this.style.display="none";
						this.style.position="static";
						this.style.width="auto";
						this.style.padding="0";
					}
				}
			}
			else if(action=="open"){
				for(var j=0;j<closeElems.length;j++){
					closeElems[j].style.display="block";
					closeElems[j].onmouseover=function(){
						return;
					}
					closeElems[j].onmouseout=function(){
						return
					}
				}
				this.firstChild.nodeValue=this.firstChild.nodeValue.replace("Open","Close");
			}
		}
	}
}

function generatePrinterFriendlyURL(printerFriendlyURL){

	var printerFriendlyURLAppended = printerFriendlyURL + "&title=" + currentSelectedLinkName;
	window.open(printerFriendlyURLAppended);
	
}

function btnRollovers(){
	var btns=fuzzyClassName("input","hover");
	
	var imgs=fuzzyClassName("img","hover");
	for(var m=0;m<imgs.length;m++){
		btns.push(imgs[m]);
	}
	
	for(var i=0;i<btns.length;i++){
		var onstaterx=new RegExp(/hover\(([\w]+?)\)/);
		btns[i].onstate="_"+btns[i].className.match(onstaterx)[1];
		btns[i].onmouseover=function(){
			var imgsrc=this.src;
			var imgfile=this.src.substring(0,this.src.lastIndexOf("."));
			var newImg=imgfile+this.onstate+this.src.substring(this.src.lastIndexOf("."));
			this.src=newImg;
		}
		btns[i].onmouseout=function(){
			this.src=this.src.replace(this.onstate,"");
		}
	
	}
}

function delCookie(name, path,domain) 
 {
     var expireNow = new Date();
     expireNow.setTime(expireNow.getTime() - 1);
     document.cookie = name + "=" +
     "; expires=" +expireNow.toGMTString()+";domain="+domain+";path="+path;
     
   }

function delete_domain_all_cookies (path,domain)
{
        // Get cookie string and separate into individual cookie phrases:
        var cookie_string = "" + document.cookie;
        var cookie_array = cookie_string.split (";");
 	 // Try to delete each cookie:
        for (var i = 0; i < cookie_array . length; ++ i)
        {
               var single_cookie = cookie_array [i].split ("=");
               
              var name = unescape (single_cookie [0]);
			 
               delCookie (name,path,domain);
	        }
		  		 
}




var solutionsPage=false;
window.onload = function() {
	
	initCaseStudy();
	btnRollovers();
	/*
	if(solutionsPage){
		dimensions();
		closeAreas();
	}
	*/

}




