/* initialize functions */
$(document).ready(function(){
	sfHover();
	anchors.doPopups();
	swapTabContent("tabOne");
});


/* =================================================================== */
// Tab functionality
function handleFlashTabs(sHref) {
	if (document.getElementById("displayModuleFlashMulti")) {
		var xmlFile = sHref.match(/#(.+)/)[1];
		var flashvars = {
		    xmlfile: sBaseUrl + "/corporate/flash/" + xmlFile + ".xml"
	    };
	    var params = {
	        base: ".",
	        wmode: "transparent"
	    };
	    var attributes = {};
        swfobject.embedSWF(sBaseUrl + "/corporate/flash/gallery.swf", "displayModuleFlashMulti", "467", "270", "8.0.0", false, flashvars, params, attributes);
	}
}
function swapTabContent(sName) {
	var sActiveTabClass = "selected";	
	
	$("div.tabContent").hide();
	$("div#" + sName +"Content").show();
	
	$("ul.tabs li a").click( function (e) {
		e.preventDefault();
		
		var sName = $(this).attr("id");
		
		$("ul.tabs li").removeClass(sActiveTabClass);
		$("div.tabContent").hide();
		$("div#" + sName +"Content").show();
		$("#"+sName).parent().addClass(sActiveTabClass);
		handleFlashTabs(this.href);
	});
	return false;
}
/* =================================================================== */

function rolloverImg() {
	$("#industries ul li a").hover(
		function () {
			var sIDname = $(this).parent().attr("id");
			var sRolloverDiv = $("#"+sIDname+"-over")
			var height = $(sRolloverDiv).height();
			
			$(sRolloverDiv).css("top", (-1 * height) - 5);
			$(sRolloverDiv).show();
			
		}, 
		function () {
			var sIDname = $(this).parent().attr("id");
			$("#"+sIDname+"-over").hide();
		}
	);

}

/* =================================================================== */

/* Browser check */
IS_DOM = (document.getElementById) ? true : false;
IS_IE = (document.all) ? true : false;
IS_MOZ = (IS_DOM && !IS_IE);

/* =================================================================== */

//call like cssjs('add',containerOBJ,classname);
	function cssjs(a,o,c1,c2){
		switch (a){
			case 'swap':
				o.className=!cssjs('check',o,c1)?o.className.replace(c2,c1):o.className.replace(c1,c2);
			break;
			case 'add':
				if(!cssjs('check',o,c1)){o.className+=o.className?' '+c1:c1;}
			break;
			case 'remove':
				var rep=o.className.match(' '+c1)?' '+c1:c1;
				o.className=o.className.replace(rep,'');
			break;
			case 'check':
				return new RegExp("(^|\\s)" + c1 + "(\\s|$)").test(o.className)
			break;
		}
	}
/* =================================================================== */
// various link functionality - popups, external, 
// original script taken from Jeremy Keith
// dependencies: cssjs(), addEvent()
var anchors = {
	a : Object,
	doPopups : function() {
		if (!document.getElementsByTagName) return false;
		var links = document.getElementsByTagName("a");
		for (var i=0; i < links.length; i++) {
			var anchor = links[i];
			if (anchor.getAttribute('href') && anchor.rel.match('external')) {
				anchor.onclick = function() {
					return anchors.openWin(this,"","");
				}
				cssjs('add',anchor,'external');
			}
		     if (cssjs('check',anchor,'pdf')) {
				anchor.onclick = function() {
					return anchors.openWin(this,"pdfWin","width=700, height=550,toolbar=no,resizable=yes");
				}
		    }
		    if (cssjs('check',anchor,'winClose')) {
				anchor.onclick = function() {
					var sLocation = $(this).attr("href");
					self.opener.location = sLocation;
					window.close();
				}
		    }
		   
		}
	},
		openWin : function(o,winName,params) {
			var win=window.open(o.href,"" + winName + "","" + params + "");
			win.focus();
			return false;
		}
}
/* =================================================================== */
/* DHTML Menus */
sfHover = function() {
	if (IS_IE) {
		var oNavUL = document.getElementById('navLevelOne');
		if (!oNavUL) return;
		var sfEls = oNavUL.getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				cssjs('add',this,' sfhover nonselected');
			}
			sfEls[i].onmouseout=function() {
				cssjs('remove',this,' sfhover nonselected');
			}
		}
	}
}