function flashWrite(url,w,h,id,vars,bg,win){
	if(id==null) id=url.split("/")[url.split("/").length-1].split(".")[0]
	if(vars==null) vars='';
	if(bg==null) bg='#FFFFFF';
	if(win==null) win='transparent';	
	
	var flashStr= "	<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000'";
		flashStr+="		codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,124,0'";
		flashStr+="		width='"+w+"'";
		flashStr+="		height='"+h+"'";
		flashStr+="		id='"+id+"'";
		flashStr+="		align='middle'>";

		flashStr+="		<param name='allowScriptAccess' value='always' />";
		flashStr+="		<param name='movie' value='"+url+"' />";
		flashStr+="		<param name='FlashVars' value='"+vars+"' />";
		flashStr+="		<param name='wmode' value='"+win+"' />";
		flashStr+="		<param name='menu' value='false' />";
		flashStr+="		<param name='quality' value='high' />";
		flashStr+="		<param name='bgcolor' value='"+bg+"' />";
	
		flashStr+="		<embed src='"+url+"'";
		flashStr+="		       flashVars='"+vars+"'";
		flashStr+="		       wmode='"+win+"'";
		flashStr+="		       menu='false'";
		flashStr+="		       quality='high'";
		flashStr+="		       bgcolor='"+bg+"'";
		flashStr+="		       width='"+w+"'";
		flashStr+="		       height='"+h+"'";
		flashStr+="		       name='"+id+"'";
		flashStr+="		       align='middle'";
		flashStr+="		       allowScriptAccess='always'";
		flashStr+="		       type='application/x-shockwave-flash'";
		flashStr+="		       pluginspage='http://www.macromedia.com/go/getflashplayer' />";
		flashStr+=" </object>";	
	document.write(flashStr);
}
//png24
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=''; 
    return '';
}
var isie6=(navigator.userAgent.toLowerCase().indexOf('msie 6')!=-1);
if(navigator.userAgent.toLowerCase().indexOf('msie 7')!=-1){
	isie6 = false;
	var isie7 = true;
}
var isie8=(navigator.userAgent.toLowerCase().indexOf('msie 8')!=-1);
var isfirefox=(navigator.userAgent.toLowerCase().indexOf("firefox")!=-1);
var isSafari =(navigator.userAgent.toLowerCase().indexOf("safari")!=-1);
if(navigator.userAgent.toLowerCase().indexOf('chrome')!=-1){
	isSafari=false;
	var ischrome=true;
}
var isopera=(navigator.userAgent.toLowerCase().indexOf("opera")!=-1);
window.onscroll=function(){
	if(!isie6){
		var aside = document.getElementById('quick');
		if(aside){			
			var objTop = 97;
			//var newtop = -333;
			var newtop = -200;
			
			if(isie7) aside.style.background='none';			
			var viewportScroll = (document.documentElement) ? ((document.body.scrollTop == 0) ? document.documentElement.scrollTop : document.body.scrollTop) : document.body.scrollTop;	
			
			if(viewportScroll<=0){
				aside.style.top=objTop+'px';
			}else{
				var top=objTop-viewportScroll;
				aside.style.top=(top>newtop)? top+'px' : newtop+'px';
			}
		}
	}
}
function asidePositionForie6(){
	var viewportScroll = (document.documentElement) ? document.documentElement.scrollTop : document.body.scrollTop;		
	var objTop = 97;
	//var newtop = -333;
	var newtop = -200;
	
	if(viewportScroll<=0) rtop=objTop;
	else{
		var top=objTop-viewportScroll;
		rtop=(top>newtop)? top : newtop;
	}
	return rtop + viewportScroll + "px";
}

function drawSelect(){
	$('select').uds({
		newClass:'uds',
		limitLength : 10,
		rSpace:35
	});
}

function drawRadio(){
	$(':radio').udr({
		radioImgOn          : '/images/udr_on.gif',
		radioImgOff         : '/images/udr_off.gif',
		radioImgOnDisabled  : '/images/udr_on_disabled.gif',
		radioImgOffDisabled : '/images/udr_off_disabled.gif'
	});	
}

// images rollover
function initRollovers() {
	if (!document.getElementById) return
	
	var aPreLoad = new Array();
	var sTempSrc;
	var aImages = document.getElementsByTagName("img");

	for (var i = 0; i < aImages.length; i++) {		
		if (aImages[i].className == "imgover") 	{
			var src = aImages[i].getAttribute("src");
			var ftype = src.substring(src.lastIndexOf("."), src.length);
			var hsrc = src.replace(ftype, "_on"+ftype);
	
			aImages[i].setAttribute("hsrc", hsrc);
			
			aPreLoad[i] = new Image();
			aPreLoad[i].src = hsrc;
			
			aImages[i].onmouseover = function() {
				sTempSrc = this.getAttribute("src");
				this.setAttribute("src", this.getAttribute("hsrc"));
			}	
			
			aImages[i].onmouseout = function() {
				if (!sTempSrc) sTempSrc = this.getAttribute("src").replace("_on"+ftype, ftype);
				this.setAttribute("src", sTempSrc);
			}
		}
	}
}

// Tab Content
function initTabMenu(tabContainerID) {
	var tabContainer = document.getElementById(tabContainerID);
	var tabAnchor = tabContainer.getElementsByTagName("a");
	for(i=0; i<tabAnchor.length; i++) {
		if (tabAnchor.item(i).className == "tab")
			thismenu = tabAnchor.item(i);
		else
			continue;

		thismenu.container = tabContainer;
		thismenu.targetEl = document.getElementById(tabAnchor.item(i).href.split("#")[1]);
		thismenu.targetEl.style.display = "none";
		thismenu.imgEl = thismenu.getElementsByTagName("img").item(0);
		thismenu.onclick = function tabMenuClick() {
			currentmenu = this.container.current;
			if (currentmenu == this)
				return false;

			if (currentmenu) {
				currentmenu.targetEl.style.display = "none";
				if (currentmenu.imgEl) {
					currentmenu.imgEl.src = currentmenu.imgEl.src.replace("_on.gif", ".gif");
				}
				currentmenu.className = currentmenu.className.replace(" on", "");
			}
			
			this.targetEl.style.display = "block";
			if (this.imgEl) {
				this.imgEl.src = this.imgEl.src.replace(".gif", "_on.gif");
			}
			this.className += " on";
			this.container.current = this;
			return false;
		};
		if (!thismenu.container.first) thismenu.container.first = thismenu;
	}
	if (tabContainer.first) tabContainer.first.onclick();
}

// popup
function popup(url,width,height){
	var filename = url.split(".asp")[0];
	var name = filename.split("/")[filename.split("/").length-1]; 
	window.open(url,name,'width='+width+', height='+height+', scrollbars=no');
}

// KIC
function facility() {
	$('.facilitylist a').click(function(){
		thistarget = $(this).attr('href');
		$(thistarget).fadeIn();
		return false;
	});
	$('.close').click(function(){
		$(this).parent().fadeOut('fast');
	});
}

// F1 world
function rule(){
	$('#ruleTab').tab();
	$hideEl = $('[id^=rule2_]');
	$hideEl.hide();
	$hideEl.eq(0).show();
	$('#select').change(function(){
		$hideEl.hide();
		var thisid = $(this).val();
		$('#'+thisid).show();
	});
}

function iframeResize(iframe_id) {
	var h = (self.innerHeight) ? document.documentElement.offsetHeight : document.body.scrollHeight;
	try{
		parent.document.getElementById(iframe_id).style.height = h+"px";
	}catch(e){}
}

// gnb setting
function resizeGNB(h){	
//	alert(h);
	$('#submenu').attr({'height':h});
	$('embed[name=submenu]').attr({'height':h});
}

/* 
function setGnb_forIE6(){
	if(isie6){
		var main = document.getElementById('mainWrap');
		var gnb = document.getElementById('gnb');
		if(main){
			//alert('main');
			if(main.offsetWidth < 990){main.style.width = '990px'};
			if(main.offsetHeight < 780){main.style.height = '780px'};
			// onresize°¡ ie6.0.2900.5512 (sp3)¿¡¼­ ¹ö±× ¹ß»ý.
			window.onresize = function(){
				if(main.offsetWidth < 980){main.style.width = '980px'} else {main.style.width="100%";}
				if(main.offsetHeight< 780){main.style.height = '780px'} else {main.style.height="100%";}
			};
		} else if(gnb){
			if(gnb.offsetWidth < 940) {gnb.style.width = '940px';};
			window.onresize = function(){
				if(gnb.offsetWidth < 940) {gnb.style.width = '940px';} else {gnb.style.width="100%";}
			};
		}
	}
}
*/

function setGnb_forIE6(){
	var gnb = document.getElementById('gnb');
	if(isie6&&gnb){
		if(gnb.offsetWidth < 940) {gnb.style.width = '940px';};
		window.onresize = function(){
			if(gnb.offsetWidth < 940) {gnb.style.width = '940px';} else {gnb.style.width="100%";}
		};
	}
}

function redefineFlashWH_main(w, h){
	var parentObj  = document.getElementById('mainWrap');
	var targetObj  = document.getElementById('main');
	
	var fixWidth   = 990;
	var fixHeight  = 780;
	var userWidth  = document.documentElement.clientWidth;
	var userHeight  = document.documentElement.clientHeight;
	var widthBool  = false;
	var heightBool  = false;

	if(w == undefined) { w = fixWidth; }
	if(w <= fixWidth) if(userWidth <= fixWidth) widthBool = true;

	if(h == undefined) { h = fixHeight; }
	if(h <= fixHeight) if(userHeight <= fixHeight) heightBool = true;

	if(widthBool) {
//		targetObj.width = fixWidth;
		parentObj.style.width = fixWidth + "px";
	} else {
//		targetObj.width = userWidth;
		parentObj.style.width ="auto";
	};

	if(heightBool) {
//		targetObj.height = fixHeight;
		parentObj.style.height = fixHeight + "px";
	} else {
//		targetObj.height = userWidth;
		parentObj.style.height = "100%";
	}
}

function regInterval(){
//	alert();
	if(document.getElementById('mainWrap')) intervalVariable = setInterval("redefineFlashWH_main()",50);
}

function qucikShow(){
	var topbtn = document.getElementById('quickMenu');
	var contentH = $('#content').height();
	if(contentH > 100) {
		topbtn.style.display = 'block';
	}
}

function tabJSON(targetWrapId,jsonData,interval){	
	var dataLen = jsonData.length-1;
	var idx = Math.floor(Math.random() * (dataLen));
	var isover = false;
	
	var tabMenu = '<ul class="pagingTab">\n';
	for(var i = 0 ; i < dataLen ; i++){
		tabMenu += '<li title="' + (i+1) + '">' + (i+1) + '</li>\n'
	}
	tabMenu += '</ul>';
	$('#'+targetWrapId).append(tabMenu);
	$('#'+targetWrapId+' .pagingTab li').eq(idx).addClass('on');
	
	var holder = '#'+targetWrapId+' .contHolder';
	$(holder).html("<p><a href='"+jsonData[idx].url+"'><img src='"+jsonData[idx].img+"' alt='"+jsonData[idx].alt+"' width='236' height='68'></a></p>");
	
	$('#'+targetWrapId).hover(function(){isover = true;},function(){isover = false;})	
	$('#'+targetWrapId+' .pagingTab li').css('cursor','pointer').mouseover(goTo);
	if(interval > 0) setInterval(function(){autoPlay()}, interval);
	
	function autoPlay(){if(isover) return;next();}
	function next(){idx++;draw();}	
	function goTo(){var selIdx = $(this).text();draw(selIdx);}
	function draw(sel){		
		idx = (sel) ? sel-1 : idx;		
		if(idx == dataLen) idx = 0;
		
		$('#'+targetWrapId+' .pagingTab li').removeClass('on').eq(idx).addClass('on');
		$(holder + ' img')
			.attr('src',jsonData[idx].img)
			.attr('alt',jsonData[idx].alt);
		$(holder + ' a').attr('href',jsonData[idx].url);
	}
}


$(function(){
	$('input[type=text]').addClass('inputText');
	setGnb_forIE6();
	qucikShow();
})