/*
-----------------------------------------------
tella inc. Global Content Javascript Functions
Author:   yoo t h (oortensia@hotmail.com)
Version: ver.1.1, 26 Mar 2009
----------------------------------------------- */

try { 
document.execCommand('BackgroundImageCache', false, true); 
} catch(e) {}

$(function (){
	attachPageTopEvents();
	attachScrollFollow();
	attachContentNavScrollEvents()
});


function attachPageTopEvents(){
	$('#pagetop > a').click(function(){
		$(this).blur();
		$('html,body').animate({ scrollTop: 0 }, 1000, 'easeOutQuart');
		return false;
	});	
}

function attachScrollFollow(){
	$('#scrollFollow').scrollFollow({speed: 1000, offset:0, easing:'easeOutQuart'});	
}

var currentNum = -1;
var prevNav = -1;
var contentNav = [false, false, false, false, false, false];

function unbindContentNav(pressNum2){
	prevNum = currentNum;
	currentNum = pressNum2;
	for(i=0; i<6; i++){
		contentNav[i] = false;
	}
	contentNav[pressNum2] = true;
	$("div.content-" + prevNum + "").fadeOut(400, function(){
		$(this).remove();
	});
}

function bindContentNav(pressNum){
	if(contentNav[pressNum] != true){
		$("#contentNav dd ul #cn" + pressNum).append('<div class="content-' + pressNum + '"></div>');
		$("div.content-" + pressNum + "").css({display:"none"}).fadeIn(250);
		unbindContentNav(pressNum);
	}
}

function attachContentNavScrollEvents(){		
	$('#cn0 a').click(function(){
		bindContentNav(0);
		var targetContent0 = $("#content0").offset().top;
		$(this).blur();
		$('html,body').animate({ scrollTop: targetContent0 }, 1000, 'easeOutQuart');
		return false;
	});
	$('#cn1 a').click(function(){
		bindContentNav(1);
		var targetContent1 = $("#content1").offset().top;
		$(this).blur();
		$('html,body').animate({ scrollTop: targetContent1 }, 1000, 'easeOutQuart');
		return false;
	});
	$('#cn2 a').click(function(){
		bindContentNav(2);
		var targetContent2 = $("#content2").offset().top;
		$(this).blur();
		$('html,body').animate({ scrollTop: targetContent2 }, 1000, 'easeOutQuart');
		return false;
	});
}