
/*	TENKY Javascript
--------------------------------------------------------- */

/*	move background around
-------------------------------------- */
$.fn.moveBgAround = function() {
	var x = Math.floor(Math.random()*801);
	var y = Math.floor(Math.random()*401);
	var timea = Math.floor(Math.random()*101) + 1500;
	$('#panel-first .scroll-bg')
		.animate({ backgroundPosition: '(' + (x * -1) + 'px ' + (y * -1) + 'px)' }, timea, 'easeInOutExpo', function() {
			$.fn.moveBgAround();
	});
}

/*	making hash
-------------------------------------- */
function split_param() {
	var obj = new Object;
	var pair = location.search.substring(1).split('&');
	for (i = 0; pair[i]; i++) {
		var dim = pair[i].split('=');
		obj[dim[0]] = dim[1];
	}
	return obj;
}

/*	user agent
-------------------------------------- */
var uagent = (function() {
	return {
		ltIE6:typeof window.addEventListener == "undefined" && typeof document.documentElement.style.maxHeight == "undefined",
		ltIE7:typeof window.addEventListener == "undefined" && typeof document.querySelectorAll == "undefined",
		ltIE8:typeof window.addEventListener == "undefined" && typeof document.getElementsByClassName == "undefined",
		ie:document.uniqueID,
		firefox:window.globalStorage,
		opera:window.opera,
		webkit:!document.uniqueID && !window.opera && !window.globalStorage && window.localStorage,
		mobile:/android|iphone|ipad|ipod/i.test(navigator.userAgent.toLowerCase())
		}
	})();



/*	load after window
--------------------------------------------------------- */
$(document).ready(function() {

/*	move background around
--------------------------------------------------------- */
	lateLoad_moveBgAround();
	function lateLoad_moveBgAround() {
		$('#panel-first .scroll-bg').css( {
			backgroundImage: 'url(./images/slider/tree_bg.jpg)',
			backgroundRepeat: 'repeat'
		}).moveBgAround();
	}

/*	simple slider settings
--------------------------------------------------------- */
	$('#main-slider').simpleLoopSlider({
		interval  : 6000,
		duration  : 750,
		easing: 'easeInOutExpo'
	});

/*	logo transration
--------------------------------------------------------- */
	$('#logosprite')
		.css( { backgroundPosition: '0px 0px'} )
		.mouseover(function() {
			$(this).stop().animate({ backgroundPosition: '(0px -55px)' }, { duration:150 })
		})
		.mouseout(function() {
			$(this).stop().animate({ backgroundPosition: '(0px 0px)' }, { duration:150, complete:function() {
				$(this).css({ backgroundPosition: '0px 0px' })
			}})
		});


/*	global navigation
--------------------------------------------------------- */
	$('#global-navigation li').hover(
		function () {
			//show its submenu
			$('ul:not(:animated)', this).slideDown(150);
		},
		function () {
			//hide its submenu
			$('ul', this).slideUp(150);
		}
	);


/*	view style
--------------------------------------------------------- */
//	$('.eq-height-news').flatHeights();
	$('#logosprite').divlinker();
	$('a').focus(function(){ this.blur(); });


/*	table style
--------------------------------------------------------- */
	$('table.pf-table-style').each(function(i) {
		$('th:not(:last)', this).addClass('vcolored');
		$('th:last', this).addClass('vcolored-last');
	});


/*	twipsy
--------------------------------------------------------- */
	$('a[rel=appendix]' + '.twipsy-above').twipsy({ placement: 'above', live: true });
	$('a[rel=appendix]' + '.twipsy-below').twipsy({ placement: 'below', live: true });
	$('a[rel=appendix]' + '.twipsy-left' ).twipsy({ placement: 'left',  live: true });
	$('a[rel=appendix]' + '.twipsy-right').twipsy({ placement: 'right', live: true });


/*  sidemenu effect
--------------------------------------------------------- */
	$('#tab-menu li a').hover(function() {
		$(this).not(':animated').animate({
			paddingLeft : '17px'
		}, 200);
	},
	function () {
		$(this).animate({
			paddingLeft : '12px'
		}, 200);
	}, 200);


/*  vertical page scrolling
--------------------------------------------------------- */
	$('a[href^=#]').click(function() {
		var href= $(this).attr("href");
		var t = $(href == "#" || href == "" ? 'html' : href);
		var position = t.offset().top;
		$((uagent.webkit  ? 'body' : 'html')).animate({ scrollTop: position }, { duration: 'normal', easing: 'easeInOutExpo', });
		return false;
	});


/*	current page
--------------------------------------------------------- */
	var str_fn = $.url().attr('file');
	switch (str_fn) {

/*	index.html - startup
--------------------------------------------------------- */
	case "index.html":
		$('a#return-index').children().unwrap();
		break;


/*	portfolio - startup
--------------------------------------------------------- */
	case "company.html":
		var param = split_param();
		var target_tab = parseInt(param.tab);
		if ((target_tab != parseInt(target_tab, 10)) || (target_tab < 0 || target_tab > 4))	target_tab = 0;
		$('#tab-content div.tab:eq(' + target_tab + ')').addClass('selected');
		$('#tab-content div.tab').css('display', 'none'); //Show first tab content
		$('#tab-content div.tab.selected').show();
		
		$('#tab-menu li:eq(' + target_tab + ')').addClass('selected');
		
		// --- .tab effect
		$('#tab-menu ul li a').click(function() {
			var new_tab = $('#tab-content div.tab:eq(' + $('#tab-menu ul li a').index(this) + ')' );
			if ($(new_tab).css('display') == 'none') {
				$('#tab-content div.tab.selected').slideUp('slow').removeClass('selected');
				$(new_tab).slideDown('slow').addClass('selected');
				
				$('#tab-menu li.selected').removeClass('selected');
				$(this).closest('li').addClass('selected');
			}
		});
		
		// --- team style (fancybox)
		$('a.fancybox').fancybox({
			'titleShow' : 'true',
			'titlePosition' : 'over',
			'cyclic' :  'true'
		});
		
		$('.mosaic-bar2').mosaic({
			animation	:	'slide'		// fade or slide
		});
		
		break;


/*	jobs - startup
--------------------------------------------------------- */
	case "jobs.html":
		var param = split_param();
		var target_job = parseInt(param.job);
		if (target_job == parseInt(target_job, 10)) {
			if (target_job < 0 || target_job > 5)	target_job = 0;
			var position = $(".select-jobs").eq(target_job).offset().top;
			$((uagent.webkit  ? 'body' : 'html')).animate({ scrollTop: position }, { duration: 'normal', easing: 'easeInOutExpo', });
		}
		
		// --- floating menu
		$('.flath').flatHeights();
		$('#sidebar').containedStickyScroll({
			duration: 500,
			easing: 'easeInOutExpo',
			unstick: true
		});
		
		// --- smooth vertical page scrolling
		$(".item-jobs").click(function () {
			var t = $(".item-jobs").index(this)
			var position = $(".select-jobs").eq(t).offset().top;
			$((uagent.webkit  ? 'body' : 'html')).animate({ scrollTop: position }, { duration: 'normal', easing: 'easeInOutExpo', });
			return false;
		});
		
		// --- goto top
		$(".goto_top").click(function () {
			$((uagent.webkit  ? 'body' : 'html')).animate({ scrollTop: 0 }, { duration: 'normal', easing: 'easeInOutExpo', });
			return false;
		});
		
		// --- sample (fancybox)
		$('a.3dsample-swf').fancybox( {
			'padding'   : 10,
			'width' : 640,
			'height' : 480,
			'autoScale' : false,
			'type' : 'swf',
			'swf' : { 'wmode':'transparent', 'allowfullscreen':'true' },
			'overlayColor' :'#fff',
			'overlayOpacity' : .8,
			'titleShow' :'false'
		});
		$('a.3dsample-image').fancybox({
			'titleShow' : true,
			'titlePosition' : 'over'
		});
		
		break;
	
	// --- switch end
	}

/*	end of script
--------------------------------------------------------- */
});	//end of document .ready

