// JavaScript Document
$(document).ready(function(){
    // get current rating
    try {
        getRating();
    } 
    catch (e) {
    }
    // get rating function
    function getRating(){
   	
        $.ajax({
            type: "GET",
            url: "../../ajax_res/manager_votation.php",
            data: "in_rating=" + $('#rate_this').text() + "&do=getrate",
            cache: false,
            async: false,
            success: function(result){
                // apply star rating to element
                $("#current-rating").css({
                    width: "" + result + "%"
                });
            },
            error: function(result){
                //alert("some error occured, please try again later");
            }
        });
    }
    
    // link handler
    $('#ratelinks li a').click(function(){    	
        $.ajax({
            type: "GET",
            url: "../../ajax_res/manager_votation.php",
            data: "in_rating=" + $('#rate_this').text() + "&rating=" + $(this).text() + "&do=rate",
            cache: false,
            async: false,
            success: function(result){
                // remove #ratelinks element to prevent another rate       	
                $("#ratelinks").remove();
                // get rating after click
                getRating();
            },
            error: function(result){
                //alert("some error occured, please try again later");
            }
        });
        
    });
});

