/*$(document).ready(function() { // As soon as the document loads, do this...
	killFrames();
	loadScripts();
	modifyHtml();
});*/

function killFrames() {
	// If the page is loaded in a frame, bypass the frame and reload in the top of the browser.
	if (top != self) {
		top.location.href = self.location.href
	}
}

function loadScripts() {
	// Load script files and jQuery plugins separate from the HTML. 
	// http://plugins.jquery.com/project/xLazyLoader
	$.xLazyLoader({
		js: 'http://www.jmeagle.com/library/jquery.url.packed.js',
		load: function() { highlightCurrentPage(); customizeBySection(); customizeByPage(); }
	});
}

function highlightCurrentPage() {
	// Mark up the current page's section link in the navigation
	// http://plugins.jquery.com/project/url_parser
	$('#navigation a').each(function() {
		var navUrlSection = jQuery.url.setUrl(this.href).segment(0);
		if(navUrlSection === jQuery.url.setUrl(location.href).segment(0)) {
			$(this).parent('li').addClass('current');
		}
	});
	// Mark up the current page's link in the subnavigation
	$('#subnavigation a').each(function() {
		if(this.href === jQuery.url.attr('source')) {
			$(this).parent('li').addClass('current');
		}
	});
}

function customizeBySection() {
	// Mark up the body tag with the section name to uniquely style child tags.
	// http://plugins.jquery.com/project/url_parser
	$('body').addClass(jQuery.url.segment(0)); 
}

function customizeByPage() {
	// On the Locations map page, preload location images.
	if(jQuery.url.attr('file') === 'locations.html') {
		//preloadLocationImages();
	}
}

function loadHomepageFlash() {
	// Load the homepage Flash with swfobject.
	// http://code.google.com/p/swfobject/
	var flashvars = {};
	var params = {};
	params.quality = "high";
	params.wmode = "opaque";
	params.bgcolor = "#ffffff";
	var attributes = {};
	attributes.id = "homepageFlash";
	swfobject.embedSWF("http://www.jmeagle.com/images/shell.swf", "homepageFlashPlaceholder", "760", "251", "8.0.0", "http://www.jmeagle.com/library/expressInstall.swf", flashvars, params, attributes);
}

function modifyHtml() {
	// For each list, mark up the first and last items.
	$('ul,ol,dl').each(function() {
		$(this).children('li:first,dt:first').addClass('first');
		$(this).children('li:last,dt:last').addClass('last');
	});
	
	// Append corner images on the side photo.
	$('#supplement .sideImage').append('<div class="sideImageTop"></div><div class="sideImageBot"></div>');
	
	loadHomepageFlash();
}

function preloadLocationImages() {
	MM_preloadImages('/images/location-headquarters.gif');
	MM_preloadImages('/images/location-adel.gif');
	MM_preloadImages('/images/location-batchelor.gif');
	MM_preloadImages('/images/location-butner.gif');
	MM_preloadImages('/images/location-fontana.gif');
	MM_preloadImages('/images/location-kingman.gif');
	MM_preloadImages('/images/location-magnolia.gif');
	MM_preloadImages('/images/location-mcnary.gif');
	MM_preloadImages('/images/location-meadville.gif');
	MM_preloadImages('/images/location-pueblo.gif');
	MM_preloadImages('/images/location-stockton.gif');
	MM_preloadImages('/images/location-wharton.gif');
	MM_preloadImages('/images/location-wilton.gif');
	MM_preloadImages('/images/location-winnebago.gif');
	MM_preloadImages('/images/location-mexico.gif');
	MM_preloadImages('/images/location-losangeles.gif');
	MM_preloadImages('/images/location-eugene.gif');
}

function openTour(queryStr) {
	// Open a pop-up window for the virtual tour. 
	window.open('/jmeagle/tour.php?' + queryStr,'VirtualTour','location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=750,height=500').focus();
}

//Dreamweaver Behaviors
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


