// JavaScript Document

$(document).ready(function(){
/*	tabs removed
	$("#ServerUpdateLink").click(function () { 
		document.getElementById("tabServerUpdate").style.zIndex = 2;
		document.getElementById("tabNews").style.zIndex = 1;
		document.getElementById("fpNewsDiv").style.display = "none";
		document.getElementById("fpServerUpdateDiv").style.display = "block";			   
	});

	$("#DevblogLink").click(function () { 
		document.getElementById("tabDevblog").style.zIndex = 2;
		document.getElementById("tabNews").style.zIndex = 1;
		document.getElementById("fpNewsDiv").style.display = "none";
		document.getElementById("fpDevblogDiv").style.display = "block";			   
	});
	
	$("#newsLink").click(function () { 
		document.getElementById("tabServerUpdate").style.zIndex = 1;
		document.getElementById("tabNews").style.zIndex = 2;
		document.getElementById("fpNewsDiv").style.display = "block";
		document.getElementById("fpServerUpdateDiv").style.display = "none";				   
	});	
*/	
	if($('#fpRotator').length > 0) {
		$('#fpRotatorStates').show();
		$('#fpRotator').cycle({
			fx: 'fade',
			speed: 700,
			timeout: 5000,
			pager: 'div#pager',
			next: '#next',
			prev: '#prev'
		});
		
		$('#fpRotator').bind('mouseenter', function() {
			 $('#fpRotator').cycle('pause');
		});
		
		$('#fpRotator').bind('mouseleave', function() {
			 $('#fpRotator').cycle('resume');
		});


	}
	

	// Navigation on-state for each section
	var docLoc = document.location.href;
	docLoc = docLoc.split("/"); // Split the url on back-slash
	docLoc = docLoc[3]; // take the third array element
	if (docLoc != "" && docLoc != "index.html"){
		docLoc = "nav" + docLoc.substring(0,1).toUpperCase() + docLoc.substring(1,docLoc.length);
		docLoc = docLoc.replace(/Game_guide/, "GameGuide");
	} 
	else if (docLoc == "" || docLoc == "index.html"){
		docLoc = "navHome";	
	}

	document.getElementById(docLoc).innerHTML = document.getElementById(docLoc).innerHTML.replace(/.png/ig,"-on.png");
	
	// Preload all rollovers
	$("#navDiv span img").each(function() {
		// Set the original src
		rollsrc = $(this).attr("src");
		rollON = rollsrc.replace(/.png$/ig,"-on.png");
		$("<img>").attr("src", rollON);
	});
	
	// Navigation rollovers
	$("#navDiv span a").mouseover(function(){
		imgsrc = $(this).children("img").attr("src");
		matches = imgsrc.match(/-on/);
		
		// don't do the rollover if state is already ON
		if (!matches) {
		imgsrcON = imgsrc.replace(/.png$/ig,"-on.png"); // strip off extension
		$(this).children("img").attr("src", imgsrcON);
		}
		
	});
	$("#navDiv span a").mouseout(function(){
		$(this).children("img").attr("src", imgsrc);
	});
	
	function oldIE(){
		if (jQuery.browser.msie && parseInt(jQuery.browser.version) < 7) {
			return true;
		}
	}

    //search box
    $("#dimebar_searchbox").focus(function(){
      if($(this).hasClass("empty")){
        $(this).attr({value:""});
      }
    })
    
    $("#dimebar_searchbox").blur(function(){
      if($(this).val()){
        $(this).removeClass("empty");
      }else{
        $(this).attr({value:"Search this Site"});
      }
    })
	
    //dropdown icons
    $(".ncdb-menu-item .ncdb-icon-expand").css("cssText", "background-position:top left !important");
    $(".ncdb-menu-item").hover(
      function(){
        $(".ncdb-icon-expand-active",this).css({display:"block", opacity:0}).animate({ opacity:1 }, { queue:false, duration:200 } );
      },
      function(){
        $(".ncdb-icon-expand-active",this).css({display:"block", opacity:1}).animate({ opacity:0 }, { queue:false, duration:200 } );
		// dropdown fixes for old versions of IE
		if (oldIE()) $("#ncdb-panel-games").css("cssText", "display: none");
		if (oldIE()) $("#ncdb-panel-language").css("cssText", "display: none");
      }
    )
	//lang dropdown fix for old versions of IE
	if (oldIE()) {
		$("#ncdb-menu-language").mouseover(function(){
			$("#ncdb-panel-language").css("cssText", "display: block");
		})
	}
    //game dropdown
    
    //when menu tile is active
    $("#ncdb-menu-games .ncdb-menu-item-link").mouseover(function(){
      //add default_game class to Aion
      $("#ncdb-panel-games #aion").addClass("default_game");
      if (oldIE()) $("#ncdb-panel-games").css("cssText", "display: block"); // dropdown fix for old versions of IE
      //on siblings rollover hide Aion
      $("#ncdb-panel-games a:not(#aion)").mouseover(function(){
            $("#ncdb-panel-games #aion").removeClass("default_game");
      });
      
      //on Aion rollover keep Aion as block
      $("#ncdb-panel-games #aion").mouseover(function(){
            $("#ncdb-panel-games #aion").addClass("default_game");
      });
    })

    //remove class from Aion if menu tile is inactive
    $("#ncdb-menu-games").mouseout(function(){
      if($("#ncdb-menu-games .ncdb-menu-item-link").css("display")=="none"){
        $("#ncdb-panel-games #aion").removeClass("default_game");
		
      }
    })
	
	$("#dimebar_searchbox").hover(function(){
		$(this).css("cssText", "background-position:bottom left !important; color:#fff !important;");
		$("#ncdb-submit").css("cssText", "background-position:bottom right !important;");
	},
  	function () {
    	$(this).css("cssText", "background-position:top left !important; color:#DFDFDF !important;");
		$("#ncdb-submit").css("cssText", "background-position:top right !important;");
  	});

});