/**
* Marcelo G
* 201152
**/
var noticiasVot = new Class({
    Implements: [Options, Events]
    
    , options: {
        elementDesc: 'a.btn-not-votacion'
        ,urlRequest: 'modulos/noticias/noticias.registrarvoto.php'
    }
    
    , initialize : function(options){
        this.setOptions(options);
        
        var elements = $$(this.options.elementDesc);
        if(elements==null)
            return;
        elements.each(function(el){
            el.href='';
            el.addEvent('click',function(){
                var js = $H(JSON.decode(el.rel));
                
        		var notimooManager = new Notimoo({
                        locationVType: 'bottom',
                        locationHType: 'left'
                });
                 
                
                var req = new Request(
            	{
            		url:'modulos/noticias/noticias.registrarvoto.php'
            		,method:'post'
            		,onSuccess:function(responseText,responseXML)
            		{ 
            		    var oHash = $H(JSON.decode(responseText));
                        var messaje = oHash.get('message2');
                        if(oHash.get('status')==1)
                        {
                            if(el.getParent().get('tag')!='div')
                            {
                                var divCont = new Element('div',{id: 'controles-vot-'+js.get('IdNoticia'), style:'display:inline;'});
                                divCont.wraps(el.getParent());
                            }
                            var container = el.getParent().getParent();
                            container.innerHTML = oHash.get('message1');
                            var recursion = container.getElements('a');
                            
                            if(recursion!=null)
                                recursion.each(function(el1){el1.addEvent('click',function(){return false;})})
                        }
                        notimooManager.show({
                            title: 'Votaci&oacute;n',
                            message: messaje,
                            width: 350, 
                            visibleTime: 2500
                        });
                    }
            		,onComplete:function()
            		{
            		        
            		}
            		,onRequest:function()
            		{
          	    		notimooManager.show({
                            title: 'Realizando Votaci&oacute;n',
                            message: 'Enviando datos...',
                            width: 350, 
                            visibleTime: 2500
                        });
            		}
            		,onFailure:function(xhr)
            		{ alert(xhr.statusText); }
            	});
                req.send(js.toQueryString());
                return false;            
            });            
        });
    }
});
