// JavaScript Document
var apis = [];
//apis.push("http://wis.arthur.com.tw/projects/lovelyTimerJs/getPhoto.php");
apis.push("http://arthurtw.com/projects/lovelyTimerJs/getPhoto.php");
apis.push("http://www.arthur.com.tw/projects/lovelyTimerJs/getPhoto.php");
apis.push("http://www.arthur.com.tw/projects/lovelyTimerJs/getPhoto.php");

var t;
//API
function getAPI() {
	var r = Math.floor(Math.random()*apis.length);
	return apis[r]+"?"+new Date().getTime();	
}
//更新
function update() {
	$("#loading").css('display','block')
	var api = getAPI();
	if($('#debuger #ta')){
		var v = api+'\n'+$('#debuger #ta').val();
		
		$('#debuger #ta').val(v)
	}
	 var img = new Image();
	 $(img).addClass("fix layer").css('display','none').load(function(){			
			$(this).css('display','block').fadeOut(0).fadeIn(500,fadeInComplete);	
			$("#photos").append($(this));
			$("#loading").css('display','none')
	 }).error(fadeInComplete).attr('src',api);	
}
//完成
function fadeInComplete() {
	while($("#photos img").size()>1) {
		$("#photos img:first").remove();
	}
	clearTimeout(t);
	t=setTimeout(update,60000);
}
//dom ready
$(function(){ 
	$("#lovelyTimerJs").click(function(){window.open("http://www.arthur.com.tw")}).rightClick( function(e) {alert("正妹報時 - 亞瑟網\nArthur.com.tw");  });	
	update();
});
