$(document).ready(function() {
	
	var sliderValue = 0;
	
	$("#slider").slider({
     
        range: "min",
         
        value: 0, 
        
        min: 0,
         
        max: 5, 
        
        slide: function(event, ui) {
        	
        	for (i = 0; i < ui.value; i++)
        	{
        		$( '#star' + (i + 1) ).attr("src","/templates/classic/p/img/design/icons/rating_star_on.png");	
        	}
        	
        	for (i = ui.value; i <= 5; i++)
        	{
        		$( '#star' + (i + 1) ).attr("src","/templates/classic/p/img/design/icons/rating_star_off.png");	
        	}
        	
        	$('#rating').val(ui.value);
        }
    });

	$.fx.speeds._default = 500;
	
    $('#rating_dialog').dialog({
        autoOpen: false,
        height: 300,
        width: 400,
        resizable: false,
		modal: true,        
	    show: "explode",
		hide: "explode", 
        buttons: {
            'Speichern': function() {

            	var kommentar = $('#kommentar').val();
            	
            	if (kommentar != "")
            	{
					$.ajax( {
											
						url: '/rating/newcomment',
						
						type: 'POST',
						
						data: ({ 
							rating: $('#rating').val(),
            			
	            			kommentar: kommentar,
	            			
	            			product_id: $('#product_id').val()
						}),
						
						success: function( ) {
							$('#rating_dialog').dialog('close');
							
							window.location.href = $('#RefreshUrl').val();							
						}
					});            		
            	}
            	else
            	{
            		alert('Bitte einen Kommentar eingeben!');
            	}          
            },
            'Abbrechen': function() {
            	
                $('textarea, #kommentar').val('');
            	
            	$(this).dialog('close');    
            }
        }
    });
	
	
	$('#write_rating').click( function() {
		
		$('#rating_dialog').dialog('open');		
	});
	
	
});
