/**
 * @version $Revision: 1.33 $ $Date: 2005/07/24 18:37:04 $
 * @author Chris Smith <chris@jacko.com>
 */
var Debaser = {

    is_ie : false,
    is_safari : false,
    
    init : function() {
        this.is_ie = document.all ? true : false;
        var ua = navigator.userAgent.toLowerCase();
        this.is_safari = ua.indexOf('safari') + 1 ? true : false;
    },

    /* ------------- utilities */
    hideElementById : function(id) {
        $(id).style.display="none";
    },
    showElementById : function(id) {
        $(id).style.display="block";
    },

    getEventToElement :function(ev) {
        if (this.is_ie) {
           return window.event.toElement;
        } else {
           return ev.relatedTarget;
        }
    },

    elementContainsElement : function(container, containee) {
        var isParent = false;
        do {
            if (container == containee) {
                isParent = true;
                break;
            }
            containee = containee.parentNode;
        } while (containee != null);
        return isParent;
    },

    toggleDrawer : function(toShow, toHide) {
        this.showElementById(toShow);
        this.hideElementById(toHide);
    },

    toggleDrawerAuto : function(toShow, toHide, outerElement, ev) {
        var toElement = Debaser.getEventToElement(ev);
        /* check to makke sure we really left the outer element */
        if (Debaser.elementContainsElement(outerElement, toElement)) {
            return;
        } else {
            Debaser.toggleDrawer(toShow, toHide);
        }
    },

    hideSidebar : function(specialEffects) {
        if (specialEffects) {
            new Rico.Effect.FadeTo( 'gsSidebarInner', 0.0, 200, 10, {complete:function() { new Rico.Effect.Size( 'gsSidebar', 1, null, 500, 10, {complete:function () {Debaser.hideElementById('gsSidebar');}});}});
        } else {
            Debaser.hideElementById("gsSidebarInner");
            Debaser.hideElementById('gsSidebar');
        }

        this.hideElementById("gsHideSidebar");
        this.showElementById("gsShowSidebar");
    },
    showSidebar : function(specialEffects) {
        this.showElementById("gsSidebar");
        if (specialEffects) {
            this.setOpacity('gsSidebarInner', 0.0); 
            new Rico.Effect.Size( 'gsSidebar', 200, null, 500, 10, {complete:function() {Debaser.showElementById("gsSidebarInner"); new Rico.Effect.FadeTo( 'gsSidebarInner', 1.0, 200, 10, null);}});
        } else {
            Debaser.showElementById("gsSidebarInner");
        }

        this.hideElementById("gsShowSidebar");
        this.showElementById("gsHideSidebar");

    },
    setOpacity : function(id, newOpacity) {
      $(id).style.filter = "alpha(opacity:"+Math.round(newOpacity*100)+")";
      $(id).style.opacity = newOpacity; /*//*/;
    },
    fadeIn : function(id, random) {
        var time = 1000;
        var steps = 5;
        if (random) {
            steps += Math.round(Math.random()*10);
        }
        this.setOpacity(id, 0.1);
        new Rico.Effect.FadeTo(id, 1.0, time, steps, null);  
    },

}
Debaser.init();


