






	$().ready(function(){
		setInterval("checkAnchor()", 300);
		$('body').append('<div id="jquery-blank-anchor"><a name="_"></a></div>');
		
	});
	
	
	var currentAnchor = null;
	var showingProdLightBox = 0;
	
	function checkAnchor(){
		if(currentAnchor != document.location.hash){
			currentAnchor = document.location.hash;
			
			if (!currentAnchor || currentAnchor == "" || currentAnchor == "#_") {
				if (showingProdLightBox > 0) {
					destroyProdLightBox(1);
				}
			} else {
				var splits = currentAnchor.substring(1).split('_');
				
				if (splits[0] == "item") {
					
					var id = splits[1];
					var title = splits[2];
					var query = "id=" + id + extraQuery;
					
					if (showingProdLightBox != id) {
						
						if (showingProdLightBox > 0) {
							destroyProdLightBox(0);
						}
						
						showProdLightBox(id);
						
						baseLoc = document.location.href;
						if (baseLoc.indexOf("#") > -1) {
							baseLoc = baseLoc.substring(baseLoc.indexOf('/'), baseLoc.indexOf("#"));
						}
						urchinTracker(baseLoc + "/item/" + id + "/" + title);
						
						$.get("/common_gl/inc_product_item.php", query, function(data){
							$("#prodItem-lightbox .lightbox-loading").hide();
							$("#prodItem-lightbox .lightbox-content").html(data);
						});
						
					} else if (currentAnchor.indexOf("_buy-online") > -1) {
						
						showOnlineStores();
					
					} else {
						
						hideOnlineStores();
						
					}
					
				}
			}
		}
	}
	
	function openProdItem(wItemTxt){
		baseLoc = document.location.href;
		if (baseLoc.indexOf("#") > -1) {
			baseLoc = baseLoc.substring(baseLoc.indexOf('/'), baseLoc.indexOf("#"));
		}
		document.location.href = baseLoc + "#" + wItemTxt;
	}
	
	function hideProdLightBox(){
		baseLoc = document.location.href;
		if (baseLoc.indexOf("#") > -1) {
			baseLoc = baseLoc.substring(0, baseLoc.indexOf("#"));
		}
		document.location = "#_";
		//destroyLightBox();
	}
	
	function destroyProdLightBox(doFade){
		showingProdLightBox = 0;
		
		$('#prodItem-lightbox').remove();
		if (doFade == 1) { 
			$('#prodItem-overlay').fadeOut(function() { $('#prodItem-overlay').remove(); });
		} else {
			$('#prodItem-overlay').remove();
		}
		//$('embed, object, select').css({ 'visibility' : 'visible' });
		$('select').css({ 'visibility' : 'visible' });
	}
	
	function showProdLightBox(wId){
		showingProdLightBox = wId;
		setupProdLightBox();
		
		$('#prodItem-overlay').fadeIn();
		//$('embed, object, select').css({ 'visibility' : 'hidden' });
		$('select').css({ 'visibility' : 'hidden' });
	}
	
	function setupProdLightBox(){
		$('body').append('<div id="prodItem-overlay"></div><div id="prodItem-itemNav"></div><div id="prodItem-lightbox"><div id="prodItem-lightbox-back"></div><div class="lightbox-secNav"><a href="#_" class="lightbox-secNav-btnClose"></a></div><div class="lightbox-container-image-box"><a href="#_" class="prevBtn"></a><a href="#_" class="nextBtn"></a><div class="lightbox-container-image"><div class="lightbox-content"></div><div class="lightbox-loading"><a href="#" class="lightbox-loading-link"></a></div></div></div></div>');
		
		var arrPageSizes = ___getPageSize();
		$('#prodItem-overlay').css({
				backgroundColor:	"#000",
				opacity:			flashWithOpacity == false ? 1 : 0.8,
				width:				arrPageSizes[0],
				height:				arrPageSizes[1]
			}).fadeIn();
		var arrPageScroll = ___getPageScroll();
		$('#prodItem-lightbox').css({
				top:	arrPageScroll[1] + (arrPageSizes[3] / 10),
				left:	arrPageScroll[0]
			}).show();
		$('#prodItem-overlay, #prodItem-lightbox-back').click(function() {
				hideProdLightBox();
				return false;
			});
		$('#prodItem-lightbox .lightbox-loading-link, #prodItem-lightbox .lightbox-secNav-btnClose').click(function() {
				hideProdLightBox();
				return false;
			});
		setupWindowResize();
	}
	
		
	function setupWindowResize(){
		$(window).resize(function() {
				// Get page sizes
				var arrPageSizes = ___getPageSize();
				// Style overlay and show it
				$('#prodItem-overlay, #jquery-overlay').css({
					width:		arrPageSizes[0],
					height:		arrPageSizes[1]
				});
				// Get page scroll
				var arrPageScroll = ___getPageScroll();
				// Calculate top and left offset for the jquery-lightbox div object and show it
				$('#prodItem-lightbox, #jquery-lightbox').css({
					top:	arrPageScroll[1] + (arrPageSizes[3] / 10),
					left:	arrPageScroll[0]
				});
				$('#jquery-blank-anchor').css({
						top: arrPageScroll[1]
					})
			});
		
		var arrPageScroll = ___getPageScroll();
		$('#jquery-blank-anchor').css({
				top: arrPageScroll[1]
			})
	}

