﻿//when the page is ready initialize the poll
$(document).ready(initPage);

//initialize the page by executing an ajax call to load the poll
function initPage()
{
    //$.cookie("LENSPOLL", "voted", { path : "/", expires : 1});
    //$.cookie("LENSPOLL", null, { path : "/", expires : 1});

    sendToJavaScript(0);

    //do an ajax call to get the poll
    $.ajax({
        type: "GET",
        url: "files/poll.xml",
        dataType: "xml",
        cache: false,
        success: setupPoll
    });
}

//when the ajax call is complete setup the poll
function setupPoll(xml)
{
    //regardless of if the user has voted we need to load the question and image parameters
    var spottext = $("#spottext");
    spottext.html("<a href=\"poll.aspx?height=600&width=900\" class=\"thickbox\">" + $(xml).find("question").attr("text") + "</a>");
    $("#spotlight > a").addClass("thickbox");
    $("#spotlight > a > img").attr("src", $(xml).find("thumbnail").attr("src"));

    //call tb_init to refresh the thick box functionality
    tb_init('a.thickbox, area.thickbox, input.thickbox');
}

function userVote(source)
{
    //flag that the user voted
    //$.cookie("LENSPOLL", "voted", { path: "/", expires: 1 });

    $("#castVote").attr("href", "poll.aspx?height=600&width=900&vote=" + source.value);
}