
$(document).ready(function(){
 $("#comment0").submit(function(){
  if( !$("#commenttext0").val() ){
    return false;
  }
  $.post("/airtheremin/watch/comment",{
   vid    : $("#commentvid0").val(),
   comment: $("#commenttext0").val()
  },function(r){
   $('#comment0').html("<div style='text-align:center;'>thanks</div>");
  });
  return false;
 });
});

$(document).ready(function(){
 $("#comment1").submit(function(){
  if( !$("#commenttext1").val() ){
    return false;
  }
  $.post("/airtheremin/watch/comment",{
   vid    : $("#commentvid1").val(),
   comment: $("#commenttext1").val()
  },function(r){
   $('#comment1').html("<div style='text-align:center;'>thanks</div>");
  });
  return false;
 });
});

$(document).ready(function(){
	$("#playanchor").mouseover(
		function(){
			$("#playimg").src("/airtheremin/images/play_over.gif");
		}
	).mouseout(
		function(){
			$("#playimg").src("/airtheremin/images/play.gif");
		}
	);
});

$(document).ready(function(){
	$('.inputembed').click(function(){
		this.select();
	});
});

function star(container, def){

	var cont = document.getElementById(container);
	var stars = new Array(5);
	var star_on  = '★';
	var star_off = '☆';

	function set( rate ){
		var i;
		for( i=0; i<5; i++ ){
			// 四捨五入
			stars[i].innerHTML = ( stars[i].index <= rate+0.5 ) ? star_on : star_off;
		}
	}
	function onmouseover(){
		set( this.index );
	}
	function onmouseout(){
		set( def );
	}
	function onclick(){
		$.post("/airtheremin/watch/rate",{
			"vid"  :cont.id.substr(5),
			"rate" :this.index},
			function(htm){ //console.log("success: "+htm)
			});
		cont.innerHTML = "thanks!";
		//clearListeners();
		return false;
	}
	function clearListeners(){
		for( var i=0; i<5; i++ ){
			stars[i].onclick=function(){return false;};
			stars[i].onmouseover=function(){return false;};
		}
	}

	cont.innerHTML = "";
	cont.onmouseout = onmouseout;
	for(var i = 0 ; i < 5 ; i++){
		stars[i] = document.getElementById(container).appendChild(document.createElement('a'));
		stars[i].href = "javascript:void(0);";
		stars[i].index = i+1;
		$(stars[i]).mouseover( onmouseover );
		//stars[i].onmouseout = onmouseout;
		$(stars[i]).click( onclick );
	}
	set( def );
}

function showRaterResponse(originalRequest){
	hideLoad();

	var newData = originalRequest.responseText;

	var selected = eval( '(' + originalRequest.responseText + ')' );
	$(selected.ret).innerHTML = "thanks!";
}
