function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}

var imgTotal = 3;
var imgCount = 1;
var frontVisible = true;
var homeText,imgDiv,imgEl;

function imgLoader() {
	var newImg = new Image();
	newImg.onload = function() {
		if (frontVisible == true) {
			imgDiv.style.backgroundImage = "url(" + newImg.src + ")";
			imgFade.custom(1,0);
			frontVisible = false;
		} else {
			imgEl.src = newImg.src;
			imgFade.custom(0,1);		
			frontVisible = true;
		}
		homeTextAni.start({
			'opacity': 0
		});
		if (imgCount == 0) {
			sloganFx.start({
				'width': 0,
				'height': 0
			});
		}
	}
	newImg.src = "/images/home_" + imgCount + ".jpg";
}

var imgText = (window.location.toString().match(/\/cn\//g)) ? [
	'國際服務，進口/出口，海洋與空氣，或 FCL 或 LCL',
	'配送服務，自動化WMS性，戰略性的位置',
	'Transload和跨碼頭服務，自動分揀系統，服裝專家',
	'運輸服務，貨運碼頭，機場，車站，路線，檢獲的貨車'
] : [
	'International Services, Import/Export, Ocean & Air, FCL or LCL',
	'Warehousing & Distribution Services, Automated WMS, Strategic Locations',
	'Transload & Cross Dock Services, Automated Sortation Systems, Garment Specialists',
	'Transportation Services, Pier Trucking, Airport Pick-ups, Line Haul Trucking'
];


function setupHome() {
	if (Fx && $("home_photos")) {
		imgDiv = $("home_photos");
		imgEl = $E('img', imgDiv);
		homeText = $("homeText");

		homeTextAni = new Fx.Styles(homeText, {duration:500, wait:false, onComplete:function() {
			if (parseInt(this.element.getStyle('opacity')) == 0) {
				homeText.innerHTML = '<p>' + imgText[imgCount] + '</p>';
				this.start({
					'opacity': 1
				});
			}
		}});

		homeText.innerHTML = '<p>' + imgText[0] + '</p>';

		sloganFx = new Fx.Styles("slogan", {duration:1000, wait:false, transition: Fx.Transitions.Back.easeOut});

		imgFade = new Fx.Style(imgEl, "opacity", {duration:1000, onComplete: function() {
			if (imgCount<imgTotal) {
				imgCount++;
			} else {
				imgCount = 0;
				sloganFx.start({
					'width': 605,
					'height': 50
				});
			}
			setTimeout(imgLoader, 6000);
		}});
		setTimeout(imgLoader, 6000);
	}
}
addLoadEvent(setupHome);
