var windowWidth

function resizeWin() {
	windowWidth = window.innerWidth | document.documentElement.clientWidth
	//alert("winWidth = " + windowWidth)
	Page.sessCookie("browserWidth", windowWidth)
	
}

function searchBox() {
	var searchBoxObj = document.getElementById("searchBox")
	var status = searchBoxObj.style.display == "block" ? "none" : "block"
	searchBoxObj.style.display = status
	document.searchForm.search.focus()
}

try {
	Event.observe(window, "resize", resizeWin, false)
	Event.observe(window, "load", pageLoad, false)	
}

catch (ex) {}

function pageLoad(ev) {
    resizeWin(ev);
    swfobject.embedSWF("/images/waiting.swf", "waitingIcon", "14", "14", "9.0.0", "expressInstall.swf", {}, { wmode: 'transparent' }, "");
}

function addRemLightbox(checkboxObj) {
	var state = checkboxObj.checked
	var imageId = checkboxObj.value
	var newValue = state == true ? imageId : null
	
	if (Page.getCookie("lightboxCount") > 100 && newValue != null) {
		alert("The maximum of 100 items in your lightbox has been reached.")
		return
	}

	//alert("newValue to save: " + imageId + " val=" + newValue)
	saveLightboxAction(imageId,newValue)
}

function saveLightboxAction(imageId, newValue) {
	var itemTotal = Page.getCookie("lightboxCount") || 0

	
    
    if (navigator.appName.indexOf("Microsoft") != -1) {
        var size = Page.getCookieGroup("lightbox") != null ? Page.getCookieGroup("lightbox").toString().length : 0
        if (size > 3000) {
            alert("The maximum number of pictures in a lightbox has been reached.")
            return
        }
    }
    
	if (newValue == null) {
		Page.deleteCookieGroup("lightbox",imageId)
	} else {
		Page.setCookieGroup("lightbox",imageId)
	}
	
	if (newValue != null) { itemTotal++ } else { itemTotal-- }
	Page.sessCookie("lightboxCount",itemTotal)
	refreshLightbox(imageId)
}

	
function addRemCart(checkboxObj) {
	var state = checkboxObj.checked
	var imageId = checkboxObj.value
	var newValue = state == true ? imageId : null
	
	if (Page.getCookie("shoppingCartCount") > 100 && newValue != null) {
		alert("The maximum of 100 items in your shopping cart has been reached.")
		return
	}

	//alert("newValue to save: " + imageId + " val=" + newValue)
	saveCartAction(imageId, newValue)	
}

function saveCartAction(imageId, newValue) {
	var itemTotal = Page.getCookie("shoppingCartCount") || 0

	if (newValue == null) {
		Page.deleteCookieGroup("shoppingCart",imageId)
	} else {
		Page.setCookieGroup("shoppingCart",imageId)
	}
	
	if (newValue != null) { itemTotal++ } else { itemTotal-- }
	if (document.getElementById("basketCounter")) document.getElementById("basketCounter").innerHTML = "&nbsp;[" + itemTotal + "]"
	
	Page.sessCookie("shoppingCartCount", itemTotal)
	//refreshLightbox(imageId)
}

function inLightbox(imageId) {
	return ("," + Page.getCookieGroup("lightbox") + ",").indexOf("," + imageId + ",") != -1
}

function refreshLightbox(imageId) {
	var itemTotal = Page.getCookie("lightboxCount") || 0
	var lbText
	
	if (document.getElementById("lightboxText")) document.getElementById("lightboxText").innerHTML = "&nbsp;[" + itemTotal + "]"
	if (document.getElementById("lightboxText2")) document.getElementById("lightboxText2").innerHTML = "&nbsp;[" + itemTotal + "]"
	if (document.getElementById("lightboxText3")) {
		if (itemTotal == 0) {
			lbText = "You have no images in your lightbox."
		} else if (itemTotal == 1) {
			lbText = "You have 1 image in your lightbox."
		} else {
			lbText = "You have " + itemTotal + " images in your lightbox."
		}
		document.getElementById("lightboxText3").innerHTML = lbText
	}
}

function removeAllFromLightbox() {
	Page.sessCookie("lightboxCount",0)
	Page.deleteCookie("lightbox")
	location.reload()
}

function enableElement(inputElement) {
	inputElement.disabled = false	
}


