// JavaScript Document
merlin={};
merlin.fontes={
	small:function(obj){
		eln = $(obj).style.fontSize.substr(0,2);
		if(eln > 10) {
			$(obj).style.fontSize = --eln+"px";
		}
	},
	big:function(obj){
		eln = $(obj).style.fontSize.substr(0,2);
		if(eln < 20) {
			$(obj).style.fontSize = ++eln+"px";
		}
	}
};
cineworld={};
barras=function(){};
cineworld.bars=Class.create();
cineworld.bars.prototype=Object.extend(new barras(),{
	_cresce: function(t, ele){
		if (t < this[ele.barra]) 
			return;
		if (ele.barra == 'sidebar2') {
			this._bar2(t);
		}
		else {
			//tamanho a crescer
			tc = t - this[ele.barra];
			
			//tamanho baixo
			tb = $(ele.div).scrollHeight;
			//tamanhos de bordas, margins e etc que devem ser desconsideradas.
			desconto = 0;
			desconto = (ele.barra == 'sidebar1') ? 25 : 0;
			desconto = (ele.barra == 'sidebar4') ? 45 : desconto;
			desconto = (ele.barra == 'sidebar3') ? 11 : desconto;
			tf = tb + tc - desconto;
			new Fx.Style($(ele.div), 'height').set(tf);
		}
	},
	_bar2: function(t){
		if (t < this.sidebar2) 
			return;
		//tamanho a crescer
		tc = t - this.sidebar2;
		//tamanho baixo
		tb = $('b2Baixo1').style.height.substr(0,2);
		
		this._equalsC2(tb + tc);
	},
	_equalsC2: function(){
		vlr= this._equalsC2.arguments[0];
		var tb1, tb2;
		tb1 = $('b2Baixo1').scrollHeight;
		tb2 = $('b2Baixo2').scrollHeight;
		tamF = (tb1 > tb2) ? tb1 : tb2;
		tamF = (vlr == null) ? tamF : vlr;
		if (tamF > 300) return;
		new Fx.Style('b2Baixo1', 'height').set(tamF);
		new Fx.Style('b2Baixo2', 'height').set(tamF);
		
		this.alturaC2=tamF;
	},
	
	initialize: function(){
		this.sidebar1 = $('sidebar1').scrollHeight;
		this.sidebar2 = $('sidebar2').scrollHeight;
		this.sidebar3 = $('sidebar3').scrollHeight;
		this.sidebar4 = $('sidebar4').scrollHeight;

		this._equalsC2();
		
		big = (this.sidebar1 > this.sidebar2) ? 'sidebar1' : 'sidebar2';
		big = (this[big] > this.sidebar3) ? big : 'sidebar3';
		big = (this[big] > this.sidebar4) ? big : 'sidebar4';
		this._cresce(this[big], {barra:'sidebar1',div:'b1Baixo'});
		this._cresce(this[big], {barra:'sidebar2',div:''});
		this._cresce(this[big], {barra:'sidebar3',div:'b3Baixo'});
		this._cresce(this[big], {barra:'sidebar4',div:'b4Baixo'});
		if(Prototype.Browser.IE){
			this._equalsC2(parseInt(this.alturaC2)+6);
		}else{
			this._equalsC2();
		}		
	}
});

cineworld.novidades=Class.create();
cineworld.novidades.prototype={
	initialize: function(){
		if(Prototype.Browser.IE)
		document.getElementsByClassName("novidades").each(function(nov){
			Event.observe(nov, "mouseover", function(evt){
				var el = Event.findElement(evt, "p");
				Element.addClassName(el,"hover");
			});
			Event.observe(nov, "mouseout", function(evt){
				var el = Event.findElement(evt, "p");
				Element.removeClassName(el,"hover");
			});
		});
	}
}

function noticia(id){
	if(document.notPrev!=id){
		Element.show($('not'+id));
		Element.hide($('not'+document.notPrev));
		Element.addClassName($('lnkNot'+id),"active");
		Element.removeClassName($('lnkNot'+document.notPrev),"active");
	}
	document.notPrev=id;
}
Event.observe(window,'load',function() {
	if($("showComents")){
		document.comentsFX= new fx.Height($("coments"),{duration: 750});
		document.comentsFX.toggle();
		Event.observe($("showComents"),"click",function (){
			document.comentsFX.toggle();
			return false;
		});
	}
	if($("sidebar4")){
		document.notPrev=1;
		new cineworld.bars();
		new cineworld.novidades();
	}
	//fade();
});

/*function fade(){
	if(atual == 0){
		atual = 1;
		noticia(atual);
	} else {
		ant = atual;
		atual+=1;
		if(atual > tot){
			atual = 1;
			ant = tot;
		}
		noticia(atual);
	}
	f = setTimeout("fade()",10000);
}*/