/*
Copyright 2011 Erick Martínez Sámano
This file is part of PHP Quick Calendar E. GNU/GPL3
*/
var transAlerts={
		en:{
			DOC_NOT_FOUND:"Document not found",
			T_W_E_P_R:"There was an error processing the request",
			P_Try_A_L:"Please try again later"
		},
		es:{
			DOC_NOT_FOUND:"Documento no encontrado",
			T_W_E_P_R:"Hubo un error al procesar su petición",
			P_Try_A_L:"Por favor, intente de nuevo más tarde"
		},
                gl:{
			DOC_NOT_FOUND:"Documento non atopado",
			T_W_E_P_R:"Produciuse un erro ao procesar a súa petición",
			P_Try_A_L:"Por favor, ténteo novamente máis tarde"
		},
		nl:{
			DOC_NOT_FOUND:"Document niet gevonden",
			T_W_E_P_R:"Er is een fout opgetreden bij het verwerken van de aanvraag",
			P_Try_A_L:"Probeert u het later nog eens"
		},
		define: function(){
		ltag=document.getElement('html').lang.substr(0,2);
		(typeof(this[ltag])=="undefined")?ltag="en":'';
		return this[ltag];
		}
};
var smallReq = new Class({
	initialize: function(container,target){
		if (typeof(target)=='undefined') {target=container;}
		target.set('tween',{onComplete:(function(){if(Browser.ie && Browser.version==7) this.style.removeAttribute('filter')}).bind(target)});
		if (Browser.ie){container.setStyle('zoom',1);}
		this.xhreq=new Request.HTML({
		onRequest: function(){
				(this.uerr)? this.uerr.setStyle('display','none'):'';
				(this.err404)? this.err404.setStyle('display','none'):'';
				(this.seErr)? this.seErr.setStyle('display','none'):'';
				target.fade('hide');
				container.addClass("QCEloader");
			},
		onComplete: function(){
				container.removeClass.delay(20,container,"QCEloader");
			},
		onFailure: function(xhr){if (xhr.status==404){
						if (!this.err404){
							this.err404=new Element('p.QCEErr#'+container.id+'9',{html:this.alerts.DOC_NOT_FOUND}); container.grab(this.err404,'top');} (this.uerr)? this.uerr.setStyle('display','none'):''; this.err404.setStyle('display','block');
						} else {
						if (!this.uerr){
							this.uerr=new Element('p.QCEErr#'+container.id+'8',{html:this.alerts.T_W_E_P_R});container.grab(this.uerr,'top');} (this.err404)? this.err404.setStyle('display','none'):'';this.uerr.setStyle('display','block');
						}
						container.fireEvent('QCEAjErr',target);
			},
		onSuccess: function(tree,elements,html,js){
				if (this.getHeader('pqce')=='t'){
					target.getChildren().destroy();
					target.set('html', html);
					target.fireEvent('QCEAjSucc');
					target.tween('opacity',1);
				}else{  if(!this.seErr){
					this.seErr=new Element('p.QCEErr#'+container.id+'7',{html:this.alerts.P_Try_A_L});
					container.grab(this.seErr,'top');}
					container.fireEvent('QCEAjErr',target);
					this.seErr.setStyle('display','block');
				}
			},
		evalScripts:false,
		link:'cancel',
		method:'get'
		});
	this.xhreq.alerts=transAlerts.define();
	},
	send: function(url,more){
		this.xhreq.options.url=url;
		this.xhreq.send(more);
	}
});
var smallShow = new Class({
	Implements: Options,
	options:{
		espacio:50,
		duracion:300,
		fps:24
	},
	initialize: function(prev,next,close,padre,options){
		this.ie= (Browser.ie)? 'quad:out':'quint:out';
		this.setOptions(options);
		this.padre=padre;
		this.prev=prev;
		this.next=next;
		this.onefx=false;
		this.padreTween=new Fx.Tween(padre,{property:'opacity', duration:2000,transition:this.ie,link:'cancel',onComplete: (function(){
			if (!this.padre.getStyle('opacity').toInt()){this.padre.setStyle('display','none');this.prev.setStyle('visibility','hidden');}
							}).bind(this)
				});
		if(!(Browser.ie && Browser.version<9)){
			this.padre.addEvent('mouseleave',this.ocultar.bind(this));
			this.padre.addEvent('mouseenter',this.mostrar.bind(this));
		}
		close.addEvent('click',function(){
			padre.setStyles({'display':'none','opacity':0});
			prev.setStyle('visibility','hidden');
			next.setStyle('visibility','hidden');
			if(Browser.ie && Browser.version<9){
				document.id('pqceIEBan3').setStyle('display','none');
			}
		});
		prev.addEvent('click',this.back.bind(this));
		next.addEvent('click',this.forw.bind(this));

	},
	scan: function(target){
		this.onefx=false;
		/*fix for ajax delays*/
			this.prev.setStyle('visibility','hidden');
			this.next.setStyle('visibility','hidden');
		/**/
		this.children=target.getChildren('div');
		this.last=this.children.length-1;
		if (this.last<2){return;}
			this.next.setStyle('visibility','visible');
			this.tween= new Fx.Tween(target,{property:'left', duration:this.options.duracion,transition:this.ie,fps:this.options.fps});
			this.left=this.children[0].getSize().x;
			this.target=target;
			this.visibleChild=0;
	},
	forw: function(){
		if (this.last<2){return;}
		if (this.onefx){return;}
		this.onefx=true;
		this.target.setStyle('width','220%');
		this.children[this.visibleChild+2].setStyle('display','block');
		this.tween.start(0,-(this.left + this.options.espacio)).chain((function(){
		this.children[this.visibleChild].setStyle('display','none');
		this.children[(this.visibleChild+1)].setStyle('display','none');
		this.target.setStyle('width','100%');
		this.tween.set(0);
		this.prev.setStyle('visibility','visible');
		this.visibleChild+=2;
		this.onefx=false;
		if (this.last==this.visibleChild) {this.next.setStyle('visibility','hidden');}
		}).bind(this));
		
	},
	back: function(){
		if (this.last<2){return;}
		if (this.onefx){return;}
		this.onefx=true;
		this.target.setStyle('width','220%');
		this.children[(this.visibleChild-1)].setStyle('display','block');
		this.children[(this.visibleChild-2)].setStyle('display','block');
		this.tween.set(-(this.options.espacio+this.left));
		this.tween.start(0).chain((function(){
		this.next.setStyle('visibility','visible');
		this.target.setStyle('width','100%');
		this.children[this.visibleChild].setStyle('display','none');
		this.visibleChild-=2;
		this.onefx=false;
		if (this.visibleChild==0) {this.prev.setStyle('visibility','hidden');}
		}).bind(this));		
	},
	ocultar: function(){
		if(this.padre.hasClass("QCEloader")){return;}
		this.timer=this.padreTween.start.delay(10000,this.padreTween,0);
	},
	mostrar: function(){
		clearTimeout(this.timer);
		this.padreTween.start(1);
	}
});

window.addEvent('domready',function(){
	var ie7=Browser.ie && Browser.version==7,ie8=Browser.ie && Browser.version==8;
	var el=document.id("QCEsmalltrgt"),target= document.id('smallQCEtrgt'),target1= document.id('smallSmooth');
if (ie7||ie8){
	var e=document.id('isQCEsmall');
	var z=target.getStyle('z-index'),w=target.getStyle('width'),h=target.getStyle('height');
	var IEBan=new Element('div#pqceIEBan3',{style:'width:'+w+';height:'+h+';z-index:'+(z-1)});
	IEBan.setStyle('z-index',z-1);
	target.setStyle('visibility','hidden').setStyle('display','block');
	e.grab(IEBan);
	IEBan.position({position:{x: 'left', y: 'top'},relativeTo:target,offset:{x:-5,y:-5}});
	//offset.y=-strength 0;offset.x=-strength 270
	target.setStyle('display','none').setStyle('visibility','visible');
	z=null;w=null;h=null;e=null;
}
	var qs=document.id('QCEsmall'),sa=document.id("smallQCEa"),ss=document.id("smallQCEs");
	var smallQCEreq= new smallReq(qs,el);
	if (ie8||ie7){
		twn=window.smallQCETween= new smallShow(sa,ss,document.id("smallQCEc"),target,{duracion:1000,fps:24});}else{
		var twn= new smallShow(document.id("smallQCEa"),document.id("smallQCEs"),document.id("smallQCEc"),target,{duracion:1000,fps:24});
	}
	el.addEvent('click:relay(.Apqcejx)',function(e){
		e.preventDefault();
		smallQCEreq.xhreq.cancel();
		if(ie7||ie8){
			IEBan.setStyle('display','none');
		}
		target.setStyle('display','none');target1.setStyle('opacity',0);
		pqceHideArr();
		smallQCEreq.send(this.href,'view=small&format=raw');
	});
	var smallQCEreqB= new smallReq(target,target1);
	el.addEvent('click:relay(.pQCEsmall)',function(e){
		e.preventDefault();
		smallQCEreqB.xhreq.cancel();
		pqceHideArr();
		target.setStyles({'display':'block','visibility':'visible','opacity':1});
		if(ie7){target.style.removeAttribute('filter');}
		if(ie7||ie8){
			IEBan.setStyle('display','block');
		}
		clearTimeout(twn.timer);
		twn.padreTween.cancel();
		(twn.onefx)?twn.tween.cancel():'';
		smallQCEreqB.send(this.href,'view=small&format=raw&p=desc');
	});
	function pqceHideArr(){
		sa.setStyle('visibility','hidden');
		ss.setStyle('visibility','hidden');
	}
if (!(ie7||ie8)){
	target.addEvent('QCEAjErr',function(el){
		el.setStyle('visibility','hidden');
		pqceHideArr();
	});
	target1.addEvent('QCEAjSucc',function(){
		twn.scan(document.id("smallQCEconMainFix"));
	});
	qs.addEvent('QCEAjErr',function(el){
		el.tween('opacity',1,1);
	});
}
	el=null,qs=null;
});
if (Browser.ie && (Browser.version==8||Browser.version==7)){
window.addEvent('domready',function(){
	var target= document.id('smallQCEtrgt'),target1= document.id('smallSmooth');
	document.id('smallQCEtrgt').addEvent('QCEAjErr',function(el){
		el.setStyle('visibility','hidden');
		pqceHideArr();
	});
	document.id('smallSmooth').addEvent('QCEAjSucc',function(){
		window.smallQCETween.scan(document.id("smallQCEconMainFix"));
	});
	document.id('QCEsmall').addEvent('QCEAjErr',function(el){
		el.tween('opacity',1,1);
	});
});
}

