// JavaScript Document

 $(document).ready(function(){
  $("#play_link").click(function(event){
	  	mp3_file = 'files/fckUserFiles/file'+$("#play_link").attr("title");
		$("#player").html('<object type="application/x-shockwave-flash" data="audio/player.swf" id="audioplayer1" height="24" width="290"><param name="movie" value="audio/player.swf"><param name="FlashVars" value="playerID=1&amp;soundFile='+ mp3_file +'&amp;autostart=yes"><param name="quality" value="high"><param name="menu" value="false"><param name="wmode" value="transparent"></object> ');
       // Stop the link click from doing its normal thing
       return false;
     });


   });
// star changer
 $(document).ready(function(){
      //$('.starField').hover(function() {
	 $('.starField').click(function() {
		value = $(this).attr("title");
		$('#vote').attr( "value", value )
		mode = $(this).attr("src")
		if ( mode == 'images/assets/star_blank.gif' ) {
			// debo poner en full todos los que son menores o iguales a mi valor
			$('#stars_fieldset img').each(function(i, o){
				id = i+1;
			    obj = $('#starfield_'+id);
				if (i < value ) {
						obj.attr({src : "images/assets/star_full.gif"});					
				}else {
						obj.attr({src : "images/assets/star_blank.gif"});					
				}
					
				});
		}
		else {
			// debo poner en blanco todos los que son mayores o iguales a mi valor			
			$('#stars_fieldset img').each(function(i, o){
				id = i+1;
			    obj = $('#starfield_'+id);
				if ( i < value ) {
						obj.attr({src : "images/assets/star_full.gif"});					
				}else {
					obj.attr({src : "images/assets/star_blank.gif"});					

				}
			});

		}
      });
   
     $("#vote_form").submit(function(){
    	  $.post("_vote.php",{
    	        id: $("#id").val(),
    	        vote: $("#vote").val(),
    	        action: "cast_vote"
    	      }, function(xml) {
    	    addMessages(xml);
    	  });
    	  return false;
    	 });      
      $("#comment_form").submit(function(){
    	  if ( $("#person").val() == '' || $("#comment").val() == '' ){
    			text = '<p>You should fill all fields</p>'
    			$("#comment_form").prepend( text );

    		  return false;
    	  }
    	  else {
	    	  $.post("_add_comment.php",{
	    	        id: $("#mp3_id").val(),
	    	        person: $("#person").val(),
	    	        comment: $("#comment").val()
	    	      }, function(xml) {
	    	    comment_msg(xml);
	    	  });
    	  }
    	  return false;
    	 });
      	
							
});

function addMessages(xml) {
    //if($("status",xml).text() == "2") return;
	rating = Math.floor( $("rating",xml).text() ) 
    text = "<p>"+$("status",xml).text() + "<br/></p>";
    //text = text + "<p> Total Votes: " + $("votes",xml).text() + "</p>";
    $("#messagewindow").html(""+text+"");
    text = " Current Rating: " + rating + "<br/>";
    text = text + "VOTES: "+$("votes",xml).text() +""; 
    $("#total_votes").html( text );
    reload_stars( rating );

  }			
function reload_stars ( rating ) {
	html = '';
	blank_star = '<img src="images/assets/blank_star.gif" alt="blank star"/>';
	full_star = '<img src="images/assets/star.gif" alt="star"/>';
	for ( current_star = 1; current_star < 6; ++current_star  ){
		
		if ( current_star <= rating ){
			html = html + full_star; 
		}
		else {
			html = html + blank_star;
		}
	}
	$('.stars').html( html )
}
function comment_msg(xml) {
	text = "<p>"+ $("status",xml).text() + "</p>"
	$("#person").attr("value","");
	$("#comment").attr("value","");	
	$("#comment_form").html( text );
	
}
 $(document).ready(function(){
  $("#add_another").click(function(event){
	$("#copiar_campos").clone().appendTo("#students_involved").find("input.student").val("");

       // Stop the link click from doing its normal thing
       return false;
     });


   });

