// JavaScript Document
// this file loads in the header of every page


$("#pageimage-shadow").ready(function(){
	if(!$("body").hasClass('homepage')) {
		if( $("#pageimage").length && $("#pagebody").length ) {
			$("#pageimage,#pageimage-shadow").hide().insertBefore("#pagebody").fadeIn('slow');
		}
	} else {
		$("#pageimage,#pageimage-shadow").fadeIn('slow');
	}
	$("#pageimage-placeholder").hide();
	$(".addthis_toolbox").insertBefore("#pagebody");
});

$(function(){
	/*$("button, .button").button();*/
	$.superbox(); 
	/*$("ul.suckerfish").superfish();*/ 
	
	//this function clears the default text in a form field when it takes focus: onFocus()
	function doClear(theText) {
	  if (theText.value == theText.defaultValue)
	   theText.value = "";
	}
	
	//this function refills the default text in a form field when it loses focus: onBlur()
	function doFill(theText,fillText) {
	  if(theText.value == "")
	   theText.value = fillText;
	}
	
	
	
	if( $(".phoneformat").length ) {
		$(".phoneformat").mask('(999) 999-9999');
	}
	
	if( $("#big-box").length ) {
		$("#big-box").css({'width':'950px','height':'360px'}).insertBefore("#pagebody");
	}
	
	$("#content h2:first").addClass('topless');
	
	/* build tabbed inner nav */
	if($("li.active .also-tabbed:first").length){
		var nav = $('<div id="nav-inner" />').append($('<div id="nav-inner-shadow" />')).append($("li.active .also-tabbed:first").clone().removeClass('also-tabbed'));	
		$(nav).removeClass('also-tabbed').insertBefore("#content");
	}
	
	/* change section */
	
	if($("#change-section").length){
		$("#change-section").change(function(){
			window.location = $(this).val();
			return true
		});
	}
	
	/* locator search */
	$("[name=categories]").change(function(){
		if($(this).val()==0){
			//alert("For Oil & Gas product inquiries please call 1-800-661-1436 and ask for Ken Pierson.");
			/* modal window */
			$modal = $('<div title="Important"><p><span class="ui-icon ui-icon-info" style="float:left; margin:0 7px 50px 0;"></span>For Oil & Gas product inquiries please call<br /> <strong>1-800-661-1436</strong> and ask for Ken Pierson.</p></div>');
			$modal.dialog({
				modal: true,
				width: 400,
				buttons: {
					Ok: function() {
						$( this ).dialog( "close" );
					}
				}
			});
			$("[name=categories] option:first").attr('selected',true);
			$("[name=categories]").trigger('change');
		}
	});
	
});
