// navigation
if(typeof jQuery !== 'undefined'){
	$(function(){
		// sub nav
		if($('body').is('.neogames')){
			var depth, mkey, skey, timer;
				depth = $('.neogames').attr('class');
				depth = (depth.substr(depth.lastIndexOf(" ")+1)).split("_");
				mkey = depth[0];
				skey = depth[1];
			
			// menu hover
			$('#neo_navi a').hover(function(){
				$(this).addClass('over');
			},function(){
				$(this).removeClass('over');
			});
		
			// menu activate
			var menuActivate = function(){
				$('#neo_navi .depth ol').css('display','none').children('a').removeClass('on');
				$('#neo_navi .depth .'+mkey).css('display','block')
				.parent().children('p').children('a').addClass('on').end().end().end()
				.children('li:nth-child('+skey+')').children('a').addClass('on');
			}
			menuActivate();
				
			// menu action
			$('#neo_navi .depth>li').hover(function(){
				$('#neo_navi .depth ol').css('display','none');
				$('#neo_navi .depth a').removeClass('on');
				$('#neo_navi ol.'+$(this).children('p').children('a').attr('title'))
				.parent().children('p').children('a').addClass('on').end().end().end()
				.css('display','block').hover(function(){
					$(this).parent().children('p').children('a').addClass('on');
				},function(){
					$(this).parent().children('p').children('a').removeClass('on');
					//menuActivate();
				});
			},function(){
				$('#neo_navi .depth a').removeClass('on');
				menuActivate();
			});
		}
	});
}

$(function(){
	//global link
	$('.sidemenu .global').hover(function(){
		$('.sidemenu .global li').hide();											  
		$('.sidemenu .global').addClass('over');
		$('.sidemenu .global li').show();
	},function(){
		$('.sidemenu .global').removeClass('over');
		$('.sidemenu .global li').hide();
	});
});


// tab ych
function setTab(name, n) {
	var tabs = $('.' + name).get();
	var btn = tabs[0].getElementsByTagName('A');
	for (var i=1; i<tabs.length; i++) {
		if (tabs[i]) {
			$(tabs[i]).fadeOut('slow');
		}
	}
	if (tabs[n]) {
		$(tabs[n]).fadeIn('slow');
	}
}

function menuTab(name, n) {
	var tabs = getElementByClass(name);
	var btn = tabs[0].getElementsByTagName('A');
	for (var i=1; i<tabs.length; i++) {
		if (tabs[i]) {
			tabs[i].style.display = 'none';
		}
	}
	if (tabs[n]) {
		tabs[n].style.display = 'block';
	}
}

// ÅÇµ¿ÀÛ
function TabMove(name,num) {
	if(!document.getElementsByName(name)) return;
	var TabGroup = document.getElementsByName(name);
	var TabThis = num-1;
	
	for(i=0; i<TabGroup.length; i++) {
		var TabName = name+(i+1);
		var TabContents = document.getElementById(TabName);
		if (TabContents) {
			if(i==TabThis) {
				TabContents.style.display = "block";
				TabGroup[TabThis].parentNode.className = "on";
			}
			else {
				TabContents.style.display = "none";
				TabGroup[i].parentNode.className = "";
			}
		}
	}
}


function prevTab(name) {
	var now  = window[name+'_index'];
	if (!now) now = 1;
	var tabs = $('.' + name).get();
	var total = tabs.length - 1;
	if (now == 1) now = total; 
	else now -= 1;
	window[name+'_index'] = now;
	setTab(name, now);
}


function nextTab(name) {
	var now  = window[name+'_index'];
	if (!now) now = 1;
	var tabs = $('.' + name).get();
	var total = tabs.length - 1;
	if (now == total) now = 1; 
	else now += 1;
	window[name+'_index'] = now;
	setTab(name, now);
}

var rollElements = function() {
	var timer;
	var intv;
	var func;
	var stopper;

	return {
		setIntv : function(t) {
			intv = t;
		},
			
		setFunc : function(f) {
			func = f;
		},
		
		setStopper : function(o) {
			var that = this;
			stopper = o;
			o.onmouseover = function() {
				clearInterval(timer);
			};
			o.onmouseout = function() {
				that.action();
			};
		},
		
		action : function() {
			if (!func) return;
			timer = setInterval(func, intv);
		}
	}
}
$(document).ready(function() {
	var list = rollElements();
		list.setStopper($('.visual_img').get(0));
		list.setIntv(5000);
		list.setFunc(function() {
			nextTab('visual_img');
		});
		list.action();
		
		$(".run").click(function(){
			$box = $('#box');   
				$box.show().animate({opacity: "1", left: "0"}, "slow");    
			}
		);
		$('.site').bind('mouseleave', function() {
			$('#box').animate({opacity: "0", left: "5"}, "slow", function() {$(this).hide(); });    
		});
		
	if (document.compatMode && document.all) document.onfocusin = function() {
		var el = event.srcElement;
		if ( el.tagName == "A" || el.tagName == "IMG" ) el.blur();
		}
		
	$('.nav li').hover(
	
	function() {
		$('.nav li').removeClass('on');
		$('.nav li a').removeClass('on');
		$(this).addClass('on');	
	});
				
	$(document).ready(function() {
		$('.menuList > li').hover(
			function() {
				$('.menuList li').removeClass('on');
				$('.menuList li a').removeClass('on');
				$(this).addClass('on');	
			});
	});	
	
		

});

function p_info() { 
        var w = 500;
        var h = 572;
        var LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
        var TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
        var win2 = window.open('http://www.neowiz.com/kor/company/inner_info.html','ready3', 'width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+'');
        win2.focus(); 

}   

function inner_info() { 
        var w = 500;
        var h = 572;
        var LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
        var TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
        var win2 = window.open('http://www.neowiz.com/kor/company/privacy2.html','ready3', 'width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+'');
        win2.focus(); 

}   

function invest_info(){
	//window.open("company/investment.html","","");
	 	var w = 640;
        var h = 347;
        var LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
        var TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
        var win2 = window.open('company/investment.html','ready4', 'width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+'');
        win2.focus();


}

function invest_infoIr(){
	//window.open("company/investment.html","","");
	 	var w = 640;
        var h = 347;
        var LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
        var TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
        var win2 = window.open('../company/investment.html','ready4', 'width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+'');
        win2.focus();


}

function showPic(whichpic){
  if(!document.getElementById("placeholder")) return true;
  var source = whichpic.getAttribute("href");
  var placeholder = document.getElementById("placeholder");
  if(placeholder.nodeName != "IMG") return true;
  placeholder.setAttribute("src",source); 

  if(!document.getElementById("descript")) return false;
  var text = whichpic.getAttribute("title") ? whichpic.getAttribute("title") : ""
  var description = document.getElementById("descript");
  if(description.firstChild.nodeType == 3){
   description.firstChild.nodeValue = text;
   placeholder.setAttribute("title",text);
  }
  return false;
 }
 function prepareGallery(){
  if(!document.getElementsByTagName) return false;
  if(!document.getElementById) return false;
  if(!document.getElementById("imggllery")) return false;
  var gallery = document.getElementById("gallery");
  var links = gallery.getElementsTagName("a");
  for(var i=0;i<links.length;i++){
   links[i].onclick = function(){
    return showPic(this);
   }
  }
 }
 function addLoadEvent(func){
  var oldonload = window.onload;
  if(typeof window.onload != 'function'){
   window.onload = func;
  }else{
   window.onload = function(){
    oldonload();
    func();
   }
  }
 }
 addLoadEvent(prepareGallery);
