﻿//Precondition: Jquery has loaded first


// Preload the images common to all pages
//urls in javascript resolve relative to the page they are run from rather than relative to this javascript file.
//urls in CSS on the other hand resolve relative to their own location (opposite)

// Preload image method
jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}
// Preload this site's images
var bp = "App_Themes/VoteEJ/images/";//basePath
$.preloadImages(bp + "arrow.jpg", bp + "boxbottom.jpg", bp + "boxrepeat.jpg", 
bp + "boxtop.jpg", bp + "divider.png", bp + "map.jpg", bp + "top.jpg");



//After the page has loaded...
$(document).ready(function()
{
     //Setup These Events
          
    //Redirect all radio button clicks to the vote button
    $("#divCurrentPoll .PollAnswer input").click(function(e){
        SelectedAnswer = this.id;//SelectedAnswer will be an existing variable that works with the callback
        //Click the submit button
        $("#divCurrentPollButtonBox input").click();
    });
    
    //Hide the vote button
    $("#divCurrentPollButtonBox input").hide();
    
    // Poll Radio Button Customization
    
    // For each Radio Button:
    //  Hide it
    //  Repurpose the existing label
    //      wire this onclick event up to the radio button click event
    //      setup default and hover styles for the radio button
    
    //Hide it
    $('#divCurrentPoll .PollAnswer input').each(function(i){
        var thisRB = $('#' + this.id);
        thisRB.hide();
    });
    
    //Wire it
    $('#divCurrentPoll .PollAnswer label').click(function(){
        var associatedRB = $('#' + this.htmlFor);
        associatedRB.click();
    });
    
    //Add the CssClass for CustomRadio to the existing labels for the radio buttons
    $('#divCurrentPoll .PollAnswer label').addClass('CustomRadio');


});

function SetupRadioButton()
{
    //$("#divCurrentPoll .PollAnswer input").hover(function(e){
    //    $("#divCurrentPoll .PollAnswer input").hide();
    //    this.add("<label class=\"RadioChecked\"></label>");
    //});
    
    //alert(this.id);
}



//TODO: Hide the poll vote button and wire up radio button clicks to its onclick event.

