var resetUI = function() {
	if (__MAINSLIDER) __MAINSLIDER.morphCurrent();
	if (__APPSQARIAH) {
		__APPSQARIAH.morphCurrent();
		__APPSQARIAH.resetUI();
	}
	
	if ($(window).getScrollSize().y > ($(window).getSize().y + 40)) {
		$('anchor_to_top_page').setStyle('display','');
		$('span_to_top_page').setStyle('display','');
	}
	else {
		$('anchor_to_top_page').setStyle('display','none');
		$('span_to_top_page').setStyle('display','none');
	}
	
	$('anchor_to_top_page').addEvent('click', function() { __SCROLLER.toTop(); });

	var intwindowheight = $(window).getSize().y - $('hd').getDimensions({computeSize :true}).totalHeight;
	var intbdheight = $('bd').getComputedSize().totalHeight;//.getDimensions({computeSize :true}).totalHeight;
	var intpaddinghheight = $('content').getComputedSize().computedTop + $('content').getComputedSize().computedBottom;

	if (intwindowheight > intbdheight) {
		$('content').setStyle('min-height',intwindowheight - $('footer').getDimensions({computeSize :true}).totalHeight - intpaddinghheight - 1);
	}
}

var QuickLoginForm = new Class({
	Implements: [Options,Events],
	options: {
		speed: 700
	},
	initialize: function(form, button, options) {
		this.setOptions(options);
		this.button = $(button);
		this.form = $(form);
		this.shown = false;
		
		var intLeft = this.button.getCoordinates().left - this.form.getParent().getDimensions({computeSize:true}).width + this.button.getCoordinates().width;
		var intTop = this.button.getCoordinates().top + this.button.getCoordinates().height + 1;
		this.form.getParent().setStyles({top:intTop,left:intLeft,display:'block'});

		this.form.set('slide', 
			{
				duration:this.options.speed, 
				onComplete: function() { 
				}.bind(this) 
			});
		this.form.slide('hide');
		
		this.button.addEvent('click',
			function(e) {
				this.form.get('slide').toggle();
			}.bind(this)
		);
		window.addEvent('keypress', 
			function(e) { 
				if (e.key == 'esc') 
					if (this.form.get('slide').open) this.form.slide('out');
			}.bind(this)
		); 
		
		$(document.body).addEvent('click', 
			function(e) {
				if(!$(e.target).getParent('#' + this.form.get('id'))) { 
					if (this.form.get('slide').open) {
						this.form.slide('out');
					}
				}
			}.bind(this)
		); 

		this.fxbutton = new Fx.Tween(this.button, {property: 'background-color',duration: this.options.speed });
	},
	show: function() {
		return this;
	},
	hide: function() {
		return this;
	}
});

var QariahMenu = new Class({   
	Implements: [Events, Options],
	options: {
		bg: { 'class': 'background', 'html': '<div class="inner"></div>' },
		morph: { 'link': 'cancel' }
	},
	initialize: function(menu, options) {
		var _this = this;
		this.setOptions(options);
		this.menu = $(menu);
		
		if (!this.menu) return;
		//console.log(this.menu);
		this.menuitems = this.menu.getChildren();
		
		this.items = this.menuitems.addEvents({
			mouseenter: function(){ _this.morphTo(this); },
			mouseleave: function(){ _this.morphTo(_this.current); },
			click: function(ev){ _this.click(ev, this); }
		});
		
		this.bg = new Element('li', this.options.bg).inject(this.menu).fade('hide').set('morph', this.options.morph);
		this.setCurrent(this.menu.getElement('.current'));
	},
	click: function(ev, item) {
		this.setCurrent(item, true);
		this.fireEvent('click', [ev, item]);
	},
	morphCurrent: function() {
		if (! this.current) return false; 
		this.morphTo(this.current);
	},
	setCurrent: function(el, effect){  
		if (el && ! this.current) {
			//this.bg.morph({ left: el.getPosition().x, top: el.getPosition().y, width: el.getCoordinates().width, height: el.getCoordinates().height });
			this.bg.set('styles', { left: el.getPosition().x, width: el.offsetWidth, height: el.offsetHeight, top: el.getPosition().y });
			//this.bg.set('styles', { left: el.offsetLeft, width: el.offsetWidth, height: el.offsetHeight, top: el.offsetTop });
			(effect) ? this.bg.fade('in') : this.bg.fade('show');
		}
		if (this.current) this.current.removeClass('current');
		if (el) this.current = el.addClass('current');    
		return this;
	},
	morphTo: function(to) {
		if (! this.current) return false; 
		this.bg.morph({ left: to.getPosition().x, top: to.getPosition().y, width: to.getCoordinates().width, height: to.getCoordinates().height });
		//this.bg.morph({ left: to.getPosition().x, top: getPosition().y, width: to.offsetWidth, height: to.offsetHeight });
		//this.bg.morph({ left: to.offsetLeft, top: to.offsetTop, width: to.offsetWidth, height: to.offsetHeight });
		this.fireEvent('morph', to);
		return this;
	}
});
