﻿//This script was writen by me.

$(document).ready(function(){
//start fuctions//
    //alert("hi");
    $("a.vote").click(function(){
        
        trID = $(this).attr("id");
        var CurClass = $("#" + trID).attr("class");
        
        if (CurClass == "vote loaded" )
        {   
            //css based duplicate voting 
            //alert("you already voted !!!");
            //$("#" + trID).after(" <strong> you have already voted!<\/strong>");
        }
        else
        {
            var CurCookie = $.cookie("c_" + trID); // get cookie
            if (CurCookie == "_loaded")
            {
                //cookie based duplicate voting 
                $("#" + trID).addClass("loaded");
                $("#" + trID).after(" <strong> You have already voted!<\/strong>");
                //alert("you have already voted!");
            }
            else
            {
                $("#" + trID).after("<br class='clr' /><img id='i_" + trID + "' src='images/loader.gif' alt='...loading' />");
				$("#" + trID).hide();
                //$("#" + trID + " span").show();
                
                //sets a class that indicatest that this article has been voted
                $("#" + trID).addClass("loaded");
                
                //sets cookie to prevent duplicate loading
                $.cookie("c_" + trID, '_loaded'); // set cookie

                //change number
                var currentNumber = $("p").text();
                
                //var url = "vote.aspx?" + this.href;
                var url = this.href;
                $.get(url, function(data){
                    $("a#" + trID).after(" " + data);
                    $("#i_" + trID).hide();
					//$("#" + trID).show();
                });
            }
        }
        
    return false;
    });
    
    
//    //flickr voting
//    $("#flickr_images a").hover(function(){
//        //$(this).addClass("hover");

//        $(this).wrap("<div class='fl_wrap'></div>");
//    },function(){
//        //$(this).removeClass("hover");
//    });
    
    
//end fuctions//
});


