var Nashvek = {
    _sliding: false,
    showShield: function() {
        $('shield').show();
        $('shield').style.height = this.getyScroll() + 'px';
        this._keepFixed('pop-up');
        $('pop-up').show();
    },
    hideShield: function() {
        $('shield').hide();
        $('pop-up').hide();
    },
    getyScroll: function() {
        yScroll = 0;

        if (window.innerHeight && window.scrollMaxY || window.innerWidth && window.scrollMaxX) {
            yScroll = window.innerHeight + window.scrollMaxY;
            xScroll = window.innerWidth + window.scrollMaxX;

            var deff = document.documentElement;
            var wff = (deff&&deff.clientWidth) || document.body.clientWidth || window.innerWidth || self.innerWidth;
            var hff = (deff&&deff.clientHeight) || document.body.clientHeight || window.innerHeight || self.innerHeight;

            xScroll -= (window.innerWidth - wff);
            yScroll -= (window.innerHeight - hff);
        } else if (document.body.scrollHeight > document.body.offsetHeight || document.body.scrollWidth > document.body.offsetWidth) {
            yScroll = document.body.scrollHeight;
            xScroll = document.body.scrollWidth;
        } else {
            yScroll = document.body.offsetHeight;
            xScroll = document.body.offsetWidth;
        }

        return yScroll;
    },
    _keepFixed: function(element)
    {
        if($(element) != null) {
            var offsetX = document.viewport.getScrollOffsets()[0];
            var offsetY = document.viewport.getScrollOffsets()[1];
            var halfSreenX = (document.viewport.getWidth()/2);
            var halfSreenY = (document.viewport.getHeight()/2);

            var fixedX = (halfSreenX + offsetX) - ($(element).getWidth()/2);
            var fixedY = (halfSreenY + offsetY) - ($(element).getHeight()/2);
            $(element).style.top = fixedY + 'px';
            $(element).style.left = fixedX + 'px';
        }
        return;
    },
    headerShowed: false,
    toggleHeader: function(status) {

        if(!Nashvek._sliding) {
            if(status == 'on') {
                Nashvek._sliding = true;
                Effect.BlindDown('site_settings', {
                    'afterFinish': function() {
                        Nashvek._sliding = false;
                        Nashvek.headerShowed = true;
                    }
                });
                return true;
            } else if(status == 'off') {
                Nashvek._sliding = true;
                Effect.BlindUp('site_settings', {
                    'afterFinish': function() {
                        Nashvek._sliding = false
                        Nashvek.headerShowed = false;
                    }
                });
                return true;
            }
        }
        return true;
    },
    rightBarPanelShow: 3,
    toggleRightBarPanel: function() {
        if(this.rightBarPanelShow == 3) {
            $('right-bar-panel-toggle').removeClassName('arrow_up_icon_mini');
            Effect.multiple(['right-bar-datetime', 'right-bar-weather', 'right-bar-search'], 
                Effect.SwitchOff, 
                {speed : 1.0, delay: 0.1, 'afterFinish': function() { 
                    Nashvek.rightBarPanelShow -= 1;
                    if(Nashvek.rightBarPanelShow == 0) {
                        $('right-bar-panel-toggle').addClassName('arrow_down_icon_mini');
                    }
                }}
            );
        } else if(this.rightBarPanelShow == 0) {
            $('right-bar-panel-toggle').removeClassName('arrow_down_icon_mini');
            Effect.multiple(['right-bar-datetime', 'right-bar-weather', 'right-bar-search'], 
                Effect.Appear, {speed : 1.0, delay: 0.1, 'afterFinish': function() { 
                    Nashvek.rightBarPanelShow += 1
                    if(Nashvek.rightBarPanelShow == 3) {
                        $('right-bar-panel-toggle').addClassName('arrow_up_icon_mini');
                    }
                }}
            );
        }
    }
};

var TableHighLightProto = Class.create();

TableHighLightProto.prototype = {
    mouseoverListener: '',
    mouseoutListener: '',
    element: '',
    initialize: function() {
        var td = $$('table.table thead td.sortable');
        for (var i = 0; i < td.length; ++i) {
            var el = td[i];
            if(!el.hasClassName('st_Sorted')) {
                this.addObserve(el);
            }
        }
        var bodyTd = $$('table.table tbody tr');
        for (var i = 0; i < bodyTd.length; ++i) {
            var el = bodyTd[i];
             this.addObserve(el);
        }
    },
    addObserve: function(el) {
        var mouseoverListener = this.highlight.bindAsEventListener(el, el);
        var mouseoutListener  = this.unhighlight.bindAsEventListener(el, el);
        Element.observe(el, 'mouseover', mouseoverListener, false);
        Element.observe(el, 'mouseout', mouseoutListener, false);
    },
    highlight: function(e, el) {
        Element.addClassName(el, 'over');
    },
    unhighlight: function(e, el) {
        Element.removeClassName(el, 'over');
    }
}

function respondToClick(obj) {
	$$('.tabbernav li').each(function(item) {
		item.removeClassName('tabberactive');
		});
	
	var obj = $(obj);
		
	obj.parentNode.addClassName('tabberactive');
	
	$$('.tabbertab').each(function(item){
		item.removeClassName('tabberactivetab');
		});
	
	var tabid = obj.readAttribute('href');

	//Remove # and open respective tab

	$(tabid.slice(1)).addClassName('tabberactivetab');
		
	return false;
}