Pollastre_Element=function (element){
	var el2=element;
	this.mElement=document.getElementById(element);
	this.mElement2=element;

	var els=document.getElementsByTagName("*");
	for (var i=0;i<els.length;i++){
		if (els[i]==el2){
			this.mElement3=els[i];
			break;
		}
	}

};

Pollastre_Element.prototype={
	mElement:0,
	mElement2:0,
	mElement3:0,
	_ajaxScripts:0,
	_initHeight:0,
	_initWidth:0,
	_animationStack:new Array(),
	_animationInterval:0,
	_animationTime:0,
	_animationTotalTime:0,
	_animationInitParams:0,
	_HoverClass:0,
	_ClassName:0,
	
	_getElement:function(){
		if (this.mElement)return this.mElement;

		if (this.mElement2!=window && this.mElement2!=document){
			return this.mElement3;
		}
		return this.mElement2;
	},
	
	addEvent:function(eventName,func){
		if (window.addEventListener)
			this._getElement().addEventListener(eventName,func,false);
		else
			this._getElement().attachEvent("on"+eventName,func);

	},
	setHoverClass:function(className,otherClasses){

	this._HoverClass=className;
		this._ClassName=otherClasses;
		var pthis=this;
		this.addEvent("mouseover",function(){pthis._getElement().className=pthis._HoverClass+" "+pthis._HoverClass+"_hover"+pthis._ClassName});
		this.addEvent("mouseout",function(){pthis._getElement().className=pthis._HoverClass+pthis._ClassName});
		this._getElement().className=this._HoverClass+this._ClassName;
	},

	detectDimensions:function(){
		this._initHeight=this.getHeight();
		this._initHeight=this.getWidth();
	},
	
	getWidth:function(){
		if (this._getElement()==document || this._getElement()==window || this._getElement()==document.getElementsByTagName("body")[0]){
			if (window.innerWidth)return window.innerWidth;
			if (document.documentElement.clientWidth)return document.documentElement.clientWidth;
			return document.body.clientWidth;
		}
		return this._getElement().offsetWidth;
	},

	getHeight:function(){
		if (this._getElement()==document || this._getElement()==window || this._getElement()==document.getElementsByTagName("body")[0]){
			if (window.innerHeight)return window.innerHeight;
			if (document.documentElement.clientHeight)return document.documentElement.clientHeight;
			return document.body.clientHeight;
		}
		return this._getElement().offsetHeight;
	},
	
	getInitWidth:function(){
		return _initHeight;
	},
	
	getInitHeight:function(){
		return _initWidth;
	},
	_animationSetInitParams:function(){
		this._animationInitParams={
			height:this.getHeight(),
			width:this.getWidth()
		};
		this._animationTotalTime=0;
		this._animationTime=new Date();
		this._animationTime=this._animationTime.getTime();
	},
	setAnimation:function(parameters,miliseconds,func){
		var pthis=this;
		if (this._animationInterval)clearInterval(this.animationInterval);
		this._animationStack=new Array();
		this.addAnimation(parameters,miliseconds*10,func);
		this._animationSetInitParams();
		this._animationInterval=setInterval(function(){pthis._processAnimations();},30);
	},
	addAnimation:function(parameters,miliseconds,funct){
		this._animationStack[this._animationStack.length]={params:parameters,time:miliseconds,func:funct};
	},

	_processAnimations:function(){
		if (!this._animationStack.length){
			clearInterval(this._animationInterval);
			this._animationInterval=0;
			return;
		}
		var animation=this._animationStack[0];
		var time=new Date();
		time=time.getTime()-this._animationTime;
		this._animationTotalTime+=time;
		time=this._animationTotalTime;
		try{
			if (animation.params.height){
				var maxStep=animation.params.height-this._animationInitParams.height;
				this._getElement().style.height=parseInt(this._animationInitParams.height+maxStep*time/animation.time)+"px";
			}
			if (animation.params.width){
				var maxStep=animation.params.width-this._animationInitParams.width;
				this._getElement().style.width=parseInt(this._animationInitParams.width+maxStep*time/animation.time)+"px";
			}
		}catch(e){}
		if (time>=animation.time){
			if (animation.params.height){
				this._getElement().style.height=parseInt(animation.params.height)+"px";
			}
			if (animation.params.width){
				this._getElement().style.width=parseInt(animation.params.width)+"px";
			}
			if (animation.func)animation.func();
			var tmpArray=new Array();
			for (var i=1,len=this._animationStack.length;i<len;i++){
				tmpArray[i-1]=this._animationStack[i];
			}
			this._animationStack=tmpArray;
			this._animationSetInitParams();
		}
	},
	
	ajax:function(page,params,func){
		var xmlhttp;
		if (window.XMLHttpRequest) {
			// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			// code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}else{
			alert("Your browser does not support XMLHTTP!");
			xmlhttp=0;
		}

		var pthis=this;
		xmlhttp.onreadystatechange=function(){
			if(xmlhttp.readyState==4){
				pthis._getElement().innerHTML=xmlhttp.responseText;
				if (pthis._ajaxScripts){
					for(var i=0,len=pthis._ajaxScripts.length;i<len;i++)document.getElementsByTagName("head")[0].removeChild(pthis._ajaxScripts[i]);
				}
				pthis._ajaxScripts=0;
				var els=pthis._getElement().getElementsByTagName("script");
				if (els.length){
					pthis._ajaxScripts=new Array();
					for(var i=0;i<els.length;i++){	
						var script=document.createElement("script");
						script.setAttribute("type",'text/javascript');
						script.text=els[i].text;
						document.getElementsByTagName("head")[0].appendChild(script);
						pthis._ajaxScripts[pthis._ajaxScripts.length]=script;
					}
				}
				Pollastre_detectHoverClass();
				if (func) func(pthis,xmlhttp.responseText);
			}
		}
		
		if (xmlhttp){
			xmlhttp.open("POST",page,true);
			xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlhttp.setRequestHeader("Content-length", params.length);
			xmlhttp.setRequestHeader("Connection", "close");
			xmlhttp.send(params);
		}
	}
};


var Pollastre_getElementArray=new Array();

function Pollastre_getElement(element){
	var p=new Pollastre_Element(element);
	for (var i=0,len=Pollastre_getElementArray.length;i<len;i++)if (Pollastre_getElementArray[i].mElement==p._getElement())return Pollastre_getElementArray[i];
	Pollastre_getElementArray[i]=p;
	return Pollastre_getElementArray[i];
}

function Pollastre_detectHoverClass(){
	var types=new Array("div","span","table","tr","td","img","a");
	for(var t=0;t<types.length;t++){
		var elements=document.getElementsByTagName(types[t]);
		for (var i=0;i<elements.length;i++){
			var clas=elements[i].className;
			clas=clas.split(" ");
			if (clas[0]=="CHover"){
				var oc="";
				for(var j=2;j<clas.length;j++)oc+=" "+clas[j];
				Pollastre_getElement(elements[i]).setHoverClass(clas[1],oc);
			}
		}
	}
}


Pollastre_getElement(window).addEvent("load",Pollastre_detectHoverClass);

