var j$ = jQuery.noConflict();
 
j$(function(){

	// Reset Default Supersized Options
	j$.fn.supersized.options = {  
		startwidth: 640, startheight: 480,
		vertical_center: 1,
		slideshow: 0, navigation: 0, transition: 0, pause_hover: 0, slide_counter: 0, slide_captions: 0 
	};
	
	// init Supresized
	j$('#supersize').supersized();

	// init Animation & Cookie
	var repeat_flag = j$.cookie('repeat');

	if(repeat_flag == 1) {
		initFinishAnimation();
		//removeCookie();
	} else {
		setTimeout("initFooter()",2000);
		setCookie();
	}
 
	// init Show-Hide Btns
	j$('#btn-show > a').click(function(){ switchContents("show"); });
	j$('#btn-hide > a').click(function(){ switchContents("hide"); });
	
	var browserheight = j$(window).height();
	j$('#content').css("height", browserheight);
		
	j$(window).bind("resize", function(){
		var browserheight = j$(window).height();
		j$('#content').css("height", browserheight);
	});

});

/* ------------------------------------

   Fnc.Initial Animations

   ------------------------------------ */
	// #nav-switcher, #footer
	function initFooter() {
 		j$('#footer').animate({ 
			  bottom: "0px",
			  opacity: 1
 		}, 500, initNav);
		
		var index_flag = j$.cookie('index');
		if(index_flag != 1) {
			j$('#logo').stop().css("display", "block").animate({ top: "0" }, 800);
		}
	}
 
	// #nav
	function initNav() {
		j$('#nav').animate({ width: "100%" }, 1000, initNavBtns);
	}

	// #nav-global, #nav-sketch
	function initNavBtns() {
		/*j$('#nav-global > li').each(function(){
			j$(this).show();
		});*/
 
		// Delay Show Elements
		var globalBtnNum = j$('#nav-global > li').size();
 
		for(i=0; i < globalBtnNum; i++) {
			var indexNum = i+1;
			setTimeout(function() {
				var target = "#nav-global > li:nth-child("+ indexNum +")";
				return function() { j$(target).fadeIn('slow'); };
			}(), 500 * indexNum);
		}
 
		j$('#nav-sketch').show().animate({ right: "0px", top: "15px" }, 1000, initSwitcher);
		j$('#nav, #footer, #header').css("minWidth", "960px");
	}
	
	// #nav-switcher
	function initSwitcher() {
 		j$('#nav-switcher').show().animate({ top: "0px" }, 500, initContent);
	}
	
	// If Cookie exist, All animation sets finished.
	function initFinishAnimation() {
		j$('#footer').stop().css("opacity","1").css("bottom","0px");
		j$('#nav').stop().css("width","100%").css("bottom","25px");
		j$('#nav, #footer, #header').css("minWidth", "960px");
		j$('#nav-global > li').stop().css("display", "block");
		j$('#nav-sketch').stop().css("display", "block").css("right","0px").css("top","15px");
		j$('#nav-switcher').stop().css("display", "block").css("top","0px");
		
		var index_flag = j$.cookie('index');

		if(index_flag == 0) {
			j$('#logo').stop().css("display", "block").css("top","0px");		
		} 
		
		// init Page Contents
		initContent();
	}

/* ------------------------------------

   Fnc.Show-Hide Switch

   ------------------------------------ */
	function switchContents(str) {
		if(str == "show"){
			j$('#footer').stop().animate({ bottom: "0px" }, 800);
			j$('#nav').stop().animate({ bottom: "25px" }, 800);
			
			var index_flag = j$.cookie('index');

			if(index_flag == 1) {
				setTimeout(function() {
					return function() { 
						j$('#logo').stop().fadeIn('slow');
					};
				}(), 800);
				
			} else {
				j$('#logo').stop().animate({ top: "0px" }, 800);
			}
			
			setTimeout(function() {
				return function() { j$('#article').stop().fadeIn('slow'); };
			}(), 800);
			
		} else {
			j$('#article').stop().fadeOut('slow');
			
			var index_flag = j$.cookie('index');
			
			if(index_flag == 1) {
				j$('#logo').stop().fadeOut('slow');
			} else {
				setTimeout(function() {
					return function() { 
						j$('#logo').stop().animate({ top: "-75px" }, 800);
					};
				}(), 800);
			}
			
			setTimeout(function() {
				return function() { 
					j$('#footer').stop().animate({ bottom: "-25px" }, 800);
					j$('#nav').stop().animate({ bottom: "-75px" }, 800);
				};
			}(), 800);
		}
		return false;
	}

/* ------------------------------------

   Fnc.Cookie

   --------------------------------------- */
	function setCookie() { j$.cookie("repeat", 1, { expires:1 }); }
	function removeCookie() {
		j$.cookie('repeat', '', { expires:-1 });
		j$.cookie('index', '', { expires:-1 });
	}
	
	