var votesSlider, startsSlider, commentButtonSlider, commentFormSlider, loginSlider, joinSlider, commentsPages, commentCurrPage, pageTracker;
var tryLogin=false;
var tryJoin=false;
var so=new Object();
var errors_log=[];
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
var toJoinURL='';
window.addEvent('domready', function() {
	try{
		for(var sNombre in so){
			try{
				so[sNombre].action();
			}catch(e){}
			so[sNombre].attributes.id=sNombre+'_swf';
			swfobject.createSWF(so[sNombre].attributes, so[sNombre].params, $(sNombre));
		}
	}catch(e){
		errors_log.push(e);
	}
	try{
		votesSlider = new Fx.Slide('votes_result', {duration: 500});
		startsSlider = new Fx.Slide('do_vote', {duration: 500});
		votesSlider.show();
		startsSlider.hide();
		$$('#votes_result img').addEvent('mouseenter', function(){choiceVote()});
		$('do_vote').addEvent('mouseleave', function(){choiceVote()});
		$$('#do_vote img').addEvent('click', function(){
			var iVote=parseInt($(this).getProperty('alt'));
			sendVote(iVote);
			});
		$$('#votes_result img','#do_vote img').setStyle('cursor', 'pointer');
	}catch(e){
		errors_log.push(e);
	}
	try{
		commentButtonSlider = new Fx.Slide('showCommentForm', {duration: 500});
		commentFormSlider = new Fx.Slide('do_comment', {duration: 500});
		commentButtonSlider.show();
		commentFormSlider.hide();
		commentsPages=[];
		$$('dl.comments').each(function(oItem){
				var oTmp=new Fx.Slide(oItem, {duration: 500});
				oTmp.hide();
				commentsPages.push(oTmp);
			});
		setCommentPage(0);
	}catch(e){
		errors_log.push(e);
	}
	$$('button').each(function(oItem){
			if(oItem.getProperty('onclick')&&oItem.getProperty('type')!='button'&&oItem.getProperty('type')!='reset'){
				oItem.setProperty('type','button');
				oItem.disabled=true;
			}
		});
	try{
		$('login_usu_email').valid=validateAsEmail;
		$('login_usu_email').addEvent('keyup', validateAsEmail);
		$('login_usu_email').addEvent('keyup', function(){
				var oTmp=$('error_2');
				if(oTmp.getStyle('display')!='none')
					oTmp.setStyle('display','none');
			});
		$('login_usu_password').valid=validateAsPassword;
		$('login_usu_password').addEvent('change', validateAsPassword);
		$('login_usu_password').addEvent('keyup', function(){
				var oTmp=$('error_4');
				if(oTmp.getStyle('display')!='none')
					oTmp.setStyle('display','none');
			});
		$$('#login input').each(function(oItem){
				if(typeof(oItem.valid)=='function'){
					oItem.addEvent('keyup', function(event){
							var event = new Event(event);
							var oParent=oItem.getParent();
							tryLogin=false;
							oParent.getChildren().filterByTag('input').each(function(oItem1){
									if(typeof(oItem1.valid)=='function'){
										if(!tryLogin&&oItem1.valid())
											tryLogin=true;
										else if(!oItem1.valid())
											tryLogin=false;
									}
								});
							$('doLogin').disabled=(!tryLogin);
							if(event.key=='enter'&&tryLogin)
								sendLogin();
						});
				}
			});
		//$('newCount').setStyle('visibility','visible');
	}catch(e){
		/*errors_log.push(e);
		loginSlider = new Fx.Slide('login', {duration: 500});
		joinSlider = new Fx.Slide('singin', {duration: 500});
		loginSlider.show();
		joinSlider.hide();
		//$('newCount').setStyle('visibility','visible');
		if(!$('frmSingIn').hasChild())
			$('frmSingIn').remove();*/
	}
	try{
		$('join_usu_id').valid=sendVerify;
		$('join_usu_id').addEvent('change', sendVerify);
		$('join_usu_email').valid=validateAsEmail;
		$('join_usu_email').addEvent('change', sendVerify);
		$('join_usu_email').addEvent('keyup', validateAsEmail);
		$('join_usu_password').valid=validateAsPassword;
		$('join_usu_password').addEvent('change', validateAsPassword);
		$('join_usu_tu').valid=function(){ return this.checked; };
		$('join_usu_tu').addEvent('change', function(){
				if(this.checked)
					$('error_10').setStyle('display','none');
				else
					$('error_10').setStyle('display','block');
			});
		$('join_usu_name').valid=notNull;
		$$('#frmSingIn input').each(function(oItem){
				if(typeof(oItem.valid)=='function'){
					oItem.addEvent('change', function(event){
							var event = new Event(event);
							var oParent=oItem.getParent();
							tryJoin=false;
							oParent.getChildren().filterByTag('input').each(function(oItem1){
									if(typeof(oItem1.valid)=='function'){
										if(!tryJoin&&oItem1.valid())
											tryJoin=true;
										else if(!oItem1.valid())
											tryJoin=false;
									}
								});
							$('doJoin').disabled=(!tryJoin);
						});
					oItem.addEvent('keyup', function(event){
							var event = new Event(event);
							if(event.key=='enter'&&tryJoin)
								sendSubscription();
						});
				}
			});
		if(toJoinURL=='')
			toJoinURL=$('frmSingIn').getProperty('action');
		/*loginSlider = new Fx.Slide('login', {duration: 500});
		joinSlider = new Fx.Slide('singin', {duration: 500});
		loginSlider.show();
		joinSlider.hide();*/
	}catch(e){
		errors_log.push(e);
	}
	try{
		if(lang=='es'){
		$('welcome_message').addEvent('click', function(){
					so.oWelcome={
						params:{
							quality:"high",
							allowScriptAccess:"sameDomain"
						},
						attributes:{
							data:"/visual/img/welcome_"+lang+"_anim_CS_640x200.swf",
							width:"640",
							height:"200"
						},
						action:function(){
						}
					};
					so.oWelcome.attributes.id='welcome_swf';
					swfobject.createSWF(so.oWelcome.attributes, so.oWelcome.params, $('welcome'));
				});
		$('welcome_message').setStyle('cursor','pointer');
		}
	}catch(e){
		errors_log.push(e);
	}
	try{
		$('recover_email').addEvent('keyup', validateAsEmail);
	}catch(e){
		errors_log.push(e);
	}
	try{
		$('contact_email').addEvent('keyup', validateAsEmail);
		$('contact_email').addEvent('keyup', function(){
				$('contact_name').value=this.value;
			});
	}catch(e){
		errors_log.push(e);
	}
	$$('a.popupCaller').each(function(oItem){
		if(oItem.getProperty('target')=='_blank'){
			var oTemp=$(document.body).getCoordinates();
			var url=oItem.href.replace('html', 'popup');
			new cmPopup(oItem,{size: {
					width: oTemp.width/4,
					height: oTemp.height/4
				},
				sPosition:'rb',
				bgcolor: '#CCCCCC',
				url: url,
				sClose:'Cerrar'
			});
		}
	});
	pageTracker = _gat._getTracker("UA-3667836-1");
	pageTracker._initData();
	pageTracker._trackPageview();
});
