var id;
var op=0;
var step=10;
var wmin=770;
var wsb;
var sep_state=0; // 0-fadein, 1-split, 2-normal
var ns4 = (document.layers)? true:false;
var ie4 = (document.all)? true:false;
var wsb = ns4 ? 16 : 20;

function OnLoad_main () {
	Align();
	//PlayMusic();
}

function OnLoad_index () {
	Start();
	PlayMusic();
}

//var win_play = null;
function PlayMusic () {
	//if (win_play) return;
	win_play = open('play.html','winplay',
		'resizable=no,scrollbars=no,menubar=no,directories=no,hotkeys=no,status=no,titlebar=no,toolbar=no,'+
		'width=220,height=220');
	win_play.blur();
}

function PlaySong(song) {
	if (win_play) {
		win_play.document.all.playmusic.src = song;
	}
}

function Align() {
	var w;
	w = (ns4 ? window.innerWidth : document.body.offsetWidth) - wsb;
	w = w>wmin ? w:wmin;
	// main frame table
	document.all.main_frame.width = w;
}

function Separate() {
	var w, h;
	w = (ns4 ? window.innerWidth : document.body.offsetWidth) - wsb;
	h = ns4 ? window.innerHeight : document.body.offsetHeight;
	w = w>wmin ? w:wmin;
	// image1
	if (sep_state == 0) {
		// main frame table
		//document.all.main_frame.width = w;
		// image1
		document.all.img1.style.pixelLeft = (w - document.all.img1.width) / 2;
		document.all.img1.style.pixelTop = (h - document.all.img1.height) / 2;
		// image2
		document.all.img2.style.pixelLeft = w / 2 - document.all.img2.width;
		//document.all.img2.style.pixelTop = 80;//(h - document.all.img2.height) / 2;
		// image3
		document.all.img3.style.pixelLeft = w / 2;
		//document.all.img3.style.pixelTop = 80;//(h - document.all.img3.height) / 2;
	}
	else if (sep_state == 2) {
		// main frame table
		//document.all.main_frame.width = w;
		// image3
		document.all.img3.style.pixelLeft = w - document.all.img3.width;
	}
}

function Start() {
	sep_state = 0;
	Separate();	
	id = window.setInterval("FadeIn()", 100);
}

function Split() {
	var s = 0;
	var x2 = document.all.img2.style.pixelLeft - step;
	var x3 = document.all.img3.style.pixelLeft + step;
	var x4 = document.body.offsetWidth - wsb;
	x4 = (x4 > wmin) ? x4 : wmin;
	x4 = x4 - document.all.img3.width;
	if (x2 < 0) { x2 = 0; s |= 1; }
	if (x3 > x4) { x3 = x4; s |= 2; } 
	document.all.img2.style.pixelLeft = x2;
    document.all.img3.style.pixelLeft = x3;   
    if (s == 3) {
    	window.clearInterval(id);
    	document.location="home.php";
    	sep_state = 2;
    }
}

function FadeIn() {
	op += step;
	if (op <= 100) {
		document.all.img1.filters.Alpha.opacity = op;
	}
	else {
		window.clearInterval(id);
	}
}

function Flip() {
	window.clearInterval(id); // in the case it's not done yet
	document.all.img2.style.visibility = "visible";
	document.all.img3.style.visibility = "visible";
	document.all.img1.style.visibility = "hidden";
	align_style = 1;
	id = window.setInterval("Split()",50);
}

function HighlightMenu() {
    if (window.event.srcElement.tagName == "A") 
        window.event.srcElement.style.color = "#D26C46";
}

function LowlightMenu() {
    if (window.event.srcElement.tagName == "A") 
        window.event.srcElement.style.color = "#A53F19";
}
