/********************************************************************
Vricks Republic Publishing S&A
Author : Kim. Bo-Young
Beginning : 2010-02-26
Final : 2010-02-26
*********************************************************************/


//flash vars
function embedSwf(embedSwf, swfWidth, swfHeight, swfId, flaVars) {
	var flashValue = "";
	flashValue += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="' + swfWidth + '" height="' + swfHeight + '" id="' + swfId + '">\n';
	flashValue += '<param name="allowScriptAccess" value="always" />\n';
	flashValue += '<param name="allowFullScreen" value="true" />\n';
	flashValue += '<param name="movie" value="' + embedSwf + '" />\n';
	flashValue += '<param name="quality" value="high" />\n';
	flashValue += '<param name="wmode" value="transparent" />\n';
	flashValue += '<param name="flashvars" value="' + flaVars + '" />\n';
	flashValue += '<embed src="' + embedSwf + '" quality="high" wmode="transparent" width="' + swfWidth + '" height="' + swfHeight + '" name="'+ swfId +'" allowScriptAccess="always" allowFullScreen="true" flashvars="' + flaVars + '" />\n';
	flashValue += '</object>\n';
	document.write(flashValue);
}
//flash no vars
function embedSwfNoVars(embedSwf, swfWidth, swfHeight, swfId) {
	var flashValue = "";
	flashValue += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="' + swfWidth + '" height="' + swfHeight + '" id="' + swfId + '">\n';
	flashValue += '<param name="allowScriptAccess" value="always" />\n';
	flashValue += '<param name="allowFullScreen" value="true" />\n';
	flashValue += '<param name="movie" value="' + embedSwf + '" />\n';
	flashValue += '<param name="quality" value="high" />\n';
	flashValue += '<param name="wmode" value="transparent" />\n';
	flashValue += '<embed src="' + embedSwf + '" quality="high" wmode="transparent" width="' + swfWidth + '" height="' + swfHeight + '" name="'+ swfId +'" allowScriptAccess="always" allowFullScreen="true" />\n';
	flashValue += '</object>\n';
	document.write(flashValue);
}
//flash layer
function embedSwfFlashLayer(embedSwf, swfWidth, swfHeight, swfId, flaVars) {
	var flashValue = "";
	flashValue += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="' + swfWidth + '" height="' + swfHeight + '" id="' + swfId + '">\n';
	flashValue += '<param name="allowScriptAccess" value="always" />\n';
	flashValue += '<param name="allowFullScreen" value="true" />\n';
	flashValue += '<param name="movie" value="' + embedSwf + '" />\n';
	flashValue += '<param name="quality" value="high" />\n';
	flashValue += '<param name="flashvars" value="' + flaVars + '" />\n';
	flashValue += '<embed src="' + embedSwf + '" quality="high" width="' + swfWidth + '" height="' + swfHeight + '" name="'+ swfId +'" allowScriptAccess="always" allowFullScreen="true" flashvars="' + flaVars + '" />\n';
	flashValue += '</object>\n';
	document.write(flashValue);
}

function setPng24(obj) {
	obj.width = obj.height= 1;
	obj.className = obj.className.replace(/\bpng24\b/i,"");
	obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ obj.src +"',sizingMethod='image');";
	obj.src = "http://download.tera-online.com/images/blank.gif";
	return "";
}

function popClose(){
	$("#popLayer").remove();
}

function displayPop(objWidth, objHeight){
	$layer = $("#popLayer");
	var docWidth = $(document).width();
	var docHight = $(document).height()+$(document).scrollTop();

	var xpos = docWidth / 2 - objWidth / 2;
	var ypos = docHight / 2 - objHeight / 2;
	$layer
		.css("top", ypos + "px")
		.css("left", xpos + "px");
}

$(document).ready(function() {
	$(".openPop").click(function() {
		window.open($(this).attr("href"), "", "width=320, height=690");
		return false;
	});
	$(".openPopStory").click(function() {
		window.open($(this).attr("href"), "", "width=400, height=710");
		return false;
	});

	$(".popZipcode").click(function() {
		$("#popLayer").remove();
		$("<div id='popLayer' style='position:absolute; z-index: 100; '></div>").prependTo("body");
		$("#popLayer").load("../pop/zipcode.html");
		var objWidth = 380;
		var objHeight = 500;

		displayPop(objWidth, objHeight);
	});

	$(".popCheckupProg").click(function() {
		$("#popLayer").remove();
		$("<div id='popLayer' style='position:absolute; z-index: 100; '></div>").prependTo("body");
		$("#popLayer").load("../pop/examination.html");
		var objWidth = 430;
		var objHeight = 1180;

		displayPop(objWidth, objHeight);
	});

	$(".openFloorPlan").click(function() {
		$("#popLayer").remove();
		$("<div id='popLayer' style='position:absolute; z-index: 100; '></div>").prependTo("body");
		$("#popLayer").load("../pop/floorPlan.html");
		var objWidth = 800;
		var objHeight = 570;

		displayPop(objWidth, objHeight);
	});
	
	$(".openProcService").click(function() {
		$("#popLayer").remove();
		$("<div id='popLayer' style='position:absolute; z-index: 100; '></div>").prependTo("body");
		$("#popLayer").load("../pop/processService.html");
		var objWidth = 800;
		var objHeight = 920;

		displayPop(objWidth, objHeight);
	});
	
	$(".openProcItem").click(function() {
		$("#popLayer").remove();
		$("<div id='popLayer' style='position:absolute; z-index: 100; '></div>").prependTo("body");
		$("#popLayer").load("../pop/processItem.html");
		var objWidth = 450;
		var objHeight = 850;

		displayPop(objWidth, objHeight);
	});
	
	$(".openMedical1").click(function() {
		$("#popLayer").remove();
		$("<div id='popLayer' style='position:absolute; z-index: 100; '></div>").prependTo("body");
		$("#popLayer").load("../pop/medicalService1.html");
		var objWidth = 630;
		var objHeight = 510;

		displayPop(objWidth, objHeight);
	});
	
	$(".openMedical2").click(function() {
		$("#popLayer").remove();
		$("<div id='popLayer' style='position:absolute; z-index: 100; '></div>").prependTo("body");
		$("#popLayer").load("../pop/medicalService2.html");
		var objWidth = 630;
		var objHeight = 510;

		displayPop(objWidth, objHeight);
	});
	
	$(".openMedical3").click(function() {
		$("#popLayer").remove();
		$("<div id='popLayer' style='position:absolute; z-index: 100; '></div>").prependTo("body");
		$("#popLayer").load("../pop/medicalService3.html");
		var objWidth = 630;
		var objHeight = 510;

		displayPop(objWidth, objHeight);
	});
	
	$(".openMedical4").click(function() {
		$("#popLayer").remove();
		$("<div id='popLayer' style='position:absolute; z-index: 100; '></div>").prependTo("body");
		$("#popLayer").load("../pop/medicalService4.html");
		var objWidth = 630;
		var objHeight = 510;

		displayPop(objWidth, objHeight);
	});
	
	$(".openMedical5").click(function() {
		$("#popLayer").remove();
		$("<div id='popLayer' style='position:absolute; z-index: 100; '></div>").prependTo("body");
		$("#popLayer").load("../pop/medicalService5.html");
		var objWidth = 630;
		var objHeight = 510;

		displayPop(objWidth, objHeight);
	});

	$(".photoInfo li").hover(function() {
		var $over = $(this).find("img");
		var src = $over.attr("src");
		$prodImg = $(this).parent().parent().children(".photo");
		$prodImg.attr("src", src.replace(/thumb_/, "img_"));
	});

	$(".spaceImage").click(function() {
		$("#popLayer").remove();
		var _tit = $(this).attr("src").replace(/space_image_/, "pop_tit_space_");
		var _pho = $(this).attr("src").replace(/space_image_/, "space_image_l_");
		$("<div id='popLayer' style='position:absolute; z-index: 100; '><div class='pop'><div class='popT'><h4><img src='"+_tit+"' alt='' /></h4></div><div class='popB'><div class='popContainer'><div class='popContent'><img class='photo' src='"+_pho+"' alt='' /><div class='btnBox'><img class='popClose cursor' onclick='popClose()' src='../images/common/btn/btn_close.gif' alt='Ã¢´Ý±â' /><br clear='all'></div></div></div></div></div></div>").prependTo("body");
		var objWidth = 720;
		var objHeight = 450;

		displayPop(objWidth, objHeight);
	});

	$(".floorPlan").click(function() {
		$("#popLayer").remove();
		var _tit = $(this).attr("src").replace(/img_space_2_/, "pop_tit_floorPlan_");
		var _pho = $(this).attr("src").replace(/img_space_2_/, "floorPlan_");
		$("<div id='popLayer' style='position:absolute; z-index: 100; '><div class='pop'><div class='popT'><h4><img src='"+_tit+"' alt='' /></h4></div><div class='popB'><div class='popContainer'><div class='popContent'><img class='photo' src='"+_pho+"' alt='' /><div class='btnBox'><img class='popClose cursor' onclick='popClose()' src='../images/common/btn/btn_close.gif' alt='Ã¢´Ý±â' /><br clear='all'></div></div></div></div></div></div>").prependTo("body");
		var objWidth = 720;
		var objHeight = 450;

		displayPop(objWidth, objHeight);
	});

	$(window).scroll(function() {
		var $quick = $("#quickArea");
		var speed = 1000;

		var gnb_h = 220;
		var visual_h = $("#visual").height();
		var foot_h = $("#footer").height();
		var obj_h = $quick.height();
		var doc_h = $(document).height();

		var obj_mar = 220;
		var obj_top = gnb_h + visual_h;
		var doc_top = $(document).scrollTop();

		if(doc_h > doc_top + obj_h + foot_h + (obj_mar * 2) ) {
			if(doc_top < obj_mar) {
				$quick.stop().animate({top: obj_mar + doc_top }, speed);
			} else if(doc_top > obj_top) {
				$quick.stop().animate({top: obj_mar + doc_top - obj_top }, speed);
			}
		}
	});	

	var $quest = $(".faqList .quest");
	$quest.next().addClass("hidden")
	$(".answer").addClass("noLine")
	$quest.addClass("cursor");

	$quest.toggle(function() {
		$(this).find("th a").addClass("bold");

		var answer = $(this).next();
		answer.toggleClass("hidden");
		answer.toggleClass("noLine");

		return false;
	}, function() {
		$(this).find("th a").removeClass("bold");

		var answer = $(this).next();
		answer.toggleClass("hidden");
		answer.toggleClass("noLine");

		return false;
	});

	try{
		$("#provision").load("../common/html/provision.html");
	}
	catch(e){}

	$(".spacePoint").hover(function() {
		var src = ($(this).attr("id")).replace(/space_/, "space_image_")+".gif";
		$(".spaceImage").attr("src", "../images/interInfo/"+src);
	});

	$('.opener').hover(function(event) {
		mouseX = event.pageX+20;
		mouseY = event.pageY-40;
		$('#dialog')
		.css("top", mouseY + "px")
		.css("left", mouseX + "px");

		$('#dialog').removeClass("hidden");

		return false;
	}, function() {
		$('#dialog').addClass("hidden");
	});
});
