﻿
window.onload = function () {
    loadRollovers();
    setInterval('hideAllInactiveMenus()', 50);
}

var menus = new Array();

var currentMenuID = 'none';
var currentMenuStatus = 'inactive';

function hideAllInactiveMenus() {
    for (var i = 0; i < menus.length; i++) {
        if (currentMenuID != menus[i]) {
            performHideMenu(menus[i]);
        }
    }
}

function showMenu(id) {
    if (menus[id] == null) {
        menus.push(id);
    }
    hideAllInactiveMenus();
    if (currentMenuStatus == 'inactive') {
        var obj = $('.' + id);
        obj.fadeIn(210);
        currentMenuID = id;
        hideAllInactiveMenus();
    }
}

function hideMenu(id) {
    setTimeout("performHideMenu('"+id+"')", 200);
}

function performHideMenu(id) 
{    
    if (currentMenuStatus == 'inactive') {
        $('.' + id).hide();
    }    
}

function setCurrentMenuID(id) {
    currentMenuID = id;
}

/*** start rollover code ***/
var EventCollection = new Array();
// custom event object used to store pre-existing events
function Event() {
    this.ObjectReference = null;
    this.MouseOver = null;
    this.MouseOut = null;
    this.Key = null;
}
function loadRollovers() {
    var imgs = document.getElementsByTagName('img');
    for (var i = 0; i < imgs.length; i++) {

        // catalog and stack existing event listeners into a custom object
        // and attach to the object
        if (imgs[i].src.indexOf('_off') > -1 ||
           imgs[i].src.indexOf('_active') > -1) {
            var existingMouseover = imgs[i].onmouseover;
            var existingMouseout = imgs[i].onmouseout;
            var tempEvent = new Event();
            var addEvent = false;
            tempEvent.Key = Guid();
            if (existingMouseover != undefined) {
                tempEvent.MouseOver = existingMouseover;
                addEvent = true;
            }
            if (existingMouseout != undefined) {
                tempEvent.MouseOut = existingMouseout;
                addEvent = true;
            }
            if (addEvent) {
                EventCollection[tempEvent.Key] = tempEvent;
                imgs[i].EventKey = tempEvent.Key;
                imgs[i].Event = tempEvent;
            }
        }
        // modify the event listeners to handle the rollover image changes
        // and fire the existing event listeners if they exist
        if (imgs[i].src.indexOf('_off') > -1) {
            var tmpImage = new Image();
            tmpImage.src = imgs[i].src.replace('_off', '_over');                       
            imgs[i].onmouseover = function () {
                this.src = this.src.replace('_off', '_over');
                if (this.Event != null && this.Event.MouseOver != null) {
                    this.Event.MouseOver();
                }
            }
            imgs[i].onmouseout = function () {
                this.src = this.src.replace('_over', '_off');
                if (this.Event != null && this.Event.MouseOut != null) {
                    this.Event.MouseOut;
                }
            }
        }
        if (imgs[i].src.indexOf('_active') > -1) {
            imgs[i].onmouseover = function () {
                if (this.Event != null && this.Event.MouseOver != null) {
                    this.Event.MouseOver();
                }
            }
            imgs[i].onmouseout = function () {
                if (this.Event != null && this.Event.MouseOut != null) {
                    this.Event.MouseOut;
                }
            }
        }
    }
}
function S4() {
    return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
}
function Guid() {
    return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
}
/*** end rollover code ***/


/*** start disqus functionality ***/
$(window).ready(function () {
    //    if ($('.center') != null) {
    //        $('.center').append('<div id="disqus_thread" style="position:relative;">');
    //    }
    if ($('#disqus_thread').length > 0) {
        var css = document.createElement('link');
        css.setAttribute('type', 'text/css');
        css.setAttribute('src', '/css/disqus.css');
        css.setAttribute('rel', 'stylesheet');
        css.setAttribute('media', 'screen');
        document.getElementsByTagName('head')[0].appendChild(css);

        /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
        var disqus_shortname = 'embodiworks';

        // The following are highly recommended additional parameters. Remove the slashes in front to use.
        var disqus_url = window.location.href;   
        var disqus_developer = 0;

        /* * * DON'T EDIT BELOW THIS LINE * * */
        (function () {
            var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
            dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
            (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
        })();
    }
});
/*** end disqus ***/

