// JavaScript Document
//Function to Load additional CSS file.
function loadCSS(){
	filename = "../css/hasJS.css";
	var fileref=document.createElement("link");
	fileref.setAttribute("rel", "stylesheet");
	fileref.setAttribute("type", "text/css");
	fileref.setAttribute("href", filename);
	
	document.getElementsByTagName("head")[0].appendChild(fileref)
}
$(document).ready(function() {loadCSS();});

function showLoader(){
    $("#loading")
    .css({display:'block'})
       .css({position:'absolute',backgroundColor:'#FFFFFF',width:'100%',height:'100%',left:'0',top:'0',opacity:'.75'})
        .html('<img src="../images/loadingAnimation.gif" alt="Wait" />');
}

function hideLoader(){
	$("#loading").html('');
}

/* 

START jQUERY 

*/
$(document).ready(function(){	
	fontResizer('12px','14px','18px');

	// $('a[rel=offsite], #nav-global a[rel!=boxy]').click(function() {
	// 	var href = this.href;
	// 
	// 	Boxy.alert("Older site", function() {
	// 		location.href = href;
	// 	}, {title: 'Message'});
	// 	return false;
	// });

	$('a[rel=boxy]').boxy({modal:true, fixed: false, y: 200});

	setPipelineHover();

	/*
	
	INITIALIZE IE NAVMAIN FIX
	
	*/
	
	$("#nav-global li").hover(
		function () {
			$(this).addClass("sfhover");
			//IE7 fix to make sure the nested UL closes
			$(this).removeClass("sfhover-off");
		}, 
		function () {
			$(this).removeClass("sfhover");
			//IE7 fix to make sure the nested UL closes
			$(this).addClass("sfhover-off");
		}
	);
	
	/*
	
	INITIALIZE FIELD VALUE RESET (looks for presence of "alt" attribute in the input tag)
	
	*/
	$("input[alt!='']").focus(function(){
		setValue(this,"onfocus"); 
		return false;
	});
	$("input[alt!='']").blur(function(){
		setValue(this,"onblur"); 
		return false;
	});
	

	$("ul#tab-selector li a").click(function() {
		$(".tab-block").hide();
		$($(this).attr('href')).show();

		$("ul#tab-selector li, ul#tab-selector li a").removeClass('on');
		$(this).addClass('on');
		$(this).parent().addClass('on');

		return false;
	});

	if(self.document.location.hash.length) {
		$("ul#tab-selector li a[href=#" + self.document.location.hash.substring(1) + "]").click();
	}

	$("a.tabbed").click(function() {
		var a_href = this.href.split("#");
		$(".tab-block").hide();
		$('.tabbed').removeClass('on');
		$(this).addClass('on');
		$(this).parent().addClass('on');
		$("#Page" + a_href[1]).show();

		return false;
	});

	if(($(".tab-block").length > 0) && ($(".tab-block:visible").length == 0)) {
		$(".tabbed:first").addClass('on');
		$(".tabbed:first a").addClass('on');
		$(".tab-block:first").show();
	}

	if($("#map_ma").length > 0) {
		initialize_maps();
	}
 });
 
/* 

BEING SETVALUE

setValue clear's a text input's value and resets it to the input's alt attribute if the user doesn't enter a value 

*/

function setValue(pEl,pSwitch) {	
	if (pSwitch == "onfocus") {
		if (pEl.value == pEl.alt) {
			pEl.value = "";	
		}
	}
	if (pSwitch == "onblur") {
		if (pEl.value == "") {
			pEl.value = pEl.alt;
		}
	}
}

/*

END SETVALUE

*/

function setPipelineHover() {
	$('.productName a').hover(function () {
		$(this).addClass('red');
		$(this).parent().next().children().addClass('red');
	}, function() {
		$(this).removeClass('red');
		$(this).parent().next().children().removeClass('red');
	});

	$('.progressBar').hover(function () {
		$(this).addClass('red');
		$(this).parent().prev().children().addClass('red');
	}, function() {
		$(this).removeClass('red');
		$(this).parent().prev().children().removeClass('red');
	});

	$('.progressBar').click(function() {
		$(this).parent().prev().children().click();
	});
}

function initialize_maps() {
  if (GBrowserIsCompatible()) {
    var map_ma = new GMap2(document.getElementById("map_ma"));
    map_ma.setCenter(new GLatLng(42.399679, -71.2753), 15);
    map_ma.setUIToDefault();

	map_ma.addOverlay(new GMarker(new GLatLng(42.399679, -71.2753)));

    var map_oh = new GMap2(document.getElementById("map_oh"));
    map_oh.setCenter(new GLatLng(39.4364100, -83.8054340), 15);
    map_oh.setUIToDefault();

	map_oh.addOverlay(new GMarker(new GLatLng(39.4364100, -83.8054340)));
  }
}
