// powered by ROTFL & LOL
var jso={
	gI:function(a,b){
		// get Element by ID
		b=b||document;
		return b.getElementById(a)
	},
	gT:function(a,b,i){
		// get Elements by Tag Name
		b=b||document;
		b=b.getElementsByTagName(a)
		a=[]
		for(i=0;i<b.length;i++)a[a.length]=b[i];
		return a
	},
	gAV:function(a,b,c,d,i){
		// get Elements by Atribute [+ Value]
		a=a||"*";
		b=b||document;
		if(!c)return false;
		b=b.getElementsByTagName(a)
		a=[]
		for(i=0;i<b.length;i++)if(b[i][c]&&(!d||(b[i][c].match(new RegExp('(^| )'+d+'($| )','gi'))!=null)))a[a.length]=b[i];;
		return a
	},
	cE:function(a,b,c,d,e,i){
		// create Element
		a=document.createElement(a)
		if(b)for(i in b)a[i]=b[i];;
		if(c)for(i in c)a.appendChild(c[i].nodeType?c[i]:document.createTextNode(c[i]));;
		if(e)for(i in e)jso.aE(a,i,e[i]);;
		if(d)d.appendChild(a);
		return a
	},
	gE:function(x){
		// get Element from Event
		x=x||window.event;
		x=x.target||x.srcElement;
		if(x.nodeType==3)x=x.parentNode;
		return x
	},
	aE:function(O,E,F){
		// add Event to Element
		return(O.x=O.addEventListener)?O.x(E,F,0):(O.x=O.attachEvent)?O.x('on'+E,F):!1;
	},
	rE:function(O,E,F){
		// remove  Event from Element
		return(O.x=O.removeEventListener)?O.x(E,F,0):(O.x=O.detachEvent)?O.x('on'+E,F):!1;
	},
	sE:function(e){
		e = e||event
		if(e.preventDefault)
			e.preventDefault();
		e.returnValue=false
		return false
	},
	sO:function(a,b){
		// set Opacity
		if(jso.ie)
			a.style.filter='alpha(opacity='+(100*b)+')';
		else
			a.style.opacity = b;
	},
	ie:false
}
/*@cc_on @if(@_jscript) jso.ie=true @end @*/
// srajax
jso.ajax = function(params)
{
	var T = this
	for(var i in params)
		this[i]=params[i];
	this.ajax = false
	if (window.XMLHttpRequest)
		this.ajax = new XMLHttpRequest();
	else
		this.ajax = new ActiveXObject("Microsoft.XMLHTTP");
	if (this.ajax)
	{
		if(this.onend)
			this.ajax.onreadystatechange=function(){if(T.ajax.readyState==4)T.onend(T.ajax);};
		this.method=this.method?this.method.toUpperCase():'GET';
		this.uri=this.uri||'';
		this.postData=this.postData?this.postData:null;
		this.ajax.open(this.method,this.uri, true);
		if (this.method == 'POST')
			this.ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		this.ajax.send(this.postData)
		this.ok = true
	}
	else
	{
		this.ok = false
	}
}

// my...box
jso.myBox=function(params)
{
	var T = this
	for(var i in params)
		this[i]=params[i];
	if(this.insertInto === undefined)
		this.insertInto=document.body;

	this.images=[]
	this.previousImage=false
	this.currentImage=false
	this.nextImage=false
	this.newImage=false
	this.domElement=jso.cE('div',{className:'myBox'},[jso.cE('div',{className:'myBoxOverlay'})])

	this.domNavigation=jso.cE('ul',{className:'myBoxNavigation'},[
		jso.cE('li',{className:'myBoxPrevious'},[
			jso.cE('a',{href:'#previousImage',onclick:function(){T.showImage.call(T,T.previousImage);return false}})
		]),
		jso.cE('li',{className:'myBoxNext'},[
			jso.cE('a',{href:'#nextImage',onclick:function(){T.showImage.call(T,T.nextImage);return false}})
		])
	])
	this.domCount=jso.cE('p',{className:'myBoxCount'},[''])
	this.domClose=jso.cE('p',{className:'myBoxClose',onclick:function(){T.closeMyBox.call(T)}},[i18n.close])

	jso.aE(window,'resize',function(){T.recalcMyBox.call(T)})
}
jso.myBox.prototype.addImage=function(params)
{
	var T=this
	var domAnachor = params.domAnachor?params.domAnachor:false
	var title = params.title?params.title:(domAnachor?domAnachor.title:false)
	var src = params.src?params.src:(domAnachor?domAnachor.href:false)
	var add = true;
	if(!src)
		return;
	var image = new this.image({title:title,src:src})
	for(var i in this.images)
	{
		if(this.images[i].src==image.src)
		{
			image=this.images[i]
			add=false
		}
	}
	if(add)
		this.images[this.images.length]=image;
	if(domAnachor)
		domAnachor.onclick = function(e){T.showImage.call(T,image);return false};
}
jso.myBox.prototype.recalcMyBox=function()
{
	if(this.domElement.parentNode==this.insertInto)
	{
		if(this.currentImage)
		{
			var html = document.body.parentNode
			this.width=(html.clientWidth > html.scrollWidth ? html.clientWidth : html.scrollWidth)
			this.height=(html.clientHeight > html.scrollHeight ? html.clientHeight : html.scrollHeight)
			if(this.currentImage.load && this.height < this.currentImage.height + 100)
				this.height = this.currentImage.height + 100;
			this.domElement.style.width=this.width+'px'
			this.domElement.style.height=this.height+'px'
			if(this.currentImage.load)
			{
				var top = (html.clientHeight - this.currentImage.height - 75)
				if(top > 0)
					top = top / 2;
				top = top + html.scrollTop > 10 ? top + html.scrollTop : 10;
				this.currentImage.domElement.style.visibility = "visible"
				this.currentImage.domElement.style.left = Math.ceil((this.width - this.currentImage.width) / 2) + 'px';
				this.currentImage.domElement.style.top = Math.ceil( top ) + 'px';
				this.domNavigation.style.width=this.currentImage.width+'px';
				this.domNavigation.style.height=this.currentImage.height+'px';
				this.domElement.className = 'myBox'+(this.previousImage?' myBoxPrevious':'')+(this.nextImage?' myBoxNext':'')+(this.images.length>1?' myBoxCount':'')
			}
			else
			{
				var T = this
				this.currentImage.checkLoad.call(this.currentImage,function(){T.recalcMyBox.call(T)})
			}
		}
		else
		{
			this.closeMyBox.call(this)
		}
	}
}
jso.myBox.prototype.showMyBox=function()
{
	document.body.className = document.body.className.replace(/ ?hide_flash/ig,'') + ' hide_flash';
	this.insertInto.appendChild(this.domElement)
	this.newImage.domElement.appendChild(this.domNavigation)
	this.newImage.domElement.insertBefore(this.domCount,this.newImage.domImageConteiner)
	this.newImage.domElement.insertBefore(this.domClose,this.newImage.domImageConteiner)
	if(this.currentImage)
		this.domElement.replaceChild(this.newImage.domElement,this.currentImage.domElement);
	else
		this.domElement.appendChild(this.newImage.domElement);
	this.currentImage = this.newImage
	this.recalcMyBox.call(this)
}
jso.myBox.prototype.showImage=function(image){
	for(var i=0;i<this.images.length;i++)
	{
		if(this.images[i] == image)
		{
			this.previousImage=this.images[i-1];
			this.nextImage=this.images[i+1];
			this.newImage=image
			this.domCount.firstChild.nodeValue = (i+1)+' '+i18n.from+' '+this.images.length;
		}
	}
	if(this.newImage)
		this.showMyBox.call(this);
}
jso.myBox.prototype.closeMyBox=function(){
	this.insertInto.removeChild(this.domElement)
	if(this.currentImage)
	{
		this.domElement.removeChild(this.currentImage.domElement);
		this.currentImage.domElement.removeChild(this.domNavigation)
		this.currentImage.domElement.removeChild(this.domCount)
		this.currentImage.domElement.removeChild(this.domClose)
	}
	this.previousImage=false
	this.currentImage=false
	this.nextImage=false
	this.newImage=false
	document.body.className = document.body.className.replace(/ ?hide_flash/ig,'')
}
jso.myBox.prototype.image=function(params){
	for(var i in params)
		this[i]=params[i];
	this.load=false
	this.interval=false
	var T = this
	this.domElement=jso.cE('div',{className:'myBoxContainer'})
	this.domTitle=this.title?jso.cE('p',{className:'myBoxTitle'},[this.title],this.domElement):false;
	this.domImageConteiner = jso.cE('div',{className:'myBoxImage'},[this.domImage=jso.cE('img',{src:this.src,onload:function(){T.load=false;T.checkLoad.call(T)}})],this.domElement)
}
jso.myBox.prototype.image.prototype.checkLoad=function(onload){
	if(onload)
		this.onload = onload;
	if(!this.load)
	{
		var T = this;
		if(this.domImage.width||this.domImage.height)
		{
			this.width = this.domImage.width
			this.height = this.domImage.height
			this.width = this.width < 300 ? 300 : this.width;
			this.domElement.style.width = this.width+"px"
			this.domImageConteiner.width = this.width+"px"
			this.load = true
			if(this.interval)
				window.clearInterval(this.interval);
			this.interval = false;
		}
		else if(!this.interval)
		{
			this.interval = window.setInterval(function(){T.checkLoad.call(T)},25);
		}
	}
	if(this.load && this.onload)
		this.onload();
}
