﻿/**
 * Stream.Page Namespace
 * Used for the following inner pages of the new Stream Realty website: About, Locations, Services and People.
 * Developed by Soho Pros., Inc.
 *
 * All private variables and functions begin with _.  They should not be referenced or called from outside of Stream.Page.
 * -----------------------------------------------------------------------------------------------------------------------
 */

Stream.Page = {
    /***** Variables *****/
    totalSubCats: 0,       
    currentSubCat: 0, 
    contentWrapper: null,
    subCatContainer: null,
    subMenu: null,
    backGround: null,
    subCatDivs: new Array(),
    subCatLinks: new Array(),
    arrowImgs: new Array(),
    /***** End Variables *****/
    
    
    /***** Functions *****/
    /**
     * function init()
     * Called when the window loads - will initialize the variables, set the onmouseover and onmouseout functions of the sub category links
     * and start the intro effects.
     */
    init: function() {
        // Initialize all the variables
        SP.subCatContainer = subCatContainer;
        SP.subMenu = subMenu;
        SP.backGround = divBackGround;
        SP.subCatDivs = subCatDivs;
        SP.subCatLinks = subMenuDivs;
        SP.arrowImgs = arrowImgs;
        SP.totalSubCats = SP.subCatLinks.length;
        
        // Set onmouseover and onmouseout for the links
        for (var i = 0; i < SP.subCatLinks.length; i++) {
            SP.subCatLinks[i].onmouseover = function(e) {
                for (var j = 0; j < SP.subCatLinks.length; j++) { 
                    if (SP.subCatLinks[j] == this) {
                        SP.subCatLinks[j].style.textDecoration = 'none';
                        SP.arrowImgs[j].style.visibility = 'visible';
                        SP.subCatLinks[j].style.cursor = 'pointer';
                    }
                }
                return false;
            };
            SP.subCatLinks[i].onmouseout = function(e) {
                for (var j = 0; j < SP.subCatLinks.length; j++) { 
                    //if ((SP.subCatLinks[j] == this) && (j != SP.currentSubCat)) {         // Commented out to prevent arrow from staying next to selected item
                        SP.subCatLinks[j].style.textDecoration = 'none';
                        SP.arrowImgs[j].style.visibility = 'hidden';
                    //}                                                                     // Commented out to prevent arrow from staying next to selected item
                }
                return false;
            };
        }
        //SP.arrowImgs[SP.currentSubCat].style.visibility = 'visible';                      // Commented out to prevent arrow from staying next to selected item
        
        // Start the effects
        new Effect.BlindUp('divBackGroundCover', { duration: .5 });
        setTimeout("SP.loadSubMenu()", 500);
        setTimeout("SP.loadDivs()", 500);
        
        return false;
    },

    /**
     * function loadSubMenu()
     * Executes the effects to bring in the sub category links menu.
     */
    loadSubMenu: function() {
        // Fade in the menu
        new Effect.Appear(SP.subMenu, { duration: .8, from: 0, to: .99 });
    },
    
    /** 
     * function loadDivs()
     * Executes the effects to bring in the initial categories content.
     */
    loadDivs: function() {
        SP.subCatContainer.style.display = 'block';
        Effect.Appear(SP.subCatContainer, { duration: .8, from: 0, to: 0.99 });
        Effect.BlindDown(SP.subCatDivs[SP.currentSubCat], { duration: 0 });   
    },
    
    /**
     * function showSubCat(elem, subCat)
     * The onclick function of the sub category links.  Will BlindUp the current displayed content and then call
     * SP._showSelectedSubCat(subCat) to display the selected sub category content.
     */
    showSubCat: function(elem, subCat) {
        if (SP.currentSubCat != subCat) { 
            for (var i = 0; i < SP.totalSubCats; i++) SP.arrowImgs[i].style.visibility = 'hidden';
            SP.arrowImgs[subCat].style.visibility = 'visible';                            
            Effect.BlindUp(SP.subCatDivs[SP.currentSubCat], { duration: 0.5 });
            setTimeout("SP._showSelectedSubCat(" + subCat + ")", 500);
            SP.currentSubCat = subCat;
        }
        return false;
    },
    
    /** 
     * function _showSelectedSubCat(subCat)
     * A private function called by showSubCat that will BlindDown the selected sub category content.
     */
    _showSelectedSubCat: function(subCat) {
        SP.subCatContainer.show();
        Effect.BlindDown(SP.subCatDivs[subCat], { duration: .75 }); 
    }
};

