﻿var Navigation={
    init:function() {
        if(!document.getElementById || !document.createTextNode) { return; }

        var navRoot = document.getElementById('navroot');
        var pageType = strPageType;
        
        for(i = 0; i < navRoot.childNodes.length; i++) {
            var node = navRoot.childNodes[i];
            if(node.nodeName == 'LI') {
                if(node.id == pageType) {
                    node.className = 'on';
                }
                node.onmouseover = function() {
                    if(this.className.indexOf('down') == -1) {
                        this.className += ' down';
                    }
                }
                node.onmouseout = function() {
                    this.className = this.className.replace('down', '');
                }
            }
        }
    }
}    
window.onload = Navigation.init;

function enlargeImage( strImage ) {
    
    //  Open a new window.
    objWin = window.open( "/app/enlarge-image.aspx?imagefilename=" + strImage, "mywin", "status=0, toolbar=0, location=0, menubar=0, resizable=0, scrollbars=0, height=560, width=640" );
    objWin.focus();
}

function imageGallery( strMode ) {
    
    //  Open a new window.
    objWin = window.open( "/app/image-gallery.aspx?mode=" + strMode, "mywin", "status=0, toolbar=0, location=0, menubar=0, resizable=0, scrollbars=0, height=560, width=640" );
    objWin.focus();
}

function gotoURL( strURL ) {

    //  Change URL.
    window.location = strURL;
}

function setAction( strActionName, strActionValue, strConfirm ) {
    var bConfirm;


    //  Request confirmation if necessary.
    if ( strConfirm != null ) {
        bConfirm = confirm( strConfirm );
    } else {
        bConfirm = true;
    }
    
    if ( bConfirm == true ) {

        //  Set the action.
        document.getElementById( "action_name" ).value = strActionName;
        document.getElementById( "action_value" ).value = strActionValue;

        //  Submit the form.
        document.getElementById( "aspnetForm" ).submit();
    }
}

function showImage( strImage ) {
    var imgLarge = document.getElementById("imgLarge");
    var imgURL = strImage.src;
    imgURL = imgURL.replace('th-', '');
    //  Set image.
    imgLarge.src = imgURL;
}

function showNextImage( strMode, curNum, maxImages ) {
    // INCREMENT
    if(curNum >= maxImages) {
        curNum = 1;
    } else {
        curNum++;
    }
    
    // UPDATE LINKS
    updateImageScrollers( strMode, curNum, maxImages );
    
    //  Set image.
    showImage(strMode + "-" + curNum + "-large.jpg");
    
}

function showPreviousImage( strMode, curNum, maxImages ) {
    
    // DECREASE
    if(curNum <= 1) {
        curNum = maxImages;
    } else {
        curNum--;
    }
    
    // UPDATE LINKS
    updateImageScrollers( strMode, curNum, maxImages );
    
    //  SET IMAGE
    showImage(strMode + "-" + curNum + "-large.jpg");
    
}

function updateImageScrollers( strMode, curNum, maxImages ) {
    var goNext = document.getElementById("goNext" + strMode);
    var goPrevious = document.getElementById("goPrevious" + strMode);
    
    var href = "Image('" + strMode + "', '" + curNum + "', '" + maxImages + "');"
    goNext.href = "javascript:showNext" + href;
    goPrevious.href = "javascript:showPrevious" + href;
}