window.addEvent('domready', function() { 
	if (isset($('la_he_visto'))){
		$('la_he_visto').addEvent('click', function(event) {  
			if ($('la_he_visto').get('rel')!='vista') {
				//prevent the page from changing  
				 event.stop();  
				 //make the ajax call  
				 var req = new Request({  
					 method: 'get',  
					 url: 'http://www.videoclubmadison.com/peliculas_vistas.php',  
					 data: { 'pelicula' : $('la_he_visto').get('rel') }, 
					 onRequest: function() { $('la_he_visto').set('text', 'cargando...') },  
					 onComplete: function(response) { 
						 $('la_he_visto').set('text', 'Confirmado'); 
						 $('la_he_visto').set('rel', 'vista');
						 Growl.Smoke({
							title: 'Informaci&oacute;n',
							text: 'Nueva pel&iacute;cula a&ntilde;adida',
							image: 'http://www.videoclubmadison.com/img/usuarios/la_he_visto.jpg',
							duration: 3
						});
						 return false;
					 }  
				 }).send();  
			}
		}); 
	}
/* rating */
if (isset($('votaciones'))){
	
		$$('.rate').each(function(element,i){
				element.addEvent('click', function(event){
					if ($('pelicula_votada').get('value')=='no') {			
						var myStyles = ['nostar', 'onestar', 'twostar', 'threestar', 'fourstar', 'fivestar', 'sixstar', 'sevenstar', 'eightstar', 'ninestar', 'tenstar'];
						myStyles.each(function(myStyle){
								if(element.getParent().hasClass(myStyle)){
										element.getParent().removeClass(myStyle)
								}
						});            
						myStyles.each(function(myStyle, index){
								if(index == element.id){
										element.getParent().toggleClass(myStyle);
													   event.stop();  
										 //make the ajax call  
										 var req = new Request({  
											 method: 'post',  
											 url: 'http://www.videoclubmadison.com/votos.php',  
											 data: { 'id' : $('pelicula_id').get('value'), 'votos' : element.id  }, 
											 onComplete: function(response) { 
												 Growl.Smoke({
													title: 'Informaci&oacute;n',
													text: 'Le has dado '+element.id+' votos a '+$('pelicula_titulo').get('value'),
													image: 'http://www.videoclubmadison.com/img/usuarios/confirmada.jpg',
													duration: 3
												});
												 $('pelicula_votada').set('value','si');
												 $('votada').set('html', 'Has votado');
												 return false;
											 }  
										 }).send();  
								}
						});            
					}
				});
			});
}
/*fin*/
});  

function isset(variable_name) {
    try {
         if (typeof(eval(variable_name)) != 'undefined')
         if (eval(variable_name) != null)
         return true;
     } catch(e) { }
    return false;
   }
