// JavaScript Document
	/* CROSS-BROWSER EVENT HANDLER */
		function addEvent(obj, evType, fn){
			 if (obj.addEventListener){
				 obj.addEventListener(evType, fn, true);
				 return true;
			 } else if (obj.attachEvent){
				 var r = obj.attachEvent("on"+evType, fn);
				return r;
			 } else {
				return false;
			 }
		}
	/* END EVENT HANDLER */
	
	
	/* JPSPAN */
/*
	function doGetPage(i) {
			if(i) {
				var p = new pageholder(PageHolderHandler);
				p.ashtml(i);
				setContent("loading...");
			}
		}
		var PageHolderHandler = {
			ashtml: function(result) {
				setContent(result);
			}
		}
		
*/

addEvent(window,'load',function(){MM_preloadImages('/lib/images/preloader.gif');});

function doGetPage(hash){
	if (hash != 1){
		var splitHash = hash.split("?")
		var url = '/lib/content/products/' + splitHash[0];
		var pars = splitHash[1];

		$('contentDiv').className = 'contentPageContent'
		$('contentDiv').innerHTML = '<div class="preloader"><img src="/lib/images/preloader.gif" /></div>';
		
		var myAjax = new Ajax.Request( url, {
			  method: 'get', 
			  parameters: pars, 
			  onComplete: function(originalRequest){
					$('contentDiv').innerHTML = originalRequest.responseText; openNavItem(hash); myLightbox = new Lightbox(); preloadSpinnerImages(); 
					} 
			  });
	
	}

}

	/* END JPSPAN */
	
	
	/* PAGELOCATOR */
		function PageLocator(propertyToUse, dividingCharacter) {
			this.propertyToUse = propertyToUse;
			this.defaultQS = 1;
			this.dividingCharacter = dividingCharacter;
		}
		PageLocator.prototype.getLocation = function() {
			return eval(this.propertyToUse);
		}
		PageLocator.prototype.getHash = function() {
			var url = this.getLocation();
			if(url.indexOf(this.dividingCharacter)>-1) {
				var url_elements = url.split(this.dividingCharacter);
				return url_elements[url_elements.length-1];
			} else {
				return this.defaultQS;
			}
		}
		PageLocator.prototype.getHref = function() {
			var url = this.getLocation();
			var url_elements = url.split(this.dividingCharacter);
			return url_elements[0];
		}
		PageLocator.prototype.makeNewLocation = function(new_qs) {
			return this.getHref() + this.dividingCharacter + new_qs;
		}
	/* END PAGELOCATOR */
	
	
	/* AjaxIframesFixer */
	
		function AjaxIframesFixer(iframeid) {
			this.iframeid = iframeid;
			if (document.getElementById('ajaxnav')) {
				this.fixLinks();
				
				this.locator = new PageLocator("document.frames['"+this.iframeid+"'].getLocation()", "?hash=");
				this.windowlocator = new PageLocator("window.location.href", "#");
				this.timer = new Timer(this);
				
				this.delayInit(); // required or IE doesn't fire
			}
		}
		AjaxIframesFixer.prototype.fixLinks = function (iframeid) {
			var links = document.getElementsByTagName("A");
			for(var i=0; i<links.length; i++) {
				if (links[i].className.indexOf("sideNav") != -1){
				var href = links[i].getAttribute("href");
					if(href.indexOf("prodCategory=") != -1 ){
						var hash = href.substr(href.indexOf("prodCategory=")+13);
						links[i].setAttribute("href","javascript:document.getElementById('"+this.iframeid+"').setAttribute('src', '/lib/scripts/backbutton/mock-page.asp?hash=?prodCategory="+hash+"');");
					}else if (href.indexOf("prodID=") != -1 ){
						var hash = href.substr(href.indexOf("prodID=")+7);
						links[i].setAttribute("href","javascript:document.getElementById('"+this.iframeid+"').setAttribute('src', '/lib/scripts/backbutton/mock-page.asp?hash=details/?prodID="+hash+"');");
					}else if(href.indexOf("category=") != -1 ){
						var hash = href.substr(href.indexOf("category=")+9);
						links[i].setAttribute("href","javascript:document.getElementById('"+this.iframeid+"').setAttribute('src', '/lib/scripts/backbutton/mock-page.asp?hash=?category="+hash+"');");
					}
				}
			}
		}
		AjaxIframesFixer.prototype.delayInit = function(){
			this.timer.setTimeout("checkBookmark", 100, "");
		}
		AjaxIframesFixer.prototype.checkBookmark = function(){
			if(this.locator.getHash() != 1) {
				window.location = this.windowlocator.makeNewLocation(this.locator.getHash());
			}
			this.checkWhetherChanged();
		}
		AjaxIframesFixer.prototype.checkWhetherChanged = function(location){
			if(this.locator.getHash() != location) {
				window.location = this.windowlocator.makeNewLocation(this.locator.getHash());
				doGetPage(this.locator.getHash());

				if (location && this.locator.getHash() == 1){
					window.location.reload();	
				}
			}
			this.timer.setTimeout("checkWhetherChanged", 200, this.locator.getHash() );
		}
	/* END AjaxIframesFixer */
	
	
	/* AjaxUrlFixer */
		function AjaxUrlFixer() {
			this.fixLinks();
			
			this.locator = new PageLocator("window.location.href", "#");
			this.timer = new Timer(this);
			this.checkWhetherChanged();
		}
		AjaxUrlFixer.prototype.fixLinks = function () {
			var links = document.getElementsByTagName("A");
			for(var i=0; i<links.length; i++) {
				
				if (links[i].className.indexOf("sideNav") != -1){
					
				var href = links[i].getAttribute("href");

					if(href.indexOf("prodCategory=") != -1 ){
						var hash = href.substr(href.indexOf("prodCategory=")+13);
						links[i].setAttribute("href","#?prodCategory="+hash);
					}else if (href.indexOf("prodID=") != -1 ){
						var hash = href.substr(href.indexOf("prodID=")+7);
						links[i].setAttribute("href","#details/?prodID="+hash);
					}else if(href.indexOf("category=") != -1 ){
						var hash = href.substr(href.indexOf("category=")+9);
						links[i].setAttribute("href","#?category="+hash);
					}
				}
			}
		}
		AjaxUrlFixer.prototype.checkWhetherChanged = function(location){
			if(this.locator.getHash() != location) {
				doGetPage(this.locator.getHash());
				if (location && this.locator.getHash() == 1){
					window.location.reload();	
				}
			}
			this.timer.setTimeout("checkWhetherChanged", 200, this.locator.getHash());
		}
	/* END AjaxUrlFixer */
	
	function setContent(new_content) {
		if(!document.getElementById || !document.getElementsByTagName) return;
		var container = document.getElementById("contentDiv");
		container.innerHTML = new_content;
	}
	function FixBackAndBookmarking() {
		if(!document.getElementById || !document.getElementsByTagName) return;
		if(document.iframesfix) {
			fix = new AjaxIframesFixer('ajaxnav');
		} else {
			fix = new AjaxUrlFixer();
		}
	}
	
	var detect = navigator.userAgent.toLowerCase();
	if(detect.indexOf("msie")>-1) document.iframesfix = true;

	addEvent(window, "load", FixBackAndBookmarking);