function ezyOverlay() {
    if ($('BACKDROP')) {
		new Effect.Fade('BACKDROP', { duration: 0.2});
        document.body.removeChild($('BACKDROP'));
    }
    else {
        var documentBody = Element.getDimensions(document.body);
        var documentWidth = document.body.clientWidth;
        var documentHeight = document.body.clientHeight;
    	var objOverlay = document.createElement("DIV");
    	objOverlay.setAttribute('id', 'BACKDROP');
    	objOverlay.style.position = 'absolute';
    	objOverlay.style.top = '0px';
    	objOverlay.style.left = '0px';
        objOverlay.style.width = documentWidth + "px";
        objOverlay.style.height = documentHeight + "px";
    	objOverlay.style.backgroundColor = '#000';
    	objOverlay.style.zIndex = '50';
    	objOverlay.style.display = 'none';
    	document.body.appendChild(objOverlay);
        Effect.Appear('BACKDROP', { duration: 0.2, from: 0.0, to: 0.8 });
    }
}

function ezyContainer(id, style, options) {
    if (typeof options == 'undefined') options = {};
    $(id).getElementsByTagName('DIV')[0].className = (style || 'noStyle');

    if (options['fullScreen'] || false) {
        if ($(id + '-FULLSIZE')) {}
        else createFullSizeContainer(id, options);
        $(id + '-FULLSIZE').innerHTML = $(id).innerHTML;
        $(id).getElementsByTagName("DIV")[0].innerHTML = ''; $(id).style.display = 'none';
        $(id + '-FULLSIZE').className = 'website';
    	$(id + '-FULLSIZE').style.zIndex = '60';
        $(id + '-FULLSIZE').style.display = 'block';
        id += '-FULLSIZE';
        positionContainer(id);
    }

    var defaultControl = '<DIV class="container-close" onClick="container.close(\'' + id + '\')"></DIV>';
    var item = $(id).getElementsByTagName("FIELDSET");
    if (item.length > 0) {
        for(i=0; i<item.length; i++) {
            if(item[i].className.toLowerCase() == 'form') continue;
            var itemID = item[i].id || 'P01';
            var effects = '{' + (item[i].getAttribute('effects') || '') + '}';
            var customControl = '';
            if(item[i].id == '') item[i].id = itemID; 
            if(itemID != '') {
                if($(itemID).getElementsByTagName('DIV').length > 0) {
                    customControl = ($(itemID).getElementsByTagName('DIV')[0].getAttribute('customControl') || '');
                    while (customControl.indexOf('[id]') != -1)
                        customControl = customControl.replace('[id]', '\"' + itemID + '\"');
                    $(itemID).getElementsByTagName('DIV')[0].setAttribute('customControl', customControl);
                }
            }
            item[i].className += ' ' + (item[i].getAttribute('styleID') || '');

            var itemTitle = '';
            if(item[i].getElementsByTagName("LEGEND").length > 0) {
                itemTitle = item[i].getElementsByTagName("LEGEND")[0].innerHTML;
                item[i].removeChild(item[i].getElementsByTagName("LEGEND")[0]);
            }

            var containerOnLoad = '';
            if(item[i].getElementsByTagName("DIV").length > 0)
                containerOnLoad = item[i].getElementsByTagName("DIV")[0].getAttribute('onLoad') || '';

            item[i].id = "";
            var itemHTML = '<DIV id="' + itemID + '" class="yui-panel" style="VISIBILITY:inherit; WIDTH:' + (options['width'] || 100) + '">' +
    					   '<DIV id="' + itemID + '-hd" class="hd"><DIV class="tl"></DIV><DIV class="tt">' + itemTitle + '</DIV>' +
                           '<DIV id="' + itemID + '-cp" class="cp">' + ((customControl == '') ? ((options['close'] || false) ? defaultControl : '') : customControl) + '</DIV>' +
                           '<DIV class="tr"></DIV></DIV>' +
    					   '<DIV id="' + itemID + '-bd" class="bd">' + item[i].innerHTML + '</DIV></DIV>';
            item[i].innerHTML = itemHTML;
            item[i].style.display = "block";
            if(effects.indexOf('attention:true') != -1) Effect.Pulsate(itemID + '-hd');
            if(containerOnLoad != '') eval(containerOnLoad);

            if(itemID != '') {
                if(customControl != '') {
                    $(itemID + '-cp').style.visibility = 'hidden';
                    $(itemID).onmouseover = Function('container.show("' + itemID + '")');
                    $(itemID).onmouseout = Function('container.hide("' + itemID + '")');
                }
            }
        }
    }

    function createFullSizeContainer(id) {
        if (typeof options == 'undefined') options = {};

        var documentWidth = document.body.clientWidth;
        var documentHeight = document.body.clientHeight;
    	var objOverlay = document.createElement('DIV');
    	objOverlay.setAttribute('id', id + '-FULLSIZE');
    	objOverlay.style.zIndex = '100';
    	objOverlay.style.position = 'absolute';
    	objOverlay.style.border = '0 none transparent';
    	objOverlay.style.top = '0px';
    	objOverlay.style.left = '0px';
        objOverlay.style.width = (options['width'] || parseInt(documentWidth / 2)) + 'px';
        objOverlay.style.height = (options['height'] || parseInt(documentHeight / 2)) + 'px';
    	objOverlay.style.backgroundColor = 'transparent';
    	document.body.appendChild(objOverlay);
    }

    function positionContainer(id, placement) {
        placement = (placement || 'center');
        var documentWidth = document.body.clientWidth;
        var documentHeight = document.body.clientHeight;

        $(id).style.top = parseInt(((documentHeight - Element.getDimensions(id)['height']) / 2) * 0.7) + 'px';
        switch(placement.toLowerCase()) {
            case 'left':
                $(id).style.left = '20px';
                break;
            case 'center':
                $(id).style.left = parseInt((documentWidth - Element.getDimensions(id)['width']) / 2) + 'px';
                break;
            case 'right':
                $(id).style.right = '20px';
                break;
        }
    }
}

ezyMenu = function(id, style, options) {
    style = (style || "noStyle");
    if (typeof options == "undefined") options = {};

    var oAnim;

    function setupMenuAnimation(p_oMenu) {
        if(!p_oMenu.animationSetup) {
            var aItems = p_oMenu.getItemGroups();
            if(aItems && aItems[0]) {
                var i = aItems[0].length - 1;
                var oSubmenu;

                do {
                    oSubmenu = p_oMenu.getItem(i).cfg.getProperty("submenu");
                    if(oSubmenu) {
                        oSubmenu.beforeShowEvent.subscribe(onMenuBeforeShow, oSubmenu, true);
                        oSubmenu.showEvent.subscribe(onMenuShow, oSubmenu, true);
                    }
                } while(i--);
            }
            p_oMenu.animationSetup = true;
        }
    }

    function onMenuBeforeShow(p_sType, p_sArgs, p_oMenu) {
        if(oAnim && oAnim.isAnimated()) {
            oAnim.stop();
            oAnim = null;
        }
        YAHOO.util.Dom.setStyle(this.element, "overflow", "hidden");
        YAHOO.util.Dom.setStyle(this.body, "marginTop", ("-" + this.body.offsetHeight + "px"));
    }

    function onMenuShow(p_sType, p_sArgs, p_oMenu) {
        oAnim = new YAHOO.util.Anim(
            this.body, 
            { marginTop: { to: 0 } },
            .5, 
            YAHOO.util.Easing.easeOut
        );
        oAnim.animate();

        var me = this;
        function onTween() {
            me.cfg.refireEvent("iframe");
        }
        function onAnimationComplete() {
            YAHOO.util.Dom.setStyle(me.body, "marginTop", ("0px"));
            YAHOO.util.Dom.setStyle(me.element, "overflow", "visible");
            setupMenuAnimation(me);
        }

        if(this.cfg.getProperty("iframe") == true) {
            oAnim.onTween.subscribe(onTween);
        }
        oAnim.onComplete.subscribe(onAnimationComplete);
    }

    function onMenuRender(p_sType, p_sArgs, p_oMenu) {
        setupMenuAnimation(p_oMenu);
    }

    var oMenuBar = new YAHOO.widget.MenuBar(id, { iframe:true, autosubmenudisplay:true, hidedelay:750, lazyload:true });
    oMenuBar.renderEvent.subscribe(onMenuRender, oMenuBar, true);
    oMenuBar.render();
};

function ezyTab(id, style, options) {
    $(id).getElementsByTagName('DIV')[0].className = 'tab ' + (style || 'noStyle');
    if (typeof options == 'undefined') options = {};

    var item = $(id).getElementsByTagName('A');
    if (item.length > 0) {
        var firstTabID = item[0].getAttribute('target');
        for(var i=0; i<item.length; i++) {
            $(item[i].getAttribute('target')).style.display = 'none';
            $(item[i].getAttribute('target')).setAttribute('rel', '[' + id + ']');
            if ((item[i].getAttribute('url') || '') == '') item[i].href = 'javascript:tabOnClick("dhtml://' + id + '", "' + item[i].getAttribute('target') + '")';
            else item[i].href = 'javascript:tabOnClick("' + item[i].getAttribute('url') + '", "' + item[i].getAttribute('target') + '")';
            item[i].setAttribute('target', '');
            var itemHTML = '<SPAN class="yui-tab" ' +
                                'onMouseOver="tabOnMouseOver(this)" onMouseOut="tabOnMouseOut(this)" ' +
                                'style="VISIBILITY:inherit; WIDTH:' + (options["width"] || 50) + '">' +
    					   '<DIV class="hd"><DIV class="tl"></DIV>' + item[i].innerHTML + '<DIV class="tr"></DIV></DIV>' +
                           '</SPAN>';
            item[i].innerHTML = itemHTML;
        }
        $(firstTabID).style.display = 'block';
    }
}

function tabOnClick(url, target) {
    if (url == "") return;
    if (target == "") window.location.href = url;
    else if ($(target).tagName.toUpperCase() == "IFRAME") $(target).src = url;
    else if (url.substr(0, "ajax://".length).toLowerCase() == "ajax://") { }
    else if (url.substr(0, "dhtml://".length).toLowerCase() == "dhtml://") {
        var id = url.substring(8);
        var item = document.getElementsByTagName('DIV');
        for(var i=0; i<item.length; i++) {
            if ((item[i].getAttribute('rel') || '') == '[' + id + ']')
                item[i].style.display = (item[i].id == target) ? 'block' : 'none';
        }
    }
}

function tabOnMouseOver(e) {
    e = e.getElementsByTagName("DIV");
    for(var i=0; i<e.length; i++) {
        e[i].className += " " + e[i].className + "-over";
    }
}

function tabOnMouseOut(e) {
    e = e.getElementsByTagName("DIV");
    for(var i=0; i<e.length; i++) {
        if (e[i].className.toLowerCase().indexOf("-over") != -1)
            e[i].className = e[i].className.substring(0, 2);
    }
}

function ezyButton(id) {
    var item = $(id).getElementsByTagName("INPUT");
    var aButton = Array();
    for(var i=0; i<item.length; i++) aButton.push(item[i].id);
    for(var i=0; i<aButton.length; i++) {
        if (typeof $(aButton[i] + "menu") != "undefined")
            new YAHOO.widget.Button(aButton[i], { type: "splitbutton", menu: aButton[i] + "menu" });
        else
            new YAHOO.widget.Button(aButton[i]);
    }
}

var ezyRSS_TIMER = null;
function ezyRSS_Scan(divID, forceStart) {
    divID = divID || 'CONTENT';
    forceStart = forceStart || false;
    if(forceStart) {
        eval("ezyRSS('RSS', {" + $('RSS').getAttribute('option') + "})");
    } else {
        var RSS_Item = $(divID).getElementsByTagName('DIV');
        for(var i=0; i<RSS_Item.length; i++) {
            if((RSS_Item[i].id == '') && (RSS_Item[i].className == 'RSS')) {
                RSS_Item[i].id = 'RSS';
                eval("ezyRSS('RSS', {" + RSS_Item[i].getAttribute('option') + "})");
                break;
            }
        }
    }
}

function ezyRSS(id, options) {
    clearTimeout(ezyRSS_TIMER);
    options = options || {};
    options['size'] = options['size'] || 150;
    options['interval'] = options['interval'] || 5000;

    var fwdDirection = true;
    var rssContent = $(id + '.content').getElementsByTagName('DIV');
    if(rssContent.length == 0) return;
    $(id).style.height = options['size'] + 'px';

    if(((getCookie('RSS', 'command') || 0) == 0) && (parseInt(rssContent[rssContent.length - 2].style.marginTop || 0) < 0)) {
        scroll();
    } else {
        var yInitialization = true;
        for(var i=0; i<rssContent.length; i++) {
            if((rssContent[i].className == "rssItem") && (rssContent[i].style.display == "none")) {
                yInitialization = false; break;
            }
        }
        if(yInitialization) {
            putCookie('RSS', 'options', $H(options).inspect());
            for(var i=0; i<rssContent.length; i++) {
                if(rssContent[i].className == 'rssItem') {
                    rssContent[i].style.height = options['size'] + 'px';
                    rssContent[i].style.display = 'none';
                }
            }
            append();
            ezyRSS_TIMER = setTimeout('ezyRSS("' + id + '", ' + $H(options).inspect() + ')', options['interval']);
        } else {
            rssContent[rssContent.length - 2].style.marginTop = 0;
            if((getCookie('RSS', 'command') || 0) == 2) return;
            append();
            scroll();
        }
    }

    function append() {
        if(((getCookie('RSS', 'effect') || 'SLIDEDOWN').toUpperCase() == 'SLIDEDOWN')
                && ((getCookie('RSS', 'command') || 0) == 0))
            fwdDirection = true;
        else if(((getCookie('RSS', 'effect') || 'SLIDEDOWN').toUpperCase() == 'SLIDEDOWN')
                && ((getCookie('RSS', 'command') || 0) == 1))
            fwdDirection = false;
        else if(((getCookie('RSS', 'effect') || 'SLIDEDOWN').toUpperCase() == 'SLIDEUP')
                && ((getCookie('RSS', 'command') || 0) == 0))
            fwdDirection = false;
        else if(((getCookie('RSS', 'effect') || 'SLIDEDOWN').toUpperCase() == 'SLIDEUP')
                && ((getCookie('RSS', 'command') || 0) == 1))
            fwdDirection = true;
        else fwdDirection = true;
        if(fwdDirection) {
            var rssDIV = document.createElement('DIV');
            rssDIV.innerHTML = rssContent[0].innerHTML;
            rssDIV.className = 'rssItem';
            rssDIV.style.height = options['size'] + 'px';
            rssDIV.style.display = 'block';
            $(id + '.content').appendChild(rssDIV);
            $(id + '.content').removeChild(rssContent[0]);
        } else {
            var rssDIV = document.createElement('DIV');
            rssDIV.innerHTML = rssContent[rssContent.length - 1].innerHTML;
            rssDIV.className = 'rssItem';
            rssDIV.style.height = options['size'] + 'px';
            rssDIV.style.display = 'none';
            $(id + '.content').insertBefore(rssDIV, rssContent[0]);
            $(id + '.content').removeChild(rssContent[rssContent.length - 1]);
            rssContent[rssContent.length - 1].style.display = 'block';
        }
    }

    function scroll() {
        if(rssContent.length < 2) return;
        if((getCookie('RSS', 'command') || 0) == 2) return;
        if(fwdDirection) {
            if(((getCookie('RSS', 'command') || 0) != 0) || (-parseInt(rssContent[rssContent.length - 2].style.marginTop || 0) > options['size'])) {
                rssContent[rssContent.length - 2].style.display = 'none';
                rssContent[rssContent.length - 2].style.marginTop = 0;
                putCookie('RSS', 'command', 0);
                ezyRSS_TIMER = setTimeout('ezyRSS("' + id + '", ' + $H(options).inspect() + ')', options['interval']);
            } else {
                rssContent[rssContent.length - 2].style.marginTop = (parseInt(rssContent[rssContent.length - 2].style.marginTop || 0) - 1) + 'px';
                ezyRSS_TIMER = setTimeout('ezyRSS("' + id + '", ' + $H(options).inspect() + ')', 5);
            }
        } else {
            if(((getCookie('RSS', 'command') || 0) != 0) || (-parseInt(rssContent[rssContent.length - 2].style.marginTop || 0) > options['size'])) {
                rssContent[rssContent.length - 2].style.display = 'none';
                rssContent[rssContent.length - 2].style.marginTop = 0;
                putCookie('RSS', 'command', 0);
                ezyRSS_TIMER = setTimeout('ezyRSS("' + id + '", ' + $H(options).inspect() + ')', options['interval']);
            } else {
                rssContent[rssContent.length - 2].style.marginTop = (parseInt(rssContent[rssContent.length - 2].style.marginTop || 0) + 1) + 'px';
                ezyRSS_TIMER = setTimeout('ezyRSS("' + id + '", ' + $H(options).inspect() + ')', 5);
            }
        }
    }
}

var ezyQUOTE_TIMER = null;
var ezySCROLL_TIMER = null;
function ezyScroller(id, options) {
    if(typeof $(id) == 'undefined') return;
    if(id.toUpperCase() == 'QUOTE') clearTimeout(ezyQUOTE_TIMER);
    else clearTimeout(ezySCROLL_TIMER);

    if((getCookie(id, 'options') || null) == null) putCookie(id, 'options', $H(options).inspect());
    $(id).style.visibility = 'visible';
    options = options || {};
    options['interval'] = options['interval'] || 15;
    if((getCookie(id, 'command') || 0) == 0) {
        scroll(options, true);
    } else if((getCookie(id, 'command') || 0) == 1) {
        putCookie(id, 'command', 2);
        scroll(options, false);
    } else if((getCookie(id, 'command') || 0) == 3) {
        putCookie(id, 'command', 2);
        scroll(options, true);
    }

    if(id.toUpperCase() == 'QUOTE')
        ezyQUOTE_TIMER = setTimeout('ezyScroller("' + id + '", ' + $H(options).inspect() + ')', options['interval'] * 1000);
    else
        ezySCROLL_TIMER = setTimeout('ezyScroller("' + id + '", ' + $H(options).inspect() + ')', options['interval'] * 1000);

    function scroll(options, fwdDirection) {
        options = options || {};
        switch((options['effects'] || '').toLowerCase()) {
            case 'fade'     : var scrollFm = 'Fade';      var scrollTo = 'Appear';    break;
            case 'slide'    : var scrollFm = 'SlideUp';   var scrollTo = 'SlideDown'; break;
            case 'blind'    : var scrollFm = 'BlindUp';   var scrollTo = 'BlindDown'; break;
            case 'shrink'   : var scrollFm = 'Shrink';    var scrollTo = 'Grow';      break;
            case 'drop'     : var scrollFm = 'Fold';      var scrollTo = 'BlindDown'; break;
            case 'puff'     : var scrollFm = 'Puff';      var scrollTo = 'Appear';    break;
            case 'squish'   : var scrollFm = 'Squish';    var scrollTo = 'SlideDown'; break;
            case 'switch'   : var scrollFm = 'SwitchOff'; var scrollTo = 'Appear';    break;
            default         : var scrollFm = 'Fade';      var scrollTo = 'Appear';    break;
        }
        scrollBlock = $(id).getElementsByTagName("LI");
    
        var activeItem = fwdDirection ? -1 : scrollBlock.length;
        for(i=0; i<scrollBlock.length; i++) {
            if((scrollBlock[i].id || '') == '') {
                scrollBlock[i].id = id + i;
                scrollBlock[i].style.display = 'none';
                continue;
            }
            else if (scrollBlock[i].style.display == '') {
                eval('Effect.' + scrollFm + '("' + scrollBlock[i].id + '", {queue:"first",duration:0.5})');
                activeItem = i;
            }
        }
    
        if(fwdDirection) {
            activeItem += 1;
            if (activeItem >= scrollBlock.length) activeItem = 0;
        } else {
            activeItem -= 1;
            if (activeItem < 0) activeItem = scrollBlock.length - 1;
        }
        eval('Effect.' + scrollTo + '("' + scrollBlock[activeItem].id + '", {queue:"end",duration:0.5})');
    }
}

function ezyLightbox(id) {
    var item = $(id).getElementsByTagName("A");
    for(var i=0; i<item.length; i++) {
        item[i].innerHTML = item[i].title + '<BR />' +
                            '<IMG src="' + item[i].href.replace("screenshot", "screenshot/thumb") + '" />';
    }
    var gallery = new Lightbox();
}

function getQueryParam(paramName) {
	var oRegex = new RegExp('[\?&]' + paramName + '=([^&]+)', 'i');
	var oMatch = oRegex.exec(window.location.search);
	return (oMatch && oMatch.length > 1) ? unescape(oMatch[1]) : "";
}

function getCookie(id, name) {
    eval('var cookie = {' + $(id).getAttribute('cookie') + '}');
    return cookie[name];
}

function putCookie(id, name, value) {
    eval('var cookie = {' + $(id).getAttribute('cookie') + '}');
    cookie[name] = value;
    cookie = $H(cookie).inspect();
    cookie = cookie.substring(1, cookie.length - 1);
    while(cookie.indexOf("\\'") != -1) cookie = cookie.replace("\\'", "");
    $(id).setAttribute('cookie', cookie);
}
