VMA = new function(){	
this.init = function(){
VMA.Voting.init();
}
}

VMA.NomineeVoting = new function(){
this.more = function(){
if(Flux.Context.isUserAuthenticated()){
window.open('/ontv/vma/2009/nominee_voting/index.jhtml?categoryId=' + VMA.Voting.categoryId, 'nominee_voting', 'height=532, width=749');
}
else{
MTVN.UI.ModalWindow.open(VMA.Voting.loginWindowUrl,null,"jquery");
return false;
}	
}
}

VMA.Utils = new function(){
this.arrayContains = function(ar, val){
var contains = false;
for(var i=0; i < ar.length; i++){ if(ar[i] == val) contains = true; }
return contains;	
}
}

VMA.Voting = new function(){

this.active = false;
this.cogix = "polling-onair";
this.validator= "timestamp|votes";
this.authClass = "com.mtvnet.auth.dis.HashDigestInputStrategy1";

this.style = "list";
this.thanksWindowUrl = "/inhouse/temp/elainem/grammy_2010_vote/thanks.jhtml";
this.loginWindowUrl = "http://community.mtvu.com/SignUp.aspx?returnPath=http://www.mtvu.com/on-campus/oscars-student-correspondent-red-carpet-contest-2010/";

this.init = function(){

$j(".vote-btn").each(function() {
var targetId = this.id;
var vars = targetId.split(":"); //get pollId and value
var pollId = vars[0];
var value = vars[1];
var embedId = "voteButton" + value;
var user = (Flux.Context.isUserAuthenticated()==true) ? Flux.Context._loggedUserUcid : "";

var flashVars = "";
flashVars += "cogix=" + VMA.Voting.cogix + "&amp;";
flashVars += "validator=" + VMA.Voting.validator + "&amp;";
flashVars += "authClass=" + VMA.Voting.authClass + "&amp;";
flashVars += "pollid=" + pollId + "&amp;";
flashVars += "answer=" + value + "&amp;";
flashVars += "user=" + user + "&amp;";

//change this when I publish
var src = "http://www.mtvu.com/on_mtvu/oscars_2010/voteButton.swf";
var width = "47";
var height = "33";

try {
var so = new SWFObject(src, embedId, width, height, "9", "#000000");
}
catch(e) {
//console.log(e);
}
so.addParam("flashVars", flashVars);
so.addParam("AllowScriptAccess", "always");
so.addParam("wmode", "transparent");
so.useExpressInstall('/sitewide/components/expressInstall/adobeExpressInstall.swf');
so.write(targetId);

});
}

this.preSubmit = function(){

if(Flux.Context.isUserAuthenticated()){

//this just sends a value back to the flash button
}
else{

window.open( VMA.Voting.loginWindowUrl, "mtvULogIn" );

return false;
}

return true;
}

this.postSubmit = function(){

alert('Thanks for voting. Remember you only get one vote per day. Come back tomorrow and keep voting until March 2nd, and find out who is going to the Oscars on March 3rd.');

window.location = 'http://www.mtvu.com/on-campus/contests-sweepstakes/oscars/oscars-voting-thanks/'; 

}
}

MTV.initArray.push(MTV.Player.init);
MTV.initArray.push(VMA.init);
MTV.initArray.push(MTVN.UI.Overlay.init);

var votingPreSubmit = VMA.Voting.preSubmit;
var revealThanks = VMA.Voting.postSubmit;


