﻿if (!Enthink) var Enthink = {};

Enthink.URLParams = {
  getVars: function( ) {
    var vars = [], hash;
    var hashes = window.location.href.slice( window.location.href.indexOf( '?' ) + 1 ).split( '&' );
    for( var i = 0; i < hashes.length; i++ )
    {
      hash = hashes[i].split( '=' );
      vars.push( hash[0] );
      vars[hash[0]] = hash[1];
    }
    return vars;
  },
  getVar: function( name ) {
    return Enthink.URLParams.getVars( )[name];
  }
};

/*--
 * Class Cookie
 */
Enthink.Cookie = {
    setCookie: function (name, value, days) {
        if (days) {
            var date = new Date();
            date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
            var expires = "; expires=" + date.toGMTString();
        }
        else var expires = "";
        document.cookie = name + "=" + value + expires + "; path=/";
    },
    getCookie: function (name) {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for (var i = 0; i < ca.length; i++) {
            var c = ca[i];
            while (c.charAt(0) == ' ') c = c.substring(1, c.length);
            if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
        }
        return null;
    },
    deleteCookie: function (name) {
        this.setCookie(name, "", -1);
    }
};
// -- end Cookie class

/*--
 * Class Overlay
 */
Enthink.Overlay = function (id) {

    Overlay = Enthink.Overlay;
    // Public STATIC variables
    Overlay.count = Overlay.count ? Overlay.count + 1 : Overlay.count = 1;
    if (!Overlay.active) { Overlay.active = 0 }
    this.init();
    // Public instance variables
    this.id = id;
    this.itemID = Overlay.count;
    this.item = null;

}
Enthink.Overlay.prototype = {

    getID: function () {
        return this.id;
    },

    getCount: function () {
        return Overlay.count;
    },

    setContent: function (url) {
        this.hideObjects();
        this.createOverlay(url);
    },

    close: function () {
        this.showObjects();
    },

    showObjects: function () {
        var elements = document.getElementsByTagName("object");
        for (e in elements) {
            if (elements[e].style)
                elements[e].style.visibility = "visible";
        }
        Overlay.iframeContentCover.style.display = "none";
        Overlay.shadowContentCover.style.display = "none";
        if (this.item)
            this.item.style.display = "none";
    },

    hideObjects: function () {
        var elements = document.getElementsByTagName("object");
        for (e in elements) {
            if (elements[e].style)
                elements[e].style.visibility = "hidden";
        }
        Overlay.iframeContentCover.style.display = "block";
        Overlay.shadowContentCover.style.display = "block";
        if (this.item)
            this.item.style.display = "block";
    },

    init: function () {
        if (!Overlay.iframeContentCover) {
            var frame = document.createElement("IFRAME");
            frame.id="enthink_iframeContentCover";
            //frame.setAttribute("style", "position: absolute; top: 0; left: 0; z-index: 100; width: 100%; height: 100%; border: none; opacity: 0; display: none; filter: alpha(opacity = 0);");
            document.body.appendChild(frame);
            Overlay.iframeContentCover = frame;
        }
        if (!Overlay.shadowContentCover) {
            var element = document.createElement("div");
            element.id = "enthink_shadowContentCover";
            //element.setAttribute("style", "position: absolute; top: 0; left: 0; z-index: 101; width: 100%; height: 100%; background: #000; display: none; padding: 0; margin: 0; opacity: 0.8; filter: alpha(opacity = 80);");
            document.body.appendChild(element);
            Overlay.shadowContentCover = element;
        }
    },

    createIFrame: function (url) {
        var frame = document.createElement("IFRAME");
        if (url)
            frame.setAttribute("src", url);
        frame.id = "frame_External";
       
        frame.setAttribute("style", "position: absolute; top: 25px; width: 640px; height: 480px; border: none; background: #fff");
        return frame;
    },

    createOverlay: function (url) {
        var element = document.createElement("div");
        element.setAttribute("style", "position: absolute; top:0; left: 0; z-index: 105; width: 100%; height: 100%;");
        element.id = "enthink-overlay-" + this.itemID;
        var x = this.createIFrame(url);
        element.appendChild(x);
        document.body.appendChild(element);

        this.item = element;
        this.hideObjects();
    },

    /*----- 
    * toString ( bool hideFunctions )
    *
    * desc: Returns all instance variables with values, 
    *       Optional flag to show or hide function definitions. 
    *       Overrides Object toString method.
    */
    toString: function (hideFunctions) {
        var str = "";
        for (var property in this)
            if (hideFunctions && typeof (this[property]) == "function")
                str += property + " : [ Object function ]\n\n";
            else
                str += property + " : [" + this[property] + "]\n\n";
        return str;
    }
};
// -- end Overlay class

$(document).ready( function( ) {
    if( Enthink.URLParams.getVar( "rssmsg" ) == "1" )
    {
        $('#rssmsg').prependTo('body').show( );
    }
});
