window.dhtmlHistory.create({
	toJSON: function(o) {
		return Object.toJSON(o);
	}
	, fromJSON: function(s) {
		return s.evalJSON();
	}
});

$j(document).ready(function(){

	onLoad();

	//if($j.browser.msie) { $j("div").css('overflow', 'hidden'); }

	dhtmlHistory.initialize();
	dhtmlHistory.addListener(loadHistory);

	if (dhtmlHistory.isFirstLoad()) {
		var hash = location.hash.replace(/^.*#/, '');
//alert('isFirstLoad');
		switch(hash) {
			
			case "categoryadult":
				loadMainNav('nav1', 'Adult Products');
			break;
			case "categorybaby":
				loadMainNav('nav2', 'PED/Baby Products');
			break;
			case "categorychart":
				loadMainNav('nav3', 'Chart Label Products');
			break;
			case "categoryspecial":
				loadMainNav('nav4', 'Specialty Products'); 
			break;

		}

			

		if(hash.substr(0,8) == "newsitem"){			
			saveHistory = false;

			createNewsPage(hash.substr(8));
		
		}

		if(hash.substr(0,12) == "pageproducts"){
			saveHistory = false;
			
			createProductPage(hash.substr(12));
		
		}

		if(hash.substr(0,14) == "loadtabnewsTab"){

			saveHistory = true;
			$('logo').style.display='block';

			var tabId = parseInt(hash.substr(14));
			
			section =hash;

			runshow=false;
			clearTimeout(t);

			blendimage('homebg', 'blendimage', 'deimages/bgBlueShaded.gif',400,prevpic);
			$('homebox').className='bluehomebox';
			
			var reset='';

			hideAll(reset);

			

			ajaxLoading('ajaxUpdater', 'loadingNews');
			new Ajax.Updater('ajaxUpdater', 'index.php?pageId=28&mode=mod_laser&action=loadAjaxNews&newsPage=9&next=1', { method: 'get' , evalScripts: true, onComplete: function() { 
			
				
			$('ajaxUpdater').style.display='block';

					switch(tabId) {
						case 1:
							
							currenttab='newsTab1';
							glasttab='newsTab5';
							nextto='';
							gparent='newsMainHeader';

							tabNav('newsTab1', '', 'newsMainHeader', 'newsTab5');

						break;
						case 2:

							currenttab='newsTab2';
							glasttab='newsTab5';
							nextto='newsTab1';
							gparent='newsMainHeader';

							tabNav('newsTab2', 'newsTab1', 'newsMainHeader', 'newsTab5');
						break;
						case 3:

							currenttab='newsTab3';
							glasttab='newsTab5';
							nextto='newsTab2';
							gparent='newsMainHeader';

							tabNav('newsTab3', 'newsTab2', 'newsMainHeader', 'newsTab5');
						break;
						case 4:

							currenttab='newsTab4';
							glasttab='newsTab5';
							nextto='newsTab3';
							gparent='newsMainHeader';

							tabNav('newsTab4', 'newsTab3', 'newsMainHeader', 'newsTab5');
						break;
						case 5:
							currenttab='newsTab5';
							glasttab='newsTab5';
							nextto='newsTab4';
							gparent='newsMainHeader';

							tabNav('newsTab5', 'newsTab3', 'newsMainHeader', 'newsTab5');
							
						break;
						default:
							//alert(pageId);
						break;

					}

					changeTab(currenttab, glasttab, '', 'tabContentc', 'newsMainHeader', 'newsTab5');

					//newsTab3,  newsTab2, , tabContentc, newsMainHeader, newsTab5

					var complexObject = new Object();
					complexObject.value1 = currenttab;
					complexObject.value2 = nextto;
					complexObject.value3 = '';
					complexObject.value4 = 'tabContentc';
					complexObject.value5 = gparent;
					complexObject.value6 = glasttab;

					dhtmlHistory.add(hash, complexObject);
					
					//me:newsTab1, tab:, pos:first, updatediv:tabContentc, parent:newsMainHeader, lasttab:newsTab5
					//me:newsTab3, tab:newsTab2, pos:, updatediv:tabContentc, parent:newsMainHeader, lasttab:newsTab5
					



			}});
		}


		if(hash.substr(0,9) == "loadgpage"){
			var section ='generic';

			runshow=false;
			clearTimeout(t);

			blendimage('homebg', 'blendimage', 'deimages/bgBlueShaded.gif',400,prevpic);
			$('homebox').className='bluehomebox';
			
			var reset='';

			hideAll(reset);

			ajaxLoading('ajaxUpdater', 'loadingNews');
			new Ajax.Updater('ajaxUpdater', 'index.php?pageId=28&mode=mod_laser&action=loadGeneric&loadPage=23', { 
				method: 'get' , 
				evalScripts: true,
				onComplete: function() {
					$('ajaxUpdater').style.display='block';
					loadGenericPage(hash.substr(9), 'http://www.laserband.com/index.php?pageId=' + hash.substr(9));
				}
			});
		}



			

	}

});



var loadHistory = function(newLocation, historyData) { 

	saveHistory = false;
	
	var nleight=newLocation.substr(0,8);
	var nlnine=newLocation.substr(0,9);

	if(!newLocation && !$('homebox')) window.location.reload();
	if(!newLocation)  { loadHome(); }


	closeLightbox();

	if(newLocation == "home") { loadHome(); }
	if($j.url.param("pageId") == 1) { loadHome();  }
	//if(!$j.url.param("pageId")) { alert(newLocation); loadHome();  } 

	//if(!newLocation && !$('homebox')) window.location.reload();

	if(newLocation == "fullScreenPopup"){ 
		$('fullScreenPopupArea').style.display='none';
		$('popinSearchDefault').style.display='block';
	}


	if(newLocation.substr(0,7) == "loadtab") {
		//alert(historyData['value1'] + ',  ' + historyData['value2'] + ', ' +  historyData['value3'] + ', ' +  historyData['value4'] + ', ' +  historyData['value5'] + ', ' +  historyData['value6']);
		changeTab(historyData['value1'], historyData['value2'], historyData['value3'], historyData['value4'], historyData['value5'], historyData['value6']);
	}

	if(newLocation.substr(0,4) == "page") { 
		
		//alert("tab:" + historyData['tab'] + ", staylit:" +  historyData['staylit'] + ", productId:" +  historyData['productId'] + ", productCategoryId:" +  historyData['productCategoryId']);
		loadNav(historyData['tab'], historyData['staylit'], historyData['productId'], historyData['productCategoryId']);
	}

	if(nleight == "category") loadMainNav(historyData['value1'], historyData['value2'], 'no');
	if(nleight == "loadnews") loadNewsPage(historyData['value1'], historyData['value2'], historyData['value3']);
	if(nleight == "loadpage") loadSearchPage(historyData);
	if(nlnine  == "loadgpage")loadGenericPage(historyData);

	if(nlnine == "loadgpage"){
		if(section != "loadgpage") loadNav('generic');
		loadGenericPage(historyData);
	}

	if(nleight == "newsitem"){
		//alert('newsitem');
		if(section != "newsresources") loadNav('newsresources');

			//alert('tab:' + historyData['tab']+ ', nextto ' + historyData['nextto']+ ', parent ' + historyData['parent']+ ', lasttab ' + historyData['lasttab']);
			tabNav(historyData['tab'], historyData['nextto'], historyData['parent'], historyData['lasttab']);		
			loadNewsItem(historyData['value1'], historyData['value2']); 
						
	}

	saveHistory = true;
}


function initializeAjaxHistory(){

}


function ajaxLoading(div, clss){
	if($(div)){
		$(div).innerHTML='';

		if(!clss) clss = "loading";
		$(div).innerHTML='<img src="styles/laserband/deimages/loading.gif" class="'+clss+'" alt="loading..." title="loading..."/>';
	}
}


/*
	Expandable Listmenu Script
	Author : Daniel Nolan
	http://www.bleedingego.co.uk/webdev.php
*/

function initMenus() {
	if (!document.getElementsByTagName) return;
	
	var aMenus = document.getElementsByTagName("LI");
	for (var i = 0; i < aMenus.length; i++) {
		var mclass = aMenus[i].className;
		if (mclass.indexOf("treenode") > -1) {
			var submenu = aMenus[i].childNodes;
			for (var j = 0; j < submenu.length; j++) {
				if (submenu[j].tagName == "A") {
					
					submenu[j].onclick = function() {
						var node = this.nextSibling;
											
						while (1) {
							if (node != null) {
								if (node.tagName == "UL") {
									var d = (node.style.display == "none")
									node.style.display = (d) ? "block" : "none";
									this.className = (d) ? "treeopen" : "treeclosed";
									return false;
								}
								node = node.nextSibling;
							} else {
								return false;
							}
						}
						return false;
					}
					
					submenu[j].className = (mclass.indexOf("open") > -1) ? "treeopen" : "treeclosed";
				}
				
				if (submenu[j].tagName == "UL")
					submenu[j].style.display = (mclass.indexOf("open") > -1) ? "block" : "none";
			}
		}
	}
}


/* 
	font-size control from
	http://www.white-hat-web-design.co.uk/articles/js-fontsize.php

	modded to change only a div
*/
function increaseFontSize(changeme) { 
   var p = $(changeme);
      if(p.style.fontSize) {
         var s = parseInt(p.style.fontSize.replace("px",""));
      } else {
         var s = 12;
      }
      if(s!=max) {
         s += 1;
      }
      p.style.fontSize = s+"px"
}

function decreaseFontSize(changeme) {
   var p = $(changeme);

	  if(p.style.fontSize) {
         var s = parseInt(p.style.fontSize.replace("px",""));
      } else {
         var s = 12;
      }
      if(s!=min) {
         s -= 1;
      }
      p.style.fontSize = s+"px"
}

function printPreviewDiv(elementId)
 {
var printContent = $(elementId);
 var windowUrl = 'about:blank';
 var uniqueName = new Date();
 var windowName = 'Print' + uniqueName.getTime();
 var printWindow = window.open(windowUrl, windowName, 'left=50000,top=50000,width=0,height=0');

      
	printWindow.document.write('<html><link href="style.css" rel="stylesheet" type="text/css"/><body>'); 

	printWindow.document.write(printContent.innerHTML);
	printWindow.document.write('</body></html>');  

	printWindow.document.close();
	printWindow.focus();
	printWindow.print();
	printWindow.close();
 }


 /* 
	cross browser opacity changing from http://brainerror.net/scripts/javascript/blendtrans/ 
*/

function opacity(id, opacStart, opacEnd, millisec) { 
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 

    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } 
} 

//change the opacity for different browsers 
function changeOpac(opacity, id) { 
	if($(id)){
		var object = $(id).style; 
		object.opacity = (opacity / 100); 
		object.MozOpacity = (opacity / 100); 
		object.KhtmlOpacity = (opacity / 100); 
		object.filter = "alpha(opacity=" + opacity + ")"; 
	}
} 


function mouseX(evt) {
if (evt.pageX) return evt.pageX;
else if (evt.clientX)
   return evt.clientX + (document.documentElement.scrollLeft ?
   document.documentElement.scrollLeft :
   document.body.scrollLeft);
else return null;
}
function mouseY(evt) {
if (evt.pageY) return evt.pageY;
else if (evt.clientY)
   return evt.clientY + (document.documentElement.scrollTop ?
   document.documentElement.scrollTop :
   document.body.scrollTop);
else return null;
}



mouse = { x: 0, y: 0 };

$j(document).ready(function(){
	   $j().mousemove(function(e){
			mouse.x = e.pageX;
			mouse.y =  e.pageY;
	   }); 
	})
