﻿
 
  YAHOO.namespace("VoteRegistration");
  YAHOO.VoteRegistration.Registrar = function() {

 
	return {

        AddVoteButtons : function(voteButtons)
        {
       
            if(!this.static.RegButtons)
                this.static.RegButtons = new Array();
            
            
            
            for (i=0;i< voteButtons.length;i++){
                    this.static.RegButtons.push(voteButtons[i]);
            }              
        },

        AddVoteAVGButtons : function(voteAvgButtons)
        {
       
            if(!this.static.RegAvgButtons)
                this.static.RegAvgButtons = new Array();
            
            
            
            for (i=0;i< voteAvgButtons.length;i++){
                    this.static.RegAvgButtons.push(voteAvgButtons[i]);
            }    
                  
        },

        static : function()
        {
        }
		
 

	}

}();
  
   
YAHOO.namespace("VoteAVGButton")
YAHOO.VoteAVGButton = function() 
{


    var contentGuid;
 
	return {
		
		init: function (id,value,contentGuid)
        {
           
            this.id = id;
            this.value = value;
            this.contentGuid = contentGuid;           
        }
              

	}
 }

    
YAHOO.namespace("VoteButton")
YAHOO.VoteButton = function() 
{


    var contentGuid;
 
	return {
		
		VoteButton: function (id,value,contentGuid,callback,t,redir)
        {

            this.id = id;
            this.img = window.document.getElementById(id);
            this.img.voteButton = this;
            this.img.onclick = onclickFunc;
            this.value = value;
            this.contentGuid = contentGuid;
            this.redirect = redir;
            
              
            function onclickFunc()
            {
                callbackfunc = this.voteButton.redirect?callback.redirect:callback.voteCallback;
                
                callback.resetVotes(this.voteButton.value, contentGuid);  
                switch(t)
                {
                case "v":
                 //  AjaxCalls.SubmitVideoVote(contentGuid,this.voteButton.value,callback.voteCallback,callback.voteCallback);
                   AjaxCalls.SubmitVideoVote(contentGuid,this.voteButton.value,callbackfunc,callbackfunc);
                  break;    
                default:
                //  AjaxCalls.SubmitVote(contentGuid,this.voteButton.value,callback.voteCallback,callback.voteCallback);
                   AjaxCalls.SubmitVote(contentGuid,this.voteButton.value,callbackfunc,callbackfunc);
                }

                             
            } 
           
        },
       
        static : function()
        {
        },
        
        getcontentGuid: function()
        {
           return this.contentGuid;
        }

	}
 }


    
YAHOO.namespace("VoteMessaging")
YAHOO.VoteMessaging = function() 
{
    
	return {
		
		initvalues: function (contentGuid,checkedImg,uncheckedImg)
        {           
            this.static.contentGuid = contentGuid;
            this.static.checkedImg = checkedImg;
            this.static.uncheckedImg = uncheckedImg;                 
        },
       

        static: function() {
 
        },
           
           
        redirect: function(obj)
        {
          if(obj)
          {
            var link = window.location.href.replace("#comments","");
            window.location.href=link;
          }
        },   
             
         voteCallback: function (obj)
        {
           if (obj)
                this.resetAvgVotes(obj);
        },
        
        ajresetVotes: function(val)
         {         
         
            var results = val.split(",");
              
            for (i=0;i< YAHOO.VoteRegistration.Registrar.static.RegButtons.length;i++)
            {
                 var button  = YAHOO.VoteRegistration.Registrar.static.RegButtons[i];
                if(results[0] == button.getcontentGuid())
                  {
                    if(results[1] >= button.value)
                       window.document.getElementById(button.id).src = checkedImg;
                    else
                        window.document.getElementById(button.id).src = uncheckedImg;
                  }                              
            }     
          
         },
         
         resetVotes: function(val, contentGuid)
         {
            for (i=0;i< YAHOO.VoteRegistration.Registrar.static.RegButtons.length;i++)
            {
                 var button  = YAHOO.VoteRegistration.Registrar.static.RegButtons[i];
                 
                if(contentGuid == button.getcontentGuid())
                  {
                    if(val >= button.value)
                       window.document.getElementById(button.id).src = checkedImg;
                    else
                        window.document.getElementById(button.id).src = uncheckedImg;
                  }                              
            }     
         },
        
        
        resetAvgVotes: function (val)
        {
 
            for (i=0;i< YAHOO.VoteRegistration.Registrar.static.RegAvgButtons.length;i++)
            {
                 var avgbutton  = YAHOO.VoteRegistration.Registrar.static.RegAvgButtons[i];
                 
                if(this.static.contentGuid == avgbutton.contentGuid)
                  {
                    if(val >= avgbutton.value)
                       window.document.getElementById(avgbutton.id).src = checkedImg;
                    else
                       window.document.getElementById(avgbutton.id).src = uncheckedImg;
                  }                              
            }     
          
        } 
      


	}
 }



