// JavaScript Document

function revealModal(divID, imgID, imgSrc)
{
	document[imgID].src = "/images/spacer.gif";
	//document.getElementById(imgID).src = imgSrc;
	document[imgID].src = imgSrc;
	document.getElementById(divID).style.display = "block";
	document.getElementById(divID).style.top = document.body.scrollTop;
}

function revealModal2(divID, imgID, imgPath, imgArray, cartArray, i, first, last, recursion, shopping)
{
	document[imgID].src = "/images/spacer.gif";
	document[imgID].src = imgPath + imgArray[i];
	if( shopping )
	{
		document.getElementById('x_alink').setAttribute("value", imgArray[i]);
		if( cartArray[i] == "1" )
			var cmdCart = "Remove";
		else
			var cmdCart = "Add to Cart";
		//var cmdCart = document.getElementById('alink' + imgArray[i].substr(0, 8)).title;
		document.getElementById('x_alink').setAttribute("title", cmdCart);
		document.getElementById('x_alink').innerHTML = cmdCart;
		document.getElementById('x_UserMessage').innerHTML = "";
		document.getElementById('x_Title').innerHTML = imgArray[i].toUpperCase().replace(".JPG", "");
	}
	
	//if( parseInt(i) > parseInt(first) )
	if( parseInt(i) > 0 )
	{
		document.getElementById('x_PrevImg').style.visibility = 'visible';
		document.getElementById('x_PrevImg').onclick = function() {revealModal2(modalExpressGallery, imgID, imgPath, imgArray, cartArray, (parseInt(i) - 1), first, last, true, shopping); return false;};
	}
	else
	{
		document.getElementById('x_PrevImg').style.visibility = 'hidden';
		document.getElementById('x_PrevImg').onclick = function() {return false;};
	}

	if( parseInt(i) < (imgArray.length - 1) )
	{
		document.getElementById('x_NextImg').style.visibility = 'visible';
		document.getElementById('x_NextImg').onclick = function() {revealModal2(modalExpressGallery, imgID, imgPath, imgArray, cartArray, (parseInt(i) + 1), first, last, true, shopping); return false;};
	}
	else
	{
		document.getElementById('x_NextImg').style.visibility = 'hidden';
		document.getElementById('x_NextImg').onclick = function() {return false;};
	}

	if( !recursion )
	{
		document.getElementById(divID).style.display = "block";
		document.getElementById(divID).style.top = document.body.scrollTop;
		document.getElementById('myModelBackground').className = "modalBackground";
		//document.body.style.overflow = "visible";
	}
}

function hideModal(divID)
{
	//document.body.style.overflow = "hidden";
	document.getElementById('myModelBackground').className = "";
	document.getElementById(divID).style.display = "none";
}

function changeQtyU(thisItem) {
	var thisItemId = thisItem;
	var testName = eval("document.getElementById('"+thisItemId+"')");
	var thisTotal = testName.value;
	if (thisTotal == "") {
		thisTotal = 0;
	}
	if (thisTotal!= 99) {
	    var newTotal = parseInt(thisTotal) + 1;
	    testName.value = newTotal;
	}
}
function changeQtyD(thisItem) {
	var thisItemId = thisItem;
	var testName = eval("document.getElementById('"+thisItemId+"')");
	var thisTotal = testName.value;
	if (thisTotal == "") {
		thisTotal = 0;
	}
	if (thisTotal!= 0) {
		var newTotal = parseInt(thisTotal) - 1;
		testName.value = newTotal;
	}
}

var modalWindow = {  
    parent:"body",  
    windowId:null,  
    content:null,  
    width:null,  
    height:null,  
    close:function()  
    {  
        $(".modal-window").remove();  
        $(".modal-overlay").remove();  
    },  
    open:function()  
    {  
        var modal = "";  
        modal += "<div class=\"modal-overlay\"></div>";  
        modal += "<div id=\"" + this.windowId + "\" class=\"modal-window\" style=\"width:" + this.width + "px; height:" + this.height + "px; margin-top:-" + (this.height / 2) + "px; margin-left:-" + (this.width / 2) + "px;\">";  
        modal += this.content;  
        modal += "</div>";      
  
        $(this.parent).append(modal);  
  
        $(".modal-window").append("<a class=\"close-window\"></a>");  
        $(".close-window").click(function(){modalWindow.close();});  
        $(".modal-overlay").click(function(){modalWindow.close();});  
    }  
};
var openMyModal = function(source)  
{  
    modalWindow.windowId = "myModal";  
    modalWindow.width = 670;  
    modalWindow.height = 530;  
    modalWindow.content = "<iframe width='670' height='530' frameborder='0' scrolling='no' allowtransparency='true' src='" + source + "'></iframe>";  
    modalWindow.open();  
};
