﻿//loaders

var Loader = Class.create();
Loader.prototype = {
	initialize: function(element, cssStyle, url, parameters, form, goodEnd){
		this.goodEnd = goodEnd || null;
		this.clearForm = form || null;
		this.url = url;
		this.parameters = parameters;
		//this.loader = $('loader');
		this.loader=$(element);
		this.request();
	},
	request: function(){
		new Ajax.Request(this.url, {method: 'post', postBody: this.parameters, onComplete: this.check.bind(this) });
		return false;
	},
	check: function(request){
		var response = request.responseText;
		var res = response.split("-__-");
		
		if(res.length == 2){
			var err_type = res[0];
			var err_msg = res[1];
		}
		else{
			if (this.loader.id=='loader'){
				this.loader.innerHTML = response;
				if ($('wrapperex')) $('wrapperex').id='wrapperex2';
			} else {
				this.loader.innerHTML = response;
			}
		}		
		this.end();
	},

	reset: function(){
		this.loader.className = "";
		this.loader.parentNode.className = "";
	},

	end: function(){
		if ($('backgrounds')) Attitude.update(bgrImgRules);
		if ($('pagination')) Attitude.update(pagingRules);
		if (!$('backgrounds')) $('flgcnt').style.height=windowHeight()-137+'px';
	}
};

function windowHeight() {
	if (document.documentElement && document.documentElement.clientHeight) return document.documentElement.clientHeight;
	else return 0;
}



function windowResize(){
	if ($('wrapperex2')) {
		$('flgcnt').style.height=windowHeight()-137+'px';
	}
}

var Addition = Class.create();
Addition.prototype = {
	setOptions: function(options) {
		this.options = {
			onComplete:	''
		},

		Object.extend(this.options, options || {});
	},

	initialize: function(element, html, container, options){
		container = $(container);
		this.setOptions(options);
		if (container.childNodes[0] && !this.options.onBottom)
			//var newElement = container.insertBefore(document.createElement(element), container.childNodes[0]);
			var newElement = Element.add(container, element, {onBottom : false});
		else
			//var newElement = container.appendChild(document.createElement(element));
			var newElement = Element.add(container, element, {onBottom : true});
		if (this.options.cssStyle) Element.addClassName(newElement, this.options.cssStyle);
		
		//var fader = new fx.FadeSize(newElement, {duration: 400, onComplete: this.options.onComplete });
		fader.hide('height');
		newElement.innerHTML = html;
		//fader.toggle('height');
	}
};
