﻿// JScript File

var timeout;
var topTimeout;

function showSubMenu()
{
//    if (timeout != undefined)
//        clearTimeout(timeout);
//        
//    var submenu = document.getElementById("submenu");

   var gallery = document.getElementById("gallery");
   var submenuStyle = document.getElementById("submenu").style;
  
    if (timeout != undefined)
        clearTimeout(timeout);
        
    if (topTimeout != undefined)
        clearTimeout(topTimeout);

   if (submenuStyle.opacity != "" && submenuStyle.opacity != undefined)
   {
        var opacityStr = submenuStyle.filter.substring(submenuStyle.filter.indexOf("=") + 1, submenuStyle.filter.indexOf(")"));

        if (submenuStyle.opacity < 1 || opacityStr < 100)
        {
            opacity("submenu", opacityStr, 100, 500);
        }
   } 
   else {
        opacity("submenu", 0, 100, 500);
        }
//    if (submenu.style.opacity < 100)
//    {
//        opacity("submenu", 0, 100, 1000);
//        gallery.style.background = "url(images/menu_line.gif) no-repeat center bottom";
//        
//    }     
}
function hideSubMenu()
{
   topTimeout = setTimeout("actualHideSubMenu()", 200);
}
function actualHideSubMenu()
{
    var submenuStyle = document.getElementById("submenu").style;
    opacity("submenu", submenuStyle.opacity * 100, 0, 500);
}


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--) {
            timeout = setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;            
        }
    } else if(opacStart < opacEnd) {
    
        for(i = opacStart; i <= opacEnd; i++)
            {
            timeout = setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {

    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
    
    if (opacity == 0)
        object.display = "none";
    else
        object.display = "inline";
} 
function closeWindow(id)
{
    var popupStyle = document.getElementById(id).style;
    popupStyle.display = "none";
    
    var parent = document.getElementById("imgPopupInner");
    var elementVar = document.getElementById("fullImage");
    parent.removeChild(elementVar);
}
function openWindow(id)
{
    var popupStyle = document.getElementById(id).style;
    
    if (popupStyle.display == "block")
        popupStyle.display = "none";
    else
        popupStyle.display = "block";
}
function SetToScroll(id)
{
    var popupStyle = document.getElementById(id).style;
    popupStyle.position = "absolute";
    popupStyle.top = (document.documentElement.scrollTop + 30) + "px";
    popupStyle.margin = "0px auto";
}
function openAndScroll(id)
{
    openWindow(id);
    SetToScroll(id);
    return false;
}
function openImage(popupId, imageUrl, width, height)
{
    var popup = document.getElementById(popupId);
    popup.style.width = width + "px";

    var closeBtn = document.getElementById('imgCloseBtn');
    closeBtn.style.top = ( -1 * (height - 10)) + "px"
    popup.style.margin = "0px auto";
    var imageObj = document.getElementById('fullImage');
    imageObj.src = imageUrl;
    
    SetToScroll('imgPopup');
    openWindow(popupId);
}
function openImage(popupId, imageUrl, width, height, imgTitle, imgText)
{
    var imgObj = document.createElement('img');
    imgObj.setAttribute('id', 'fullImage');
    imgObj.setAttribute('alt', imgTitle);
    imgObj.setAttribute('src', imageUrl);
    
    var popup = document.getElementById(popupId);
    
    popup.style.width = width + "px";

    var closeBtn = document.getElementById('imgCloseBtn');
    closeBtn.style.top = ( -1 * (height - 10)) + "px"
    popup.style.margin = "0px auto";

    closeBtn.parentNode.insertBefore(imgObj, closeBtn);
    
    var title = document.getElementById('imgTitle');
    if(imgTitle != null && imgTitle != "" && imgTitle != "untitled")
    {
        title.innerHTML = imgTitle;
    }
    else
        title.innerHTML = "";
    
    var imgTextDiv = document.getElementById('imgText');
    imgTextDiv.innerHTML = '';
    if (imgText != null && imgText != "")
    {
        imgTextDiv.innerHTML += imgText;
    }
    SetToScroll('imgPopup');
    openWindow(popupId);
}