﻿//
// Site.js - Site-wide functions.
//

var Site = {

    goto: function(url) {
        window.location = url;
    },
    
    init: function() {
    },
    
    //
    // reveal() : Reveal effect.
    //
    reveal: function(id) {
        Site.revealWithJQuery(id);
    },
    
    //
    // conceal() : Conceal effect.
    //
    conceal: function(id) {
        Site.concealWithJQuery(id);
    },
    
    //
    // JQuery Code
    //    
    revealWithJQuery: function(id) {
        var layer = $("#"+id);
        var clipper = $("#"+id+"Clipper");
        var layout = $("#Layout");

        var newClipperHeight = layer.height() + 10;
        var newLayoutHeight  = layout.height() + newClipperHeight;
        
        clipper.animate({
            height: newClipperHeight
        });
        layout.animate({
            height: newLayoutHeight
        });
    },    
    concealWithJQuery: function(id) {
        var layer = $("#"+id);
        var clipper = $("#"+id+"Clipper");
        var layout = $("#Layout");

        var newClipperHeight = layer.height() + 10;
        var newLayoutHeight  = layout.height() - newClipperHeight;
        
        clipper.animate({
            height: 0
        });
        layout.animate({
            height: newLayoutHeight
        });
    },
    
    //
    // Ext Code
    //
    revealWithExt: function(id) {
        var layer   = Ext.get(id);
        var clipper = Ext.get(id + "Clipper");
        var layout  = Ext.get("Layout");

        var newClipperHeight = layer.getHeight() + 10;
        var newLayoutHeight  = layout.getHeight() + newClipperHeight;

        var duration = 2;
        clipper.scale(undefined, newClipperHeight, {
            duration: duration
        });        
        layout.scale(undefined, newLayoutHeight, {
            duration: duration,
            callback: function() {
               layout.setBottom("0px");    /* For Safari */
            }
        });
    },
    concealWithExt: function(id) {
        var layer   = Ext.get(id);
        var clipper = Ext.get(id + "Clipper");
        var layout  = Ext.get("Layout");

        var newClipperHeight = layer.getHeight() + 10;
        var newLayoutHeight  = layout.getHeight() - newClipperHeight;

        var duration = 2;
        clipper.scale(undefined, 0, {
            duration: duration
        });        
        layout.scale(undefined, newLayoutHeight, {
            duration: duration,
            callback: function() {
                layout.setBottom("0px");    /* For Safari */
            }
        });
    },

    onQuestionMouseOver: function(id) {
//            Ext.get(id).slideIn();            
    },
    onQuestionMouseOut: function(id) {
//            Ext.get(id).slideIn();            
    },
    
    onQuestionClick: function(id) {
        Site.onQuestionClickWithJQuery(id);
    },
    
    onQuestionClickWithJQuery: function(id) {
        if ($("#"+id+"Clipper").height() == 0) {
            Site.reveal(id);
        } else {
            Site.conceal(id);
        }
    },
    
    onQuestionClickWithExt: function(id) {
        var layer   = Ext.get(id);
        var clipper = Ext.get(id + "Clipper");

        if (clipper.getHeight() == 0) {
            Site.reveal(id);
        } else {
            Site.conceal(id);
        }
    }

};
$(document).ready(Site.init);
