var rand=Math.floor(Math.random()*116000);
//rand=rand%9000+9000;
$(document).ready(function(){
	get_photo();
	$('.star,.cancel').livequery('click', function(){
		$('.star,.cancel').unbind('click');
	});
}
);
function get_photo(){
	
	//var rpc = new PHPRPC_Client('http://bawbaw.deep.tw/beauty/rpc.beauty.php', ['get_beauty']);
	var rpc = new PHPRPC_Client('http://get-beauty.appspot.com/', ['get_beauty']);
	rpc.get_beauty(rand,function(result){
		if(!result || result['a']==''){
			setTimeout(function(){document.location.href=document.location.href;}, 100);
			return;
		}
		$('.all_pic').attr('href',result['a']);
		$('#girl_image').attr('src',get_photo_proxy()+result['p']).show();
		$('.all_pic').show();
		$('#girl_image').load(function(){
			$('#rate').rating('rating.php?photo_url='+result['p']+'&album_url='+result['a'], {maxvalue:5}).show();
			$('#waiting').hide();
			setTimeout(function(){document.location.href=document.location.href.replace(/#\d+/g, "");}, 20000);
		}
		);
		/*
		$('#girl_image').error(
			function(){
				//setTimeout(function(){document.location.href=document.location.href.replace(/#\d+/g, "");}, 10);
				var src=$(this).attr('src');
				var new_src = src.replace(/\/random_beauty\.php/g, "/renew_random_beauty.php");
				$(this).attr('src',new_src);
			}
		);
		*/
	});
}
function get_photo_proxy()
{
	var proxy_list=[
	//'http://bellona.lunarservers.com/~deep01/bawbaw-hu3/random_beauty.php/',
	//'http://bellona.lunarservers.com/~deep01/bawbaw-hu/random_beauty.php/',
	//'http://bawbaw.icittys.com/random_beauty.php/',
	//'http://bawbaw.icittys.com/random_beauty.php/',
	//'http://bawbaw.icittys.com/random_beauty.php/',
	//'http://bawbaw.icittys.com',
	'http://hot.icittys.com',
	'http://hot.icittys.com',
	'http://hot.icittys.com'
	];
	var proxy_count=proxy_list.length;
	return proxy_list[Math.floor(Math.random()*proxy_count)];
}