// flash detect min
var FlashDetect=new function(){var self=this;self.installed=false;self.raw="";self.major=-1;self.minor=-1;self.revision=-1;self.revisionStr="";var activeXDetectRules=[{"name":"ShockwaveFlash.ShockwaveFlash.7","version":function(obj){return getActiveXVersion(obj);}},{"name":"ShockwaveFlash.ShockwaveFlash.6","version":function(obj){var version="6,0,21";try{obj.AllowScriptAccess="always";version=getActiveXVersion(obj);}catch(err){}
return version;}},{"name":"ShockwaveFlash.ShockwaveFlash","version":function(obj){return getActiveXVersion(obj);}}];var getActiveXVersion=function(activeXObj){var version=-1;try{version=activeXObj.GetVariable("$version");}catch(err){}
return version;};var getActiveXObject=function(name){var obj=-1;try{obj=new ActiveXObject(name);}catch(err){obj={activeXError:true};}
return obj;};var parseActiveXVersion=function(str){var versionArray=str.split(",");return{"raw":str,"major":parseInt(versionArray[0].split(" ")[1],10),"minor":parseInt(versionArray[1],10),"revision":parseInt(versionArray[2],10),"revisionStr":versionArray[2]};};var parseStandardVersion=function(str){var descParts=str.split(/ +/);var majorMinor=descParts[2].split(/\./);var revisionStr=descParts[3];return{"raw":str,"major":parseInt(majorMinor[0],10),"minor":parseInt(majorMinor[1],10),"revisionStr":revisionStr,"revision":parseRevisionStrToInt(revisionStr)};};var parseRevisionStrToInt=function(str){return parseInt(str.replace(/[a-zA-Z]/g,""),10)||self.revision;};self.majorAtLeast=function(version){return self.major>=version;};self.minorAtLeast=function(version){return self.minor>=version;};self.revisionAtLeast=function(version){return self.revision>=version;};self.versionAtLeast=function(major){var properties=[self.major,self.minor,self.revision];var len=Math.min(properties.length,arguments.length);for(i=0;i<len;i++){if(properties[i]>=arguments[i]){if(i+1<len&&properties[i]==arguments[i]){continue;}else{return true;}}else{return false;}}};self.FlashDetect=function(){if(navigator.plugins&&navigator.plugins.length>0){var type='application/x-shockwave-flash';var mimeTypes=navigator.mimeTypes;if(mimeTypes&&mimeTypes[type]&&mimeTypes[type].enabledPlugin&&mimeTypes[type].enabledPlugin.description){var version=mimeTypes[type].enabledPlugin.description;var versionObj=parseStandardVersion(version);self.raw=versionObj.raw;self.major=versionObj.major;self.minor=versionObj.minor;self.revisionStr=versionObj.revisionStr;self.revision=versionObj.revision;self.installed=true;}}else if(navigator.appVersion.indexOf("Mac")==-1&&window.execScript){var version=-1;for(var i=0;i<activeXDetectRules.length&&version==-1;i++){var obj=getActiveXObject(activeXDetectRules[i].name);if(!obj.activeXError){self.installed=true;version=activeXDetectRules[i].version(obj);if(version!=-1){var versionObj=parseActiveXVersion(version);self.raw=versionObj.raw;self.major=versionObj.major;self.minor=versionObj.minor;self.revision=versionObj.revision;self.revisionStr=versionObj.revisionStr;}}}}}();};FlashDetect.JS_RELEASE="1.0.4";

// subnav
var navRollState = 0; 
var subnavRollState = 0; 
jQuery(document).ready(function()
{
	$("#navigation > ul > li > a").mouseenter(function(e)
	{
		//setTimeout(delayCloseSubnav,500);
		closeSubnav(1);
		navRollState = 1; 
		$(this).parent().children(".subnav").fadeIn(170);
		// position 
		var offset = $(this).offset();
		/*
		var offset = $(this).parent().offset();
		if ($(this).parent().hasClass('selected'))
		{
			offset.left = Math.round(offset.left - 265 - ($(this).width() / 2)); 
		}
		else
		{
			offset.left = Math.round(offset.left - 255 - ($(this).width() / 2)); 
		}
		if (navigator.userAgent.toString().indexOf('MSIE') != -1)
		{
			offset.left -= 35; 
		}
		$(this).parent().children(".subnav").css('left',offset.left+'px');
		*/
		//$("#debug").html($(this).width() + ' ol:'+ offset.left);
		$(this).parent().children(".subnav").fadeIn(170);
	});
	$(".subnav > div > ul > li > a").mouseenter(function()
	{
		closeSuperSubnav(1);
		subnavRollState = 1; 
		// position
		var parentOffset = $(this).parent().parent().parent().offset();
		var offset = $(this).offset();
		offset.left = offset.left - parentOffset.left + 138; 
		offset.top = offset.top - parentOffset.top + 20; 
		$(this).parent().children(".supersubnav").css({'left':offset.left+'px','top':offset.top+'px'});
		$(this).parent().children(".supersubnav").fadeIn(170);
	});
	$("#navigation .subnav").mouseenter(function()
	{
		navRollState = 1; 
	});
	$("#navigation .supersubnav").mouseenter(function()
	{
		navRollState = 1; 
	});
	$("#navigation > ul > li > a").mouseleave(function()
	{
		//alert('nav a leave');
		navRollState = 0; 
		setTimeout(closeSubnav,200); 
	});
	$("#navigation .subnav").mouseleave(function()
	{
		//alert('nav .subnav leave');
		subnavRollState = 0; 
		navRollState = 0; 
		setTimeout(closeSubnav,200); 
	});
	$("#navigation .supersubnav").mouseleave(function()
	{
		//alert('nav .subnav leave');
		subnavRollState = 0; 
		setTimeout(closeSubnav,200); 
	});
	
   // standard page version
   $("a.serverGridViewButton").click(function(){
		$("#serverGrid").show(250);
		return false;
	});
   $("a.serverMapViewButton").click(function(){
		$("#serverGrid").hide(250);
		return false;
	});
	// locations page version
   $("a.serverGridViewButtonLoc").click(function(){
		$('html, body').animate({scrollTop:$(".col-90").offset().top-20}, 'slow');
		return false;
	});
   $("a.serverMapViewButtonLoc").click(function(){
		 $('html, body').animate({scrollTop:150}, 'slow');
		return false;
	});	
	
	// affiliate
	$('.toggle-link').click(function()
	{
		if ($(this).next('div.link-code').css('display') == 'block')
		{
			$(this).next('div.link-code').slideUp(250);
		}
		else
		{
			$(this).next('div.link-code').slideDown(250);
			$(this).next('div.link-code').children('form > textarea').select();
		}
	});
	
	$('#fp-location-content a').mouseenter(function(){
		$('#fp-location-content').stop(); 
	})
	
	//if ($.browser.msie)
	//{
		//$('#twitterWidget').css('display','none');
	//}
	
});

function maxLocationScroll()
{
	// scroll locations
	var destScroll = Math.min( (parseInt($('#fp-location-content ul').width()) - 640));
	$('#fp-location-content').animate({scrollLeft:destScroll}, 45000);
}

function displayInstructions(which)
{
	if (jQuery(which).parent().children('div.instructions').css('display') == 'block')
	{
		jQuery(which).parent().children('div.instructions').slideUp(250);
	}
	else
	{
		jQuery(which).parent().children('div.instructions').slideDown(250);
	}
}

function displayFAQ(which)
{
	if (jQuery(which).parent().children('div').css('display') == 'block')
	{
		jQuery(which).parent().children('div').slideUp(250);
	}
	else
	{
		jQuery(which).parent().children('div').slideDown(250);
	}
}

function logIn()
{
	var lF = document.getElementById('loginForm'); 
	if ((lF.USERID.value != '')&&(lF.PASSWORD.value != ''))
	{
		lF.submit();
	}
	return false;
}

function resetForm()
{
	var lF = document.getElementById('loginForm'); 
	lF.USERID.value = '';
	lF.PASSWORD.value = '';
	return false;
}
function delayCloseSubnav()
{
	if ((subnavRollState == 0)&&(navRollState == 0))
	{
		closeSubnav(1);
	}
}
function closeSubnav(forceClose)
{
	if (((subnavRollState == 0)&&(navRollState == 0))||(forceClose == 1))
	{
		$("#navigation .subnav").fadeOut(170);
		$("#navigation .supersubnav").css('display','none');
	}
	else
	{
		//alert('nRS:'+navRollState+' ssRS:'+subnavRollState+' fC:'+forceClose);
	}
}
function closeSuperSubnav(forceClose)
{
	if ((subnavRollState == 0)||(forceClose == 1))
	{
		$("#navigation .supersubnav").fadeOut(170);
	}
}

function OpenSupport()
{
	window.open('https://www.clanwarz.com/chat/phplive.php?d=0','liveChat','location=0,menubar=0,resizable=1,scrollbars=0,status=0,titlebar=0,toolbar=0,width=550,height=600');
}

// front page location slider
function fpLocationScroll(direction)
{
	var numPages = parseInt($('#fp-location-content ul').width()) / 640;
	var curPage = Math.floor(parseInt($('#fp-location-content').scrollLeft()) / 640);
	
	$('#fp-location-content').stop(); 
	
	if (direction == 'next')
	{
		if (curPage < numPages)
		{
			var destScroll = Math.min( ((curPage + 1) * 640), (parseInt($('#fp-location-content ul').width()) - 640));
			
			$('#fp-location-content').animate({scrollLeft:destScroll}, 'slow');
		}
	} 
	else if (direction == 'prev')
	{
		if (curPage > 0)
		{
			var destScroll = (curPage - 1) * 640; 
		}
		else
		{
			var destScroll = 0; 
		}
		$('#fp-location-content').animate({scrollLeft:destScroll}, 'slow');
	}
	
	return false;
}

