var myBody;
var myOverlay;
var myLightBox;
var myLink;
var myCloseButton;
var myVideo;
var myPicture;
var xScroll;
var yScroll;
var myPageScroll;
var myWidth;
var myHeight;
var myPageSize;
var cHeight = "333";
var cWidth = "579";
var myMediaType;

function ConvertPicture(pId)
{
    document.getElementById(pId).style.cursor = 'pointer';
    mySrc = document.getElementById(pId).src;
    mySrc = mySrc.replace('_70', '_1000');
    mySrc = mySrc.replace('_110', '_1000');
    document.getElementById('picMain').src = mySrc;
}

function GoLink(pPar)
{
	var pVal = pPar.split("~");
	var mPath;
	
	mPath = "";

	switch (pVal[0])
	{
		case "0" :
			if (document.URL.indexOf('/Shop') == '-1') { mPath = ''; } else { mPath = '../'; }
			document.location = mPath + "Main.aspx";
			break;
		case "1" :
			if (pVal[4] == '0')
			{
				document.location = 'http://' + pVal[1];
			}
			else
			{
				window.open('http://' + pVal[1],'','scrollbars=yes,status=no,resizable=no,toolbar=no,menubar=no,location=no,width=' + pVal[6] + ',height=' + pVal[5] + ',titlebar=no');
			}
			break;
		case "2" :
			if (pVal[4] == '0')
			{
				document.location = 'https://' + pVal[1];
			}
			else
			{
				window.open('https://' + pVal[1],'','scrollbars=yes,status=no,resizable=no,toolbar=no,menubar=no,location=no,width=' + pVal[6] + ',height=' + pVal[5] + ',titlebar=no');
			}
			break;
		case "3" :
			if (pVal[4] == '0')
			{
				document.location = 'ftp://' + pVal[1];
			}
			else
			{
				window.open('ftp://' + pVal[1],'','scrollbars=yes,status=no,resizable=no,toolbar=no,menubar=no,location=no,width=' + pVal[6] + ',height=' + pVal[5] + ',titlebar=no');
			}
			break;
		case "4" :
			if (pVal[4] == '0')
			{
				document.location = 'news://' + pVal[1];
			}
			else
			{
				window.open('news://' + pVal[1],'','scrollbars=yes,status=no,resizable=no,toolbar=no,menubar=no,location=no,width=' + pVal[6] + ',height=' + pVal[5] + ',titlebar=no');
			}
			break;
		case "5" :
			document.location = 'mailto://' + pVal[1];
			break;
		case "9" :
			if (pVal[4] == '0')
			{
			    if(pVal.length < 8)
			    {
				    document.location = mPath + "Documents.aspx?Q1=" + pVal[1];
				}
				else
				{
				    switch(pVal[7])
				    {
				        case "-1":
				            document.location = mPath + "Documents.aspx?Q1=" + pVal[1];
				            break;
				        case "1" :
				            document.location = mPath + "SpaFitness.aspx?Q1=" + pVal[1];
				            break;
				        case "2" :
				            document.location = mPath + "Events.aspx?Q1=" + pVal[1];
				            break;
				        case "3" :
				            document.location = mPath + "Wedding.aspx?Q1=" + pVal[1];
				            break;
				        case "4" :
				            document.location = mPath + "Meeting.aspx?Q1=" + pVal[1];
				            break;
				    }
				}
			}
			else
			{
			    if(pVal.length < 8)
			    {
				    window.open(mPath + 'Document.aspx?Q1=' + pVal[1],'','scrollbars=yes,status=no,resizable=no,toolbar=no,menubar=no,location=no,width=' + pVal[6] + ',height=' + pVal[5] + ',titlebar=no');
				}
				else
				{
				    switch(pVal[7])
				    {
				        case "-1":
				            window.open(mPath + 'Document.aspx?Q1=' + pVal[1],'','scrollbars=yes,status=no,resizable=no,toolbar=no,menubar=no,location=no,width=' + pVal[6] + ',height=' + pVal[5] + ',titlebar=no');
				            break;
				        case "1" :
				            window.open(mPath + 'SpaFitness.aspx?Q1=' + pVal[1],'','scrollbars=yes,status=no,resizable=no,toolbar=no,menubar=no,location=no,width=' + pVal[6] + ',height=' + pVal[5] + ',titlebar=no');
				            break;
				        case "2" :
				            window.open(mPath + 'Events.aspx?Q1=' + pVal[1],'','scrollbars=yes,status=no,resizable=no,toolbar=no,menubar=no,location=no,width=' + pVal[6] + ',height=' + pVal[5] + ',titlebar=no');
				            break;
				    }
				}
			}
			break;
	}
}

function GetTextValue(pArea)
{
	var frm = document.forms[0];	
	var retValue;
	
	retStr = "";
    for (i=0; i < frm.length; i++)
	{
		if (frm.elements[i].id.indexOf(pArea) != "-1")
		{
			retValue = frm.elements[i].value;
		}
	}
	return retValue;
}

function onMouse(pThis,pColor)
{
	pThis.style.color = pColor;
}


function ShowLightBox(pType, pPath) 
{
    myMediaType = pType;

    InitLightBox()
    myOverlay = document.getElementById("myOverlay");
    myLightBox = document.getElementById("myLightBox");

    myOverlay.style.display = 'block';
    myLightBox.style.top = myPageScroll[1] + ((myPageSize[3] - cHeight) / 2);
    myLightBox.style.left = ((myPageSize[0] - cWidth) / 2);
    myLightBox.style.display = 'block';

    switch (myMediaType) 
    {
        case "P":
            LoadPicture(pPath);
            break;
        case "V":
            LoadVideo(pPath);
            break;
    }
}

function InitLightBox() 
{
    myPageSize = PageSize();
    myPageScroll = PageScroll();

    myBody = document.getElementsByTagName("body").item(0);

    // -------
    // Overlay
    // -------
    myOverlay = document.createElement('div');
    myOverlay.setAttribute('id', 'myOverlay');
    myOverlay.onclick = function() { CloseLightBox(); return false; }
    myOverlay.style.display = 'none';
    myOverlay.style.position = 'absolute';
    myOverlay.style.top = '0';
    myOverlay.style.left = '0';
    myOverlay.style.zIndex = '90';
    myOverlay.style.width = '100%';
    myOverlay.style.height = myPageSize[1] + 'px';
    myBody.insertBefore(myOverlay, myBody.firstChild);

    // --------
    // LightBox
    // --------
    myLightBox = document.createElement("div");
    myLightBox.setAttribute('id', 'myLightBox');
    myLightBox.style.display = 'none';
    myLightBox.style.position = 'absolute';
    myLightBox.style.zIndex = '100';
    myLightBox.style.width = cWidth + 'px';
    myLightBox.style.height = cHeight + 'px';
    myBody.insertBefore(myLightBox, myOverlay.nextSibling);

    // ----
    // Link
    // ----
    myLink = document.createElement("a");
    myLink.setAttribute('href', '#');
    myLink.setAttribute('title', 'Click to close');
    myLink.onclick = function() { CloseLightBox(); return false; }
    myLightBox.appendChild(myLink);

    // -----------
    // Close Image
    // -----------
    myCloseButton = document.createElement("img");
    myCloseButton.src = 'http://www.lesottomans.com/Tools/Images/General/Close.gif';
    myCloseButton.setAttribute('id', 'closeButton');
    myCloseButton.style.position = 'absolute';
    myCloseButton.style.zIndex = '200';
    myLink.appendChild(myCloseButton);
}

function LoadVideo(pPath) 
{
    // -----
    // Video
    // -----
    myVideo = document.createElement("embed");
    myVideo.setAttribute("src", pPath);
    myVideo.setAttribute("autoStart", "true");
    myVideo.style.width = cWidth + "px";
    myVideo.style.height = cHeight + "px";
    myLightBox.appendChild(myVideo)
}

function LoadPicture(pPath) 
{
    // -------
    // Picture
    // -------
    myPicture = document.createElement("img");
    myPicture.src = pPath;
    myPicture.setAttribute('id', 'myPicture');
    myLightBox.appendChild(myPicture)
}

function CloseLightBox() 
{
    myOverlay.style.display = 'none';
    myLightBox.style.display = 'none';

    switch (myMediaType) 
    {
        case "P":
            myLightBox.removeChild(myPicture);
            break;
        case "V":
            myLightBox.removeChild(myVideo);
            break;
    }
}

function PageScroll() 
{
    yScroll;

    if (self.pageYOffset) 
    {
        yScroll = self.pageYOffset;
    }
    else 
    {
        if (document.documentElement && document.documentElement.scrollTop) 
        {
            yScroll = document.documentElement.scrollTop;
        }
        else
        {
            if (document.body) 
            {
                yScroll = document.body.scrollTop;
            }
        }
    }
    myPageScroll = new Array('', yScroll)

    return myPageScroll;
}

function PageSize() 
{
    if (window.innerHeight && window.scrollMaxY) 
    {
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    }
    else 
    {
        if (document.body.scrollHeight > document.body.offsetHeight) 
        {
            xScroll = document.body.scrollWidth;
            yScroll = document.body.scrollHeight;
        }
        else 
        {
            xScroll = document.body.offsetWidth;
            yScroll = document.body.offsetHeight;
        }
    }

    if (self.innerHeight) 
    {
        myWidth = self.innerWidth;
        myHeight = self.innerHeight;
    }
    else 
    {
        if (document.documentElement && document.documentElement.clientHeight) 
        {
            myWidth = document.documentElement.clientWidth;
            myHeight = document.documentElement.clientHeight;
        }
        else
        {
            if (document.body) 
            {
                myWidth = document.body.clientWidth;
                myHeight = document.body.clientHeight;
            }
        }
    }

    if (yScroll < myHeight) 
    {
        pHeight = myHeight;
    }
    else 
    {
        pHeight = yScroll;
    }

    if (xScroll < myWidth) 
    {
        pWidth = myWidth;
    }
    else 
    {
        pWidth = xScroll;
    }

    myPageSize = new Array(pWidth, pHeight, myWidth, myHeight)
    return myPageSize;
}


