// position
function sideTop(){ 
	var top  = Math.floor(($(window).height() - $(".side").height()) / 2) - 10;  
	$(".side").css({top: top })
};



// position
function position(){  
		
	//side top
	var i = $(this).scrollTop();
	if ( i >= 980 ) {
		$(".prev a").fadeIn("slow");
	} else {
		$(".prev a").fadeOut("slow");
	}
	if ( i <= 12980 ) {
		$(".next a").fadeIn("slow");
	} else {
		$(".next a").fadeOut("slow");
	}
	
	if ( i < 980 ) {
		var link2 = "#concept";
	} else if ( i < 1980 ) {
		var link1 = "#home";
		var link2 = "#profile";
	} else if ( i < 3480 ) {
		var header= "li.profile a";
		var link1 = "#concept";
		var link2 = "#contents";
	} else if ( i < 5480 ) {
		var header= "li.contents a";
		var link1 = "#profile";
		var link2 = "#bizstyle";
	} else if ( i < 7480 ) {
		var header= "li.bizstyle a";
		var link1 = "#contents";
		var link2 = "#keyfactor";
	} else if ( i < 9980 ) {
		var header= "li.keyfactor a";
		var link1 = "#bizstyle";
		var link2 = "#casestudy";
	} else if ( i < 11980 ) {
		var header= "li.casestudy a";
		var link1 = "#keyfactor";
		var link2 = "#docs";
	} else if ( i < 13480 ) {
		var header= "li.docs a";
		var link1 = "#casestudy";
		var link2 = "#contact";
	} else if ( i < 14980 ) {
		var header= "li.contact a";
		var link1 = "#docs";
	}
	$(".prev a").attr("href",link1);
	$(".next a").attr("href",link2);
	$("#headerWrap li a").css({"background-position": "0 0" });
	$(header).css({"background-position": "0 -38px" });
	
	//side right
	var left = $(window).width() - 58;
	if( $(window).width() <= 1440 ) {
		$(".side").css({left: left });
	} else if ( $(window).width() > 1440 ) {
		left = ($(window).width() - 1440) / 2 + 1382;
		$(".side").css({left: left });
	}
		
};




//bgScroll
function bgScroll(){
	
	//Y setting
	var y = $(this).scrollTop();
	
	//X setting
	var x = $(window).width();
	if ( x > 1440 ) {
		x = 0;
	} else if ( x < 1024 ) {
		x =-208;
	} else {
		x = ($(window).width() - 1440) / 2;
	}
	
	$('#homeBg1').css('background-position', 'center ' + 'top');
	$('#homeBg2').css('background-position', 'center ' + -y / 2 + 'px');
	$('#homeBg3').css('background-position', 'center ' + y * 1.4  + 'px');
	
	var delta = y - 1000;
	$('#conceptBg1').css('background-position', 'center ' + -( delta + 200 ) / 300 + 'px');
	$('#conceptBg2').css('background-position', 'center ' + -delta / 0.2 + 'px');
	$('#conceptBg3').css('background-position', 'center ' + delta * 1.4 + 'px');
	
	var delta = y - 2000;
	$('#profileBg1').css('background-position', 'center ' + ( delta - 30 ) * 1.5 + 'px');
	$('#profileBg2').css('background-position', 'center ' + delta * 1.4 + 'px');
	$('#profileBg3').css('background-position', 'center ' + delta * 1.1 + 'px');
	$('#profileBg4').css('background-position', 'center ' + delta * 0.5 + 'px');
	$('#profileBg5').css("background-position", 'center ' + delta * -1.2+ 'px' );
	
	var delta = y - 3500;
	$('#contentsBg1').css('background-position', 'center ' + delta * 1.1 + 'px');
	$('#contentsBg2').css('background-position', 'center ' + -( delta + 500 ) / 7 + 'px');
	
	$('#contentsBg3').css("background-position", x + delta / 2 +'px ' + -delta / 0.5 + 'px');
	$('#contentsBg4').css('background-position', x + delta / 5 +'px ' + delta * 1.4 + 'px');
	$('#contentsBg5').css('background-position', 'center ' + -( delta - 300 ) / 2 + 'px');
	$('#contentsBg6').css('background-position', 'center ' + -( delta - 23000 ) / 20 + 'px');
	
	var delta = y - 5500;
	$('#bizstyleBg1').css('background-position', 'center ' + + ( delta - 50 ) * 1.05 + 'px');
	//$('#bizstyleBg2').css('background-position', 'center ' + ( delta - 335 ) * 1.1 + 'px');
	$('#bizstyleBg3').css('background-position', 'center ' + -delta / 4 + 'px');
	$('#bizstyleBg4').css('background-position', 'center ' + -delta / 10 + 'px');
	$('#bizstyleBg5').css('background-position', 'center ' + -delta / 0.3 + 'px');
	
	var delta = y - 7500;
	//$('#keyfactorBg1').css('background-position', 'center ' + 'bottom');
	$('#keyfactorBg2').css('background-position', 'center ' + delta * 1.1 + 'px');
	$('#keyfactorBg3').css('background-position', 'center ' + -( delta + 1000 ) / 3 + 'px');
	$('#keyfactorBg4').css('background-position', 'center ' + delta * 2 + 'px');
	
	var delta = y - 10250;
	$('#casestudyBg1').css('background-position', 'center ' + 'top ');
	$('#casestudyBg2').css('background-position', x + delta / 1 +'px ' + ( delta - 150 ) * 1.15 + 'px');
	$('#casestudyBg3').css('background-position', 'center ' + -delta / 4.5 + 'px');
	$('#casestudyBg4').css('background-position', x - delta / 1 +'px ' + -delta / 0.6 + 'px');
	
	var delta = y - 12250;
	$('#docsBg1').css('background-position', x + delta +'px 0px');
	$('#docsBg2').css('background-position', 'center ' + delta * 1.8 + 'px');
	$('#docsBg3').css('background-position', 'center ' + -delta * 0.1 + 'px');
	$('#docsBg4').css('background-position', x + -delta / 5 +'px ' + -delta * 1.7 + 'px');
	
	var delta = y - 13750;
	$('#contactBg1').css('background-position', 'center ' + -delta * 1.2 + 'px');
	$('#contactBg2').css('background-position', 'center ' + delta * 1.8 + 'px');
	$('#contactBg3').css('background-position', 'center ' + -delta * 0.6 + 'px');
};


//default
$(document).ready(function(){
	sideTop();
	position();
	//fancybox
	$("#profileWrap a").fancybox({
		'width'				: '75%',
		'height'			: '75%',
        'autoScale'     	: false,
        'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});
	$("#keyfactorWrap a").fancybox();
	$("#footerWrap a").fancybox({
		'width'				: '75%',
		'height'			: '75%',
        'autoScale'     	: false,
        'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});
}); 

//resize
$(window).resize(function(){
	sideTop();
	position();
	bgScroll();
});

//scroll
$(window).scroll(function(){ 
	position();
	bgScroll();
}); 




//news
$(function(){
	/*
	1. if there is this material, show 2
	2. material2
	3. height of material2
	4. showing speed of material2
	5. hiding speed of material2
	6. how many px from material1 for hiding material2
	*/
    DelayVisibleContents("#home", "#news", 25, 300, 300, 1280);
});
 
var DelayVisibleContents = function(t, c, h, d1, d2, m){
	var f = 0;
	$(c).css({height: 0}).hide();
	setInterval(function() {
	var tPs = $(t).offset().top;
	var wHt = $(window).height();
	var bSc = $(this).scrollTop() + wHt;
	if(f == 0 && (bSc > tPs && bSc - m < tPs)) {
		f++;
		$(c+":not(:animated)").css("display","block").animate({height:h+"px"},{"duration":d1,complete:function(){f++;}});
		} else if(f >= 2 && (bSc <= tPs || bSc - m >= tPs)) {
		f--;
		$(c+":not(:animated)").animate({height:"toggle"},{"duration":d2,complete:function(){$(this).css({height: 0}).hide();f--;}});
		}
	}, 300);
}





//easingscroll
$(function(){
	$("a[href*='#']").easingScroll({
		easing: "easeInOutExpo",
		duration: 2000
	});
});

//queryloader2
var IE6browser = (navigator.userAgent.indexOf("MSIE 6")>=0) ? true : false;
if(!IE6browser){
$(document).ready(function () {
    $("#profile").queryLoader2({
        barColor: "#241400",
        backgroundColor: "#000",
        barHeight: 5,
        completeAnimation: "fade"
    });
});
}
