var state = 0;
var win;

function init() {
	var flashcontent = document.getElementById("flashcontent");
	var temp;

	if (document.getElementById("swf-player")) {
		temp = document.getElementById("swf-player");
		flashcontent.removeChild(temp);
	}

	if (document.getElementById("sub-nav")) {
		temp = document.getElementById("sub-nav");
		flashcontent.removeChild(temp);
	}	

	if (document.getElementById("img-back")) {
		var footer = document.getElementById("footer");
		temp = document.getElementById("img-back");
		footer.removeChild(temp);
	}

	if (document.getElementById("div-contract")) {
		temp = document.getElementById("div-contract");
		flashcontent.removeChild(temp);
	}
	if (document.getElementById("blog")) {
		win.destroy();
	}
}

function load () {
	requestPlayList();
	player ();
	intro ();
}

// intro
function intro () {
	state = 0; // 0 intro, 1 photograpy, 2 contract, 3 blog, 4 snap, 5 portrait, 6 landscape, 7 stage, 8, travel, 

	init();

	var flashcontent = document.getElementById("flashcontent");
	var swf_player = document.createElement("div");
	swf_player.id= "swf-player";
	flashcontent.appendChild(swf_player);

	var fo = new SWFObject ("/intro/intro.swf", "viewer", "900", "700", "8", "#181818");
	fo.addVariable("xmlDataPath", "/intro/gallery.xml");
	fo.write("swf-player");

	var img = document.createElement("img");
	img.src = "/images/footer.jpg";
	img.id = "img-footer";
	img.width = "160";
	img.height = "40";
	img.alt = "표현할 수 없는 것을 뺀 나미저 ver.3";
	swf_player.appendChild(img);
}

// photography
function photograpy() {
	state = 1; // 0 intro, 1 photograpy, 2 contract, 3 blog, 4 snap, 5 portrait, 6 landscape, 7 stage, 8, travel, 
	
	var flashcontent = document.getElementById("flashcontent");
	var div_sub;
	var temp;
	var img;

	init();

	div_sub = document.createElement("div");
	div_sub.id = "sub-nav";

	var div_tree1 = document.createElement("div");
	div_tree1.id = "sub-tree1";

	var dl = document.createElement("dl");
	img = document.createElement("img");
	img.src = "/photography/images/photography_snap.jpg";
	img.id = "img-snap";
	img.width = "150";
	img.height = "150";
	img.style.cursor="pointer";
	img.alt = "SNAP";
	img.onclick = function () { subNavSnap (); }
	dl.appendChild(img);
	div_tree1.appendChild(dl);
	div_sub.appendChild(div_tree1);

	var dl = document.createElement("dl");
	img = document.createElement("img");
	img.src = "/photography/images/photography_portrait.jpg";
	img.id = "img-portrait";
	img.width = "150";
	img.height = "150";
	img.style.cursor="pointer";
	img.alt = "PROTRAIT";
	img.onclick = function () { subNavPortrait (); }	
	dl.appendChild(img);
	div_tree1.appendChild(dl);
	div_sub.appendChild(div_tree1);

	var dl = document.createElement("dl");
	img = document.createElement("img");
	img.src = "/photography/images/photography_landscape.jpg";
	img.id = "img-landscape";
	img.width = "150";
	img.height = "150";
	img.style.cursor="pointer";
	img.alt = "LANDSCAPE";
	img.onclick = function () { subNavLandscape (); }	
	dl.appendChild(img);
	div_tree1.appendChild(dl);
	div_sub.appendChild(div_tree1);

	var dl = document.createElement("dl");
	img = document.createElement("img");
	img.src = "/photography/images/photography_stage.jpg";
	img.id = "img-stage";
	img.width = "150";
	img.height = "150";
	img.style.cursor="pointer";
	img.alt = "STAGE";
	img.onclick = function () { subNavStage (); }
	dl.appendChild(img);
	div_tree1.appendChild(dl);
	div_sub.appendChild(div_tree1);

	var dl = document.createElement("dl");
	img = document.createElement("img");
	img.src = "/photography/images/photography_travel.jpg";
	img.id = "img-travel";
	img.width = "150";
	img.height = "150";
	img.style.cursor="pointer";
	img.alt = "TRAVEL";
	dl.appendChild(img);
	div_tree1.appendChild(dl);
	div_sub.appendChild(div_tree1);

	var temp = document.createElement("div");
	temp.setAttribute("class","padding");

	var div_tree2 = document.createElement("div");
	div_tree2.id = "sub-tree2";	

	var dl = document.createElement("dl");
	img = document.createElement("img");
	img.src = "/photography/images/photography_snap_title.jpg";
	img.width = "150";
	img.height = "30";
	dl.appendChild(img);
	div_tree2.appendChild(dl);
	div_sub.appendChild(div_tree2);

	var dl = document.createElement("dl");
	img = document.createElement("img");
	img.src = "/photography/images/photography_portrait_title.jpg";
	img.width = "150";
	img.height = "30";
	dl.appendChild(img);
	div_tree2.appendChild(dl);
	div_sub.appendChild(div_tree2);

	var dl = document.createElement("dl");
	img = document.createElement("img");
	img.src = "/photography/images/photography_landscape_title.jpg";
	img.width = "150";
	img.height = "30";
	dl.appendChild(img);
	div_tree2.appendChild(dl);
	div_sub.appendChild(div_tree2);

	var dl = document.createElement("dl");
	img = document.createElement("img");
	img.src = "/photography/images/photography_stage_title.jpg";
	img.width = "150";
	img.height = "30";
	dl.appendChild(img);
	div_tree2.appendChild(dl);
	div_sub.appendChild(div_tree2);

	var dl = document.createElement("dl");
	img = document.createElement("img");
	img.src = "/photography/images/photography_travel_title.jpg";
	img.width = "150";
	img.height = "30";
	dl.appendChild(img);
	div_tree2.appendChild(dl);
	div_sub.appendChild(div_tree2);

	flashcontent.appendChild(div_sub);
}

// subNav snap
function subNavSnap () {
	state = 4; // 0 intro, 1 photograpy, 2 contract, 3 blog, 4 snap, 5 portrait, 6 landscape, 7 stage, 8, travel, 

	init();
	back ();

	var flashcontent = document.getElementById("flashcontent");
	var swf_player = document.createElement("div");

	swf_player.id= "swf-player";
	flashcontent.appendChild(swf_player);

	var fo = new SWFObject ("/photography/snap/viewer.swf", "viewer", "900", "700", "8", "#181818");
	fo.addVariable("xmlDataPath", "/photography/snap/gallery.xml");

	fo.write("swf-player");
}

// subNav portrait
function subNavPortrait () {
	state = 5; // 0 intro, 1 photograpy, 2 contract, 3 blog, 4 snap, 5 portrait, 6 landscape, 7 stage, 8, travel, 
	init();
	back ();

	var flashcontent = document.getElementById("flashcontent");
	var swf_player = document.createElement("div");
	swf_player.id= "swf-player";
	flashcontent.appendChild(swf_player);

	var fo = new SWFObject ("/photography/portrait/viewer.swf", "viewer", "900", "700", "8", "#181818");
	fo.addVariable("xmlDataPath", "/photography/portrait/gallery.xml");
	fo.write("swf-player");	
}

// subNav landscape
function subNavLandscape () {
	state = 6; // 0 intro, 1 photograpy, 2 contract, 3 blog, 4 snap, 5 portrait, 6 landscape, 7 stage, 8, travel, 
	init();
	back ();

	var flashcontent = document.getElementById("flashcontent");
	var swf_player = document.createElement("div");
	swf_player.id= "swf-player";
	flashcontent.appendChild(swf_player);

	var fo = new SWFObject ("/photography/landscape/viewer.swf", "viewer", "900", "700", "8", "#181818");
	fo.addVariable("xmlDataPath", "/photography/landscape/gallery.xml");
	fo.write("swf-player");	
}

// subNav stage
function subNavStage () {
	state = 7; // 0 intro, 1 photograpy, 2 contract, 3 blog, 4 snap, 5 portrait, 6 landscape, 7 stage, 8, travel, 
	init();
	back ();
	var flashcontent = document.getElementById("flashcontent");
	var swf_player = document.createElement("div");
	swf_player.id= "swf-player";
	flashcontent.appendChild(swf_player);

	var fo = new SWFObject ("/photography/stage/viewer.swf", "viewer", "900", "700", "8", "#181818");
	fo.addVariable("xmlDataPath", "/photography/stage/gallery.xml");
	fo.write("swf-player");	
}

// subNav travel
function subNavTravel () {
	state = 8; // 0 intro, 1 photograpy, 2 contract, 3 blog, 4 snap, 5 portrait, 6 landscape, 7 stage, 8, travel, 
	init();
	back ();
	var flashcontent = document.getElementById("flashcontent");
	var swf_player = document.createElement("div");
	swf_player.id= "swf-player";
	flashcontent.appendChild(swf_player);

	var fo = new SWFObject ("/photography/travel/viewer.swf", "viewer", "900", "700", "8", "#181818");
	fo.addVariable("xmlDataPath", "/photography/travel/gallery.xml");
	fo.write("swf-player");	
}

function back () {
	var footer = document.getElementById("footer");
	var img = document.createElement("img");
	img.src = "/photography/images/photography_back.jpg";
	img.id = "img-back";
	img.width = "60";
	img.height = "30";
	img.style.cursor="pointer";
	img.alt = "< Back";
	img.style.textAlign="left";
	img.onclick = function () { photograpy(); }
	footer.appendChild(img);	
}

function mouseCursorPointer () {
	document.body.style.cursor="pointer";
}

function mouseCursorDefalut () {
	document.body.style.cursor="default";
}

function contract () {
	state = 2; // 0 intro, 1 photograpy, 2 contract, 3 blog, 4 snap, 5 portrait, 6 landscape, 7 stage, 8, travel, 
	init();

	var flashcontent = document.getElementById("flashcontent");

	var div_contract = document.createElement("div");
	div_contract.id = "div-contract";

	var div_profile = document.createElement("div");
	div_profile.id = "div-profile";

	var pNode;
	var br = document.createElement("br");
	var textNode;
	var img;

	img = document.createElement("img");
	img.id = "img-contract";
	img.src = "/contract/images/contract.jpg";
	img.width = "200";
	img.height = "200";
	div_profile.appendChild(img);

	pNode = document.createElement("p");
	pNode.innerHTML =
		"email : iam (at) hyouk.net<br/>" +
		"location : Seoul, Korea";
	div_profile.appendChild(pNode);

	var div_info = document.createElement("div");
	div_info.id = "div-info";

	pNode = document.createElement("p");
	pNode.innerHTML =
		"<span style='color:#B0B0B0;'><Strong>ABOUT:</Strong></span><br/>" +
		"저는 신기혁 또는 DiG[디그]라고 불리는, 1979년 부산에서 태어난 한국인입니다.<br/>" +
		"자전거 타기와 여행 그리고, 사진과 음악 듣기를 좋아합니다.<br/><br/>" +
		"이곳은 제가 지내온 과거의 시간과 꿈꾸는 것에 대한 이야기들이 가득 담겨 있습니다.<br/>" +
		"부디 가끔씩 들러 그 이야기들을 들어 주시기 바랍니다.<br/><br/>" +
		"<span style='color:#B0B0B0;'><Strong>EQUIPMENT:</Strong></span><br/>" +
		"- camera : contax g2 set, contax tvs-digital<br />" +
		"- bicycles : alex moulton tsr, brompton m6p<br /><br />" +
		"<span style='color:#B0B0B0;'><Strong>SKILL:</Strong></span><br />" +
		"- language : java, c<br />" +
		"- middleware : skelmir cee-j, sk-vm, wipi java, embedded linux<br /><br />" +
		"<span style='color:#B0B0B0;'><Strong>SITE:</Strong></span><br />" +
		"- adobe flash, xhtml, dom, ajax";

	div_info.appendChild(pNode);		
	div_contract.appendChild(div_profile);
	div_contract.appendChild(div_info);
	flashcontent.appendChild(div_contract);
}

function blog () {
	state = 3; // 0 intro, 1 photograpy, 2 contract, 3 blog, 4 snap, 5 portrait, 6 landscape, 7 stage, 8, travel,
	init();
	
	win = new Window({id:"blog", className: "darkX", title: "", top:75, left: (document.body.clientWidth / 2) - (960 /2), width:960, height:700,
			resizable: false, minimizable: false, maximizable: false, draggable: false, closable:false,
			url: "http://www.hyouk.net/blog/"});
	win.show();
}

function resize() {
	if (document.getElementById("blog")) {
		win.showCenter(false, 75, (document.body.clientWidth / 2) - (960 /2));
	}
}

function returnState() {
	switch (state) {
		case 0:
			intro();
			break;
		case 1:
			photograpy();
			break;
		case 2:
			contract();
			break;
		case 3:
			blog();
			break;
		case 4:
			subNavSnap ();
			break;
		case 5:
			subNavPortrait ();
			break;
		case 6:
			subNavLandscape ();
			break;
		case 7:
			subNavStage ();
			break;
		case 8:
			subNavTravel ();
			break;
	}
}

