<?
include("../include/config.php");
?>
$j(document).ready(function(){
    var rating_text     = $j('#rating_text').html();
    var rating_current  = $j("input[id='current_rating']").val();
        
    $j("[id*='star_']").click(function(event) {
        event.preventDefault();
        var star_id     = $j(this).attr("id");
        var id_split    = star_id.split('_');
        var rating      = id_split[2];
        var video_id    = id_split[3];
        $j("#rating_text").html('<?php echo $lang['538']; ?>');
        $j.post(base_url + '/rate.php', { id: video_id, value: rating },
        function (response) {
            $j("#rating").html(response.rating_code);
            $j("#rating_text").html(response.msg);
        }, "json");            
    });
    
    $j("[id*='star_']").mouseover(function(){
        var star_id     = $j(this).attr('id');
        var id_split    = star_id.split('_');
        var rating      = id_split[2];
        var video_id    = id_split[3];
        for ( var i = 1; i<=5; i++ ) {
            var star_sel = $j("a[id='star_video_" + i + "_" + video_id + "']");
            if ( i <= rating )
                $j(star_sel).removeClass().addClass('full');
            else
                $j(star_sel).removeClass();
        }
        if ( rating == 1 ) {
            $j('#rating_text').html('<?php echo $lang['631']; ?>');
        } else if ( rating == 2 ) {
            $j('#rating_text').html('<?php echo $lang['632']; ?>');
        } else if ( rating == 3 ) {
            $j('#rating_text').html('<?php echo $lang['633']; ?>');
        } else if ( rating == 4 ) {
            $j('#rating_text').html('<?php echo $lang['634']; ?>');
        } else if ( rating == 5 ) {
            $j('#rating_text').html('<?php echo $lang['635']; ?>');
        }
    });
    
    $j("ul[id='rating_container_video']").mouseout(function(){
        var star_id     = $j("[id*='star_video_1_']").attr('id');
        var id_split    = star_id.split('_');
        var video_id    = id_split[3];
        for ( var i = 0; i < 5; i++ ) {
            var star        = i+1;
            var star_sel    = $j("a[id='star_video_" + star + "_" + video_id + "']");
            if ( rating_current >= i+1 ) {
                $j(star_sel).removeClass().addClass('full');
            } else if ( rating_current >= i+0.5 ) {
                $j(star_sel).removeClass().addClass('half');
            } else {
                $j(star_sel).removeClass();
            }     
        }
        $j('#rating_text').html(rating_text);
    });
});
