﻿/*
	파일명	: common.js
	작성일	: 2012.01.04
	코멘트	: 공통 스크립트를 작성한다.
*/
$(document).ready(function(){

	// 화면 전체를 페이드인 하기전에 hide시킨다.
	$('#wrap').hide();

	// CSS이미지를 preload한다.
	$.preloadCssImages();

	// 말풍선을 바운스 시킨다.
	var bouncespeed = 500;
	$('a[class!=url][class!=tca-honor-design non-html][class!=tca-site-day non-html][class!=tca-site-month non-html]').each(function(){
		$(this).css({backgroundPosition: '5px 5px'});
		bounce(this);
	});

	// 대상을 바운스 시킨다.
	function bounce(currentA) {
		newx = Math.floor(10*Math.random());
		newy = Math.floor(10*Math.random());
		newspeed = bouncespeed + Math.floor(100*Math.random());
		$(currentA).animate({backgroundPosition: newx + 'px ' + newy + 'px'}, newspeed, 'linear', function() { bounce(currentA);});
	}

	// 레이어 팝업 호출 (ColorBox call)
	$(".colophon-call").colorbox({width:"460px", inline:true, href:"#colophon-inner"});
	$(".community-call").colorbox({width:"460px", inline:true, href:"#community-inner"});
	$(".map-call").colorbox({width:"460px", inline:true, href:"#map-inner"});
	$(".team-call").colorbox({width:"460px", inline:true, href:"#team-inner"});
	//$(".video-call").colorbox({width:"460px", inline:true, href:"#video-inner"});
	$(".portfolio-call").colorbox({width:"460px", inline:true, href:"#portfolio-inner"});
	$(".portfolio-call").click(function(){
		$(".portfolio-call").colorbox({width:"460px", inline:true, href:"#portfolio-inner"});
	});
	$(".introduce-call").colorbox({width:"460px", inline:true, href:"#introduce-inner"});

	// 화면 전체를 페이드인 한다.
	$('#wrap').fadeIn(1000);

	// 스크롤 좌표값을 가져온다.
	if(navigator.appName == "Microsoft Internet Explorer"){
		var position = document.body.scrollTop;
	} else{
		var position = window.pageYOffset;
	}

	//서서히 스크롤이 되면서 화면 하단이 보여진다.
	var scrollToX = $(window).height();
	if(position < scrollToX) {
		$('html, body').animate({ scrollTop: scrollToX }, 3500, 'easeInOutExpo');

		var posY = Math.floor(1000 * Math.random());

		// 0.2초마다 스크롤의 좌표를 체크하여 맨 하단에 위치했을시 스크롤링을 정지한다.
		var tId = setInterval(function(){
			if( posY != parseInt($('html').scrollTop()) ){
				posY = parseInt($('html').scrollTop());
			} else if( posY == parseInt($('html').scrollTop()) ){
				$('html, body').stop();
				clearInterval(tId);
			}
		},200);
	}

	// 새창 띄우기
	$("a.non-html").click(function(){
		newWindow($(this).attr("href"),"","","",1,1,1,1,1,1,0);
		return false;
	});

	//Pagination Initialize
	pagination("#team-inner", teamCnt);
	pagination("#portfolio-inner", portCnt);

	function pagination(obj, objCnt){
		$(obj).find("ul li:gt("+ (objCnt-1) +")").hide();
		$(obj).find(".pagination a").click(function(){
			var num 	= parseInt($(this).html());
			var loopCnt = (num-1)*objCnt;
			$(obj).find("ul li").hide();
			for(var i=0; i<objCnt; i++, loopCnt++){
				$(obj).find("ul li:eq("+loopCnt+")").show();
			}
			return false;
		});
	}
});

/*
	함수명	: 팝업띄우기
	인자값	: newWindow(URL, 윈도우 이름, 윈도우 가로 사이즈, 윈도우 세로 사이즈, 스크롤바 유무, 리사이징 유무, 메뉴바 유무, 툴바 유무, 주소창 유무, 상태표시바 유무, 풀스크린 유무)
	사용예	: <a href="popup.html" target="_blank" onclick="newWindow(this.href,'popup',810,400,0,0,0,0,0,0,0); return false;">
*/
function newWindow(a_str_windowURL, a_str_windowName, a_int_windowWidth, a_int_windowHeight, a_bool_scrollbars, a_bool_resizable, a_bool_menubar, a_bool_toolbar, a_bool_addressbar, a_bool_statusbar, a_bool_fullscreen) {
	var int_windowLeft 			= (screen.width		- a_int_windowWidth) 	/ 2;
	var int_windowTop 			= (screen.height 	- a_int_windowHeight) 	/ 2;
	var str_windowProperties 	= "height="+ a_int_windowHeight +",width="+ a_int_windowWidth +",top="+ int_windowTop +",left="+ int_windowLeft +",scrollbars="+ a_bool_scrollbars +",resizable="+ a_bool_resizable +",menubar="+ a_bool_menubar +",toolbar="+ a_bool_toolbar +",location="+ a_bool_addressbar +",statusbar="+ a_bool_statusbar +",fullscreen="+ a_bool_fullscreen + "";
	var obj_window 				= window.open(a_str_windowURL, a_str_windowName, str_windowProperties);
	if (parseInt(navigator.appVersion) >= 4) {
		//obj_window.window.focus();
	}
	return false;
}
