$(document).ready(function(){

//Hide all but the first tab
$('.content DIV').first().siblings().hide();

//Make the navigation affect the tabs
$('.tab-link').click(function(e) {
	location.hash = this.hash.replace('#', '#!');
	e.preventDefault();
	$('.active').removeClass('active');
	$(this).addClass('active');
	$('.content DIV').hide();
	$($(this).attr('href')).show();
});

var hashname = window.location.hash.replace('#!', '#');
	
if(hashname && $(hashname).length > 0){
	$('.active').removeClass('active');
	$('.content DIV').hide();
	$(hashname).show();
	$('.nav a[href="' + hashname + '"]').addClass('active');
}

$().dimeBar({
	"rightItems"            :   [""],
	"leftItems"             :   ["corporateLink", "gamesMenu"],
	"corporateLink"         :   "http://us.ncsoft.com/en/",

	"otherGames": {
		"games"		   :	 "Games",
		"cityOfHeroes"       :     "http://www.cityofheroes.com/en.html",
		"aion"               :     "http://aiononline.com/",
		"lineageTwo"         :     "http://www.lineage2.com/",
		"guildWars"          :     "http://www.guildwars.com/"
	}

});

var mouse_is_inside = false;


$('.has-dropDown').hover(function(){ 
mouse_is_inside=true; 
}, function(){ 
mouse_is_inside=false; 
});

$("body").mouseup(function(){ 
//alert("mouse_is_inside:" + mouse_is_inside);
if(! mouse_is_inside) {
	$('.has-icon-hover').removeClass('has-icon-hover');
			$('.db-dropDown').hide();
}
});


$('div.has-dropDown').find('.reg-link').click(function() {
	//	alert("dimebar click:" + $(this).next().attr("class") ); //this is the URL of the clicked link
	var $this = $(this).next();
	//alert("b4");
	$('.db-dropDown').not($this).hide(220).siblings().removeClass('has-icon-hover');
	
	$(this).next('.db-dropDown').animate({ height: "toggle"}, 400);
//	alert("after");
	$(this).next().find('a.default-game').addClass('default-game-hover');
	$(this).toggleClass('has-icon-hover'); 
	//console.log('one')
});

$('li.db-franchise').hover(function() {
	
	$('li.db-franchise').find('a.default-game').removeClass('default-game-hover');
	var franchise = $(this).children().attr('id');
	$(this).children().addClass(franchise + '-hover');
	
},function() {
	
	var franchise = $(this).children().attr('id');
	$(this).children().removeClass(franchise + '-hover');
	$('li.db-franchise').find('a.default-game').addClass('default-game-hover');
});
/*
$('.left-items').bind('clickoutside', function(){
	
	$('.db-dropDown').hide();
});

*/
$('body > *:not(div#db-container)').click(function() {
	$('.has-icon-hover').removeClass('has-icon-hover');
	$('.db-dropDown').hide();
});


$('div.has-dropDown').find('a.reg-link').addClass('has-icon');



$('#db-search label').fadeIn(1000);
$('#db-search input').focus(function() {
	$(this).addClass('db-input-focused');
	if($(this).val() === '') {
		$('#db-search  label').fadeOut('fast');
	}
});    
$('#db-search  input').blur(function() { 
	$(this).removeClass('db-input-focused');   
	if($(this).val() === '') {
		$('#db-search  label').fadeIn('slow');
	} 
});



});
