function imgScreen(){
	var obj = new Array();
	var path = 'http://'+location.hostname+'/main_image/lotation.xml';
	var backGround = $("#animateBackGround");
	var foreGround = $("#animateForeGround");
	var delay = '6000';

	preload = function(img){
		var d = new Image();
		d.src = img;
		//console.log(d);
	},

	imgTurn = function(){
		var i=0;

		foword = function(){
			if(i<obj.length){
				var winSize = $("body").width();
				$(backGround).css({"width":winSize});
				$(foreGround).css({"width":winSize});
				$("#animateContainor ").css({"width":winSize});

				$(backGround).animate({
					"opacity":"0",
					"marginLeft":"-"+Number(winSize)*2+"px"
				},1500,"easeInCubic",function(){
						$(backGround).css({
							"background-image": "url("+obj[i].back+")",
							"margin-left":""+winSize+"px",
							"opacity":"0"
						}).animate({
							"opacity":"0.2",
							"marginLeft":"0px"
						},1500,"easeOutCubic",function(){
							$(backGround).animate({
								"opacity":"1"
							},1000);
						});
				});

				$(foreGround).delay(750).animate({
					//"opacity":"0.5",
					"marginLeft":"-"+Number(winSize)*2+"px"
				},1500,"easeInQuart",function(){
						$(foreGround).css({
							"background-image": "url("+obj[i].fore+")",
							//"opacity":"0.5",
							"margin-left":""+winSize+"px"
						}).animate({
							//"opacity":"1",
							"marginLeft":"0px"
						},1500,"easeOutQuart");
						i++;
						setTimeout(foword,delay);
				});

			}else{
				i=0;
				setTimeout(foword,100);
			}
		}
		foword();
	},

	dataLoad = function(XML){
		var i = new Number(0);
		$(XML).find("Img").each(function(){
			obj[i]  = {"back":$(this).find("Back").text(),"fore":$(this).find("Fore").text(),"ID":$(this).find("ID").text()};
			preload($(this).find("Back").text());
			preload($(this).find("Fore").text());
			i++;
		});

		if(i>0){
			imgTurn();
		}
	}
	
	$.ajax({
		'url': path,
		'type': 'get',
		'dataType': 'xml',
		'data': {},
		'cache': false,
		'success': dataLoad
	});
}


$(function(){
	imgScreen();
});
