
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function sluiten()
{
	self.close()
}

function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}
window.onload = externalLinks;

function CreateQuicktimeControl(DivID, CLSID, ObjectID, WIDTH, HEIGHT, SRC, AUTOSTART)
{
 	var d = document.getElementById(DivID);
  	d.innerHTML = 
   '<object classid=' + CLSID + ' id=' + ObjectID + ' width=' + WIDTH + ' height=' + HEIGHT +' CODEBASE="http://www.apple.com/qtactivex/qtplugin.cab#version=7,0,4,0"><param name="SRC" value=' + SRC + '><PARAM NAME="controller" VALUE="TRUE"><PARAM NAME="type" VALUE="video/quicktime"><param name="autoStart" value=' + AUTOSTART + '><EMBED WIDTH=' + WIDTH + ' HEIGHT=' + HEIGHT + ' CONTROLLER="TRUE" TARGET="myself" SRC=' + SRC + ' type="video/quicktime" BGCOLOR="#000000" BORDER="0" PLUGINSPAGE="http://www.apple.com/quicktime/download/indext.html"></object>';
}

function CreateWindowsMediaControl(DivID, CLSID, ObjectID, WIDTH, HEIGHT, URL, AUTOSTART)
{
  var d = document.getElementById(DivID);
  d.innerHTML = 
    '<object classid=' + CLSID + ' id=' + ObjectID + ' width=' + WIDTH + ' height=' + HEIGHT +' type="application/x-oleobject" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715"><param name="uiMode" value="None"><param name="DisplaySize" value="0"><param name="TransparentAtStart" value="false"><param name="ShowControls" value="True"><param name="ShowStatusBar" value="True"><param name="Mute" value="False"><PARAM name="Volume" value="600"><param name="FileName" value=' + URL + '><param name="autoStart" value=' + AUTOSTART + '><embed src=' + URL + ' width=' + WIDTH + ' height=' + HEIGHT +' type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" AutoStart=' + AUTOSTART + ' ShowStatusBar="1" ShowTracker="1" ShowControls="1" ShowAudioControls="1" ShowPositionControls="1" EnableTracker="1" Mute="0"></object>';
}

function clearText(thefield) {
        if (thefield.defaultValue == thefield.value)
                thefield.value = ""
        else thefield.value = thefield.defaultValue
} 

// ON DOCUMENT READY, DOE DEZE SCRIPTS
$(document).ready(function(){

  //Load Active gamers stuff
  showActiveGamers();
  
  
  $("#loginEmailIcon").effect("pulsate", {}, 1000);
	

});



/**
 * TSStatus: Teamspeak 3 viewer for php5
 * @author Sebastien Gerard <sebeuu@gmail.com>
 * @see http://tsstatus.sebastien.me/
 * 
 **/

function tsstatusconnect(host, port, channel)
{
	var command = "ts3server://" + host + "/?port=" + port;
	var nick = "";
	var pass = "";
	
	if(document.getElementById("tsstatusNick") != null) nick = document.getElementById("tsstatusNick").value;
	if(nick != "")
	{
		command += "&nickname=" + nick;
		var dateExpire = new Date;
		dateExpire.setMonth(dateExpire.getMonth()+1);
		document.cookie = escape("tsstatus_" + host) + "=" + escape(nick) + "; expires=" + dateExpire.toGMTString();
	}
	
	if(document.getElementById("tsstatusPasswd") != null) pass = document.getElementById("tsstatusPasswd").value;
	if(pass != "")
	{
		command += "&password=" + pass;
		var dateExpire = new Date;
		dateExpire.setMonth(dateExpire.getMonth()+1);
		document.cookie = escape("tsstatus_" + host + "_pwd") + "=" + escape(pass) + "; expires=" + dateExpire.toGMTString();
	}
	
	if(channel != undefined)
	{
		command += "&channel=" + channel;
	}

	var popup = window.open(command);
	popup.close();
}


function showLogin () {
	
	$('body').scrollTo('0%', 'slow', function(){
		$('#open').trigger('click'); 
	});	
}

//------------------ Shouts
var shoutIntervalID = 0;

function startShoutInterval(){
	shoutIntervalID = setInterval('loadShouts();', (1000 * 10 ));	
}

function stopShoutInterval(){
	return clearInterval(shoutIntervalID);	
}

function loadShouts () {
	
	//Stop shout interval
	stopShoutInterval();
	
	var dontWant = '';
	$('.shoutMessage').each(function() {
		if(dontWant != ""){
			dontWant += ',';
		}
		dontWant += $(this).attr('shoutBoxID');
	});
	
	var aurl = 'ajax.php?mode=shoutbox_getShouts&dontWant=' + dontWant ;
	
	//$('#debugMsg').html('<a href="http://11-clan.eu/'+aurl+'">debug</a>');
	
	$.get(aurl, function(dataStr){
		
		jsonObj = jQuery.parseJSON(dataStr);
		
		if(jsonObj.noChange != 1){
			//$('#messages').empty();
			
			//Prepend new messages
			var str = '';
			$.each(jsonObj.rows, function(key, row) { 
				
				//Check if message is already there (thanks IE, piece of shit)
				if($('#shoutBox_'+ row.shoutBoxID).length > 0){
					//alert('This isnt supposed to happen.');
				}else{
					str = '';
					str += '<div class="shoutMessage" id="shoutBox_'+ row.shoutBoxID +'" shoutBoxID="'+ row.shoutBoxID +'"';
					str += ' style="display:none;"';
					str += '>';
					str += '<strong class="bold">'+ row.username +'</strong>';
					if(row.timeStr != "" && row.timeStr != undefined){
						str += '<span class="ArtikelInfo"> - '+ row.timeStr +'</span>';
					}
					
					if(row.type == 'developer'){
						//str += '<span class="ArtikelInfo"> - <img src="images/icons/shout_lock.png" alt="Leader shout" title="Leader shout"> </span>';
						str += '<div style="float: right; margin-top: 2px;"><img src="images/icons/shout_lock.png" alt="Leader shout" title="Leader shout"> </div>';
					}
					
					str += '<br />';
					str += row.shoutBoxMsg +'<br />';
					str += '</div>';
					
					$('#messages').prepend(str);
					
					$('.shoutMessage:first').show("drop", { direction: "up" }, 1000);
				}
			});
			
			
			//Remove old messages
			var i = 0;
			$('.shoutMessage').each(function() {
				i++;
				if(i > 10){
					$(this).hide("drop", { direction: "up" }, 1, function(){
						$(this).remove();
					});
					//$().fadeOut();
					//'.shoutMessage:last'
				}
			});
		}
	});
	
	//Restart shout interval
	startShoutInterval();

}


function sendShout () {
	var aurl = 'ajax.php?mode=shoutbox_putShout';
	
	var developer = 0;
	
	if($('#developerChkBox:checked').length){
		developer = 1;	
	}
	
	$.post(aurl, {msg: $('#msg').val(), developer: developer}, function(dataStr){

		jsonObj = jQuery.parseJSON(dataStr);
		
		if(jsonObj.ok == 1){
			loadShouts();
			$('#msg').val('');
			$('#msg').focus();
		}else if(jsonObj.needLogin == 1){
			//This does not work
//			$.get('ajax.php?mode=login_getPanelData', function(LoginData){
//				$('#loginPanel').html(LoginData);
//				showLogin();
//			});
			alert('It appears that your not logged in, please log in first.');
			
		}else{
			alert('error sending shout: ' + jsonObj.error);
		}
	});
}

function showActiveGamers () {
	
	var aurl = 'ajax.php?mode=gamers_getActiveGamers';
	
	$.get(aurl, function(dataStr){
		
		$('.BlockMemberContentRows').hide();
		$('.BlockMemberContentRows').html(dataStr);
		//$('.BlockMemberContentRows').fadeIn("1500");	
		$('.BlockMemberContentRows').show("slide", { direction: "up" }, 1000);	//This fits more in the animation style of order thingies
		
	});
}

/* RADIO TRACKS */
var tracksIntervalID = 0;

function startTracksInterval(){
	tracksIntervalID = setInterval('loadTrackInfo();', (1000 * 30 ));	
}

function stopTracksInterval(){
	return clearInterval(tracksIntervalID);	
}

function loadTrackInfo()
{
	stopTracksInterval();
	
	var aurl = 'ajax.php?mode=radio';
	
	$.get(aurl, function(dataStr){
		
		var jsonObj = jQuery.parseJSON(dataStr);
		
		//alert(dataStr);
		
		if(jsonObj.current != undefined){ //Niet goed getest 2011-10-26
			
			$('.Current').html(jsonObj.current);
			$('.Next').html(jsonObj.next);
		}
	
	});
	
	//Restart shout interval
	startTracksInterval();

}
