//
var screenWidth = 0;
var screenHeight = 0;
var subPage;
var subFrame;
var pageST;
var moveST = 1;
//
var i = 0;
var speed = 0.08;
var setInt;

//
var homeURL = '../main/main.asp';
var lightingURL = '../garden/lighting.asp';
var homeSWF = null; // Subcontent Object
var lightSWF = null; // Subcontent Object
var lightMenu = null;

var autoMenu;

// getting browser size
function setPage() {

	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		screenWidth = window.innerWidth;
		screenHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		screenWidth = document.documentElement.clientWidth;
		screenHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		screenWidth = document.body.clientWidth;
		screenHeight = document.body.clientHeight;
	}

	// set subpage
	subPage = document.getElementById("subPage");
	subPage.style.width = screenWidth;
	subPage.style.height = screenHeight;

	if ( !pageST ) {
		// set subframe
		subFrame = document.getElementById("frame");
		pageST = 1;
	}
	// Subpage Auto Slide & Link Page
	if ( autoMenu ) {
		moveAction();
		lightMenu = autoMenu;
		autoMenu = null;
	}
}

// Left Right movement action
function moveAction() {
	moveST = 1;
	if ( pageST == 1 ) {
		// to LED
		//homeURL = subFrame.src;
		setInt = setInterval(moveToRight,10);
	} else if ( pageST == 2 ) {
		// to Home
		setInt = setInterval(moveToLeft, 10);
	}
}

// go LED garden
function moveToRight() {
	var mx;
	if ( moveST == 1 ) {
		mx = -(screenWidth+20) * Math.sin(i*(Math.PI/2));
		i += speed;
		subPage.style.left = mx;
		//
		if ( i >= 1 ) {
			subFrame.src = lightingURL;
			subFrame.style.left = -screenWidth*2;
			moveST = 2;
			i =0;
		}
	} else if ( moveST == 3 ) {
		mx = (screenWidth+20) * Math.sin(i*(Math.PI/2));
		i += speed;
		subPage.style.left = screenWidth - mx;
		//
		if ( i >= 1 ) {
			clearInterval(setInt);
			subPage.style.left = 0;
			pageST = 2;
			i = 0;
			//
			if (lightMenu) menuSelect();
		}
	}
}

// go Home
function moveToLeft() {
	var mx;
	if ( moveST == 1 ) {
		mx = (screenWidth+20) * Math.sin(i*(Math.PI/2));
		i += speed;
		subPage.style.left = mx;
		//
		if ( i >= 1 ) {
			lightMenu =null;
			//document.frame.location.href = homeURL;
			subFrame.src = homeURL;
			subFrame.style.left = screenWidth*2;
			moveST = 2;
			i =0;
		}
	} else if ( moveST == 3 ) {
		mx = (screenWidth+20) * Math.sin(i*(Math.PI/2));
		i += speed;
		subPage.style.left = -screenWidth + mx;
		//
		if ( i >= 1 ) {
			clearInterval(setInt);
			subPage.style.left = 0;
			pageST = 1;
			i =0;
		}
	}
}

// Lighting Garden Go Sub
function menuSelect() {
	lightSWF.menuSelect( lightMenu[0], lightMenu[1] );
	lightMenu = null;
}

window.onload = setPage;
window.onresize = setPage;

