$(document).ready(function() { // As soon as the document loads, do this...
	doQuickly();
	loadScripts();
});

function doQuickly() {
	killFrames();
	preloadMenu();
}

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.plastproinc.com/library/jquery.url.packed.js',
			'http://www.plastproinc.com/library/simpletreemenu.js'
		],
		css: [
			'http://www.plastproinc.com/library/simpletree.css'
		],
		/*
		img: [''],
		name: '',
		*/
		success: function(){
			highlightCurrentPage();
			customizeBySection(''); 
			customizeByPage();
			modifyHtml();
		},
		error: function(){
			
		},
		each: function(url){
			
		}
	
	});
}

function highlightCurrentPage() {
	// http://plugins.jquery.com/project/url_parser
	// Mark up the current page's link in the subnavigation
	$('#subNav a').each(function() {
		if(this.href.replace('%20',' ') === jQuery.url.attr('source')) {
			$(this).wrapInner('<span class="current"></span>');
		}
	});
}

function customizeBySection(sectionName) {
	// Mark up the body tag with the section name (top-level directory) to uniquely style child tags.
	// http://plugins.jquery.com/project/url_parser
	if(sectionName.length > 0) {
		$('body').addClass(sectionName);
	} else {
		$('body').addClass(jQuery.url.segment(3));
	}
}

function customizeByPage() {
	// Customize specific pages in various ways.
/*
	switch (jQuery.url.attr('file')) {
		case 'contact.html':
			customizeBySection('contact');
			break;
		case 'site_map.html':
			customizeBySection('sitemap');
			break;
		default:
					
	}
*/
}

/*
function loadHomepageFlash() {
	// Load the homepage Flash with swfobject.
	var flashvars = {dataFile: 'includes/monoslideshow.xml', showRegistration: 'false', showLogo: 'false'};
	var params = {bgcolor:'#ffffff',wmode:'opaque'};        
	var attributes = {};
	swfobject.embedSWF("includes/monoslideshow.swf", "placeholder", "560", "315", "9.0.0", false, 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');
	});
	$('ul').addClass('tier1');
	$('ul ul').each(function() {
		$(this).removeClass('tier1');
		$(this).addClass('tier2');
	});
	$('ul ul ul').each(function() {
		$(this).removeClass('tier2');
		$(this).addClass('tier3');
	});	
	
	if($('#treemenu1').length) {
		ddtreemenu.createTree("treemenu1", true);
	}
	
	sniffBrowsers();
}


/* All scripts below are older ones that could be replaced or rewritten. */


// Preload main menu buttons

function preloadMenu() {
	MM_preloadImages("/images/nav-about-over.gif");
	MM_preloadImages("/images/nav-products-over.gif");
	MM_preloadImages("/images/nav-features-over.gif");
	MM_preloadImages("/images/nav-resources-over.gif");
	MM_preloadImages("/images/nav-where-to-buy-over.gif");
	MM_preloadImages("/images/nav-search-over.gif");
	MM_preloadImages("/images/nav-press-over.gif");
	MM_preloadImages("/images/nav-catalog-over.gif");
}

// 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];}
}

function ImgRestore() { //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 ImgSwap() { //v3.0
  var i,j=0,x,a=ImgSwap.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];}
}

function sniffBrowsers() {
	// Browser detect script from dynamicdrive.com/dynamicindex9/browsersniffer.htm
	
	var exclude=1;
	var agt=navigator.userAgent.toLowerCase();
	var win=0;var mac=0;var lin=1;
	if(agt.indexOf('win')!=-1){win=1;lin=0;}
	if(agt.indexOf('mac')!=-1){mac=1;lin=0;}
	var lnx=0;if(lin){lnx=1;}
	var ice=0;
	var ie=0;var ie4=0;var ie5=0;var ie6=0;var com=0;var dcm;
	var op5=0;var op6=0;var op7=0;
	var ns4=0;var ns6=0;var ns7=0;var mz7=0;var kde=0;var saf=0;
	if(typeof navigator.vendor!="undefined" && navigator.vendor=="KDE"){
		var thisKDE=agt;
		var splitKDE=thisKDE.split("konqueror/");
		var aKDE=splitKDE[1].split("; ");
		var KDEn=parseFloat(aKDE[0]);
		if(KDEn>=2.2){
			kde=1;
			ns6=1;
			exclude=0;
			}
		}
	else if(agt.indexOf('webtv')!=-1){exclude=1;}
	else if(typeof window.opera!="undefined"){
		exclude=0;
		if(agt.indexOf("opera/5")!=-1||agt.indexOf("opera 5")!=-1){op5=1;}
		if(agt.indexOf("opera/6")!=-1||agt.indexOf("opera 6")!=-1){op6=1;}
		if(agt.indexOf("opera/7")!=-1||agt.indexOf("opera 7")!=-1){op7=1;}
		}
	else if(typeof document.all!="undefined"&&!kde){
		exclude=0;
		ie=1;
		if(typeof document.getElementById!="undefined"){
			ie5=1;
			if(agt.indexOf("msie 6")!=-1){
				ie6=1;
				dcm=document.compatMode;
				if(dcm!="BackCompat"){com=1;}
				}
			}
		else{ie4=1;}
		}
	else if(typeof document.getElementById!="undefined"){
		exclude=0;
		if(agt.indexOf("netscape/6")!=-1||agt.indexOf("netscape6")!=-1){ns6=1;}
		else if(agt.indexOf("netscape/7")!=-1||agt.indexOf("netscape7")!=-1){ns6=1;ns7=1;}
		else if(agt.indexOf("gecko")!=-1){ns6=1;mz7=1;}
		if(agt.indexOf("safari")!=-1 || (typeof document.childNodes!="undefined" && typeof document.all=="undefined" && typeof navigator.taintEnabled=="undefined")){mz7=0;ns6=1;saf=1;}
		}
	else if((agt.indexOf('mozilla')!=-1)&&(parseInt(navigator.appVersion)>=4)){
		exclude=0;
		ns4=1;
		if(typeof navigator.mimeTypes['*']=="undefined"){
			exclude=1;
			ns4=0;
			}
		}
	if(agt.indexOf('escape')!=-1){exclude=1;ns4=0;}
	if(typeof navigator.__ice_version!="undefined"){exclude=1;ie4=0;}
}