﻿// JavaScript Document
// Mathews Javascripts - Scripts in use throughout the site
// Sleeping Giant Studios, LLC
// Created by David Ellenwood - 09/05/2007


/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			GLOBAL VARIABLE FOR FLASH DETECTION & GENERIC FUNCTIONS
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */

// These are related files: include/javaScript/activeX_fix.js, globalVariables.js, flashDetection.asp
// GF 11/21/2006
var bShown=0;

// Functions to add and remove event handling unobtrusively
// Thanks to Peter Paul Kock @ http://www.quirksmode.org/js/eventSimple.html

function addEventSimple(obj,evt,fn) {
	if (obj.addEventListener)
		obj.addEventListener(evt,fn,false);
	else if (obj.attachEvent)
		obj.attachEvent('on'+evt,fn);
}

function removeEventSimple(obj,evt,fn) {
	if (obj.removeEventListener)
		obj.removeEventListener(evt,fn,false);
	else if (obj.detachEvent)
		obj.detachEvent('on'+evt,fn);
}


/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 			MASTHEAD CUSTOMER SEARCH FORM
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */

// Add some events to the customer search in the site masthead.
function intMiniSearch() {
	if(document.getElementById('miniSearch')) {
		
		// Get some variables...
		var miniSearchFrm	= document.getElementById('miniSearch');
		var defaultValue	= 'Customer Name (First and/or Last)';
		
		// Highlight & clear the search box on focus...
		miniSearchFrm.txtSearchValue.onfocus = function() {
			if(this.value == defaultValue) {this.value = '';}
			this.style.color = '#333';
		}
		
		// Return to the default values if no search term was entered...
		miniSearchFrm.txtSearchValue.onblur = function() {
			if(this.value == '') {this.value = defaultValue;}
			if(this.value == defaultValue) {this.style.color = '#999';}
		}
		
		// Verify that there is valid data to search on; otherwise, return an error...
		miniSearchFrm.btnSearchSubmit.onclick = function() {
			if(miniSearchFrm.txtSearchValue.value == '' || miniSearchFrm.txtSearchValue.value == defaultValue) {
				alert('Please enter a customer name.');
				miniSearchFrm.txtSearchValue.focus();
				return false;
			} else {
				miniSearchFrm.submit;
				showLoadBar(miniSearchFrm,miniSearchFrm.btnSearchSubmit,'Searching...');
			}
		}
		
	}
}


/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 			BROWSER POP-UPS
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */

//Function to show and hide pop-ups
//REQUIRES: STATIC POP-UP WIDTH OF 500PX!
function showHidePopUp() {
	if(document.getElementById(this.rel) && document.getElementById('overlay')) {
	
		// Get some objects...
		var popUp	= document.getElementById(this.rel);
		var overlay	= document.getElementById('overlay');
		
		//show or hide it the popup...
		if(popUp.style.display == 'none') {
		
			//First, show the overlay...
			overlay.style.display	= 'block';
			
			//Get the L-R positioning of the popup based on the width of the overlay...
			var popLeft = (overlay.offsetWidth - 500) / 2 + 'px';
			
			//Set the L-R positioning...
			popUp.style.left = popLeft;
			
			//Set the close buttons...
			var links = popUp.getElementsByTagName('a');
			for(i=0;i<links.length;i++) {
				if(links[i].className == 'closeBtn') {
					links[i].onclick = showHidePopUp;
				}
			}
			
			// Show the popup!
			popUp.style.display		= 'block';
		} else {
		
			//Hide it!
			overlay.style.display	= 'none';
			popUp.style.display		= 'none';
		}
		
	} else {
		alert('Sorry, this link is currently unavailable.')
	}
}

// Initialize the Standards link in the site footer...
function intStandardsPopUp() {
	
	//If the link is avaliable, then add an action to it.
	if(document.getElementById('whyStandardsBtn')) {
		var btn = document.getElementById('whyStandardsBtn');
		btn.onclick = showHidePopUp;
	}

}


/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 			LOADING BARS
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */

// Function to hide the submit button(s) an show my load bar. 
function showLoadBar(form,submitBtn,loadTxt) {
	
	// get the parent of my submit button...
	var submitBtnParent = submitBtn.parentNode;
	
	// setup the HTML content for my loadbar
	var txtHTML =	'<span class="loading">'+loadTxt+'</span>';
	var objHTML =	'<object class="loadingBar" title="" type="application/x-shockwave-flash" data="/include/site/multimedia/swf/loadingBar.swf" height="24" width="164">'+
					'	<param name="movie" value="/include/site/multimedia/swf/loadingBar.swf" />'+
					'	<param name="wmode" value="transparent" />'+
					'</object>';
	
	//Create a new element for my loadbar and fill tit with the loadbar content...
	loadBox = document.createElement('h3');
	loadBox.innerHTML = txtHTML + objHTML;
	loadBox.className = 'loadBox';
	
	//Hide the submit button box...
	submitBtnParent.style.display = 'none';
	
	//Insert my loadbar element before the hidden submit button box...
	form.insertBefore(loadBox,submitBtnParent);
	
}

/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 			MEDIA PLAYER SETTINGS & INITIALIZATION
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */

$.fn.media.defaults.flvPlayer = "/include/site/multimedia/swf/mediaplayer.swf";
$.fn.media.defaults.mp3Player = "/include/site/multimedia/swf/mediaplayer.swf";
$(document).ready(function(){
	$('a.showPlayer').media({
		//flashvars:	{skinURL:'/include/site/multimedia/swf/SteelExternalAll.swf'},
		//params:		{wmode:'opaque'},
		//attrs:		{wmode:'transparent'}
	});
	
	$('a.hideLink').hide();
	
});


/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 			INITIALIZATION CALLS...
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */

// Initialize scripts that need it...

// Add masthead search validation...
addEventSimple(window,'load',intMiniSearch);

// Add an event trigger to the Standards link in the site footer...
addEventSimple(window,'load',intStandardsPopUp);
