$(document).ready(function() {
   checkSystemCapabilities();
});

function checkSystemCapabilities() {
	// Show Minimum System Requirements
	$("#javaScriptAlertMessage").removeClass("showJavaScriptAlert");
	$("#javaScriptAlertMessage").addClass("hideJavaScriptAlert");
	$("#systemRequirements").removeClass("hideSystemRequirements");
	$("#systemRequirements").addClass("showSystemRequirements");
	
	
	// Check Cookies
	if (isUserCookiesEnabled()) {
		$("#detectCookies").html("Enabled");
	}

	// Check Flash
	if (FlashDetect.installed) {
		$("#detectFlash").html("Flash " + FlashDetect.major + "." + FlashDetect.minor + "." + FlashDetect.revision);
	}

	// Check Browser
	if (!BrowserDetect.isOther) {
		$("#detectBrowser").html(BrowserDetect.browserLabel);
	}

	// Check Operating System
	if (!OsDetect.isOther) {
		$("#detectOperatingSystem").html(OsDetect.osLabel);
	}

	// Check Screen Resolution
	$("#detectScreenResolution").html(getScreenResolution());

	// Check Popup Windows
	
	if (!isPopupBlocker()) {
		$("#detectPopupBlocker").html("Unblocked");
	}
	
	// Check MP3
	checkMP3();
	
	// Check Flash Video
	checkFLV();
}		


function isUserCookiesEnabled() {
	var cookieEnabled = false;
	document.cookie = "cookieChecking=true";
	cookieEnabled = document.cookie.indexOf("cookieChecking=true") > -1;
	document.cookie = "cookieChecking=false";
	return cookieEnabled;
}

function isPopupBlocker() {
	var testWindow = window.open('','','width=1,height=1,left=0,top=0,scrollbars=no');
	if (testWindow) {
		testWindow.close();
		return false;
	} else { 
		return true;
	}
}

function getScreenResolution() {
	return window.screen.width + "x" + window.screen.height;
}
  
function createRequest() {
  var tRequest_obj;
   //Set up the global request object
  try { 
    tRequest_obj = new XMLHttpRequest();
  } 
  catch ( trymicrosoft ) 
  {
    try { 
      tRequest_obj = new ActiveXObject ("Msxml2.XMLHTTP");
    } 
    catch ( othermicrosoft ) 
    {
      try {
        tRequest_obj = new ActiveXObject ("Microsoft.XMLHTTP");
      } 
      catch (failed) { // For legacy Browsers use the iFrame obj.
        //alert('iframe');
      }
    }
  }
  return tRequest_obj;
}

var mp3Request;
function checkMP3() {
	try {
		mp3Request = createRequest();
		//use POST to prevent caching
		mp3Request.open("POST", "systemcheck.mp3", true);
		//IE doesn't like it if you put perens on the end of the next line
		mp3Request.onreadystatechange = finishMP3;
		mp3Request.send(null);
	} catch(exception) {
		$("#MP3").html("Undetermined");
	}
}

function finishMP3() {
	if (mp3Request.readyState == 4) {
		if (mp3Request.status == 200) {
			$("#MP3").html("Unblocked");
		} else {
			$("#MP3").html("Blocked");
		}
		$("#mp3loading").html("");
	} else if ($("#MP3").html() != "Undetermined"){
		// Get the Dots string and the number of dots
		var dots = $("#mp3loading").html();

		// If the number of dots is less than 5, add another dot. Else restart the dot string
		if( dots.length < 5 ) {
			// Add a dot
			$("#mp3loading").html(dots + ".");
		} else {
			// Clear out the dots
			$("#mp3loading").html("");
		}

		setTimeout ( "finishMP3()" , 300 ); 
	} else {
		// Clear out the dots
		$("#mp3loading").html("");
	}
}


var flvRequest;
function checkFLV() {
	try {
		flvRequest = createRequest();
		//use POST to prevent caching
		flvRequest.open("GET", "systemcheck.flv", true);
		//IE doesn't like it if you put perens on the end of the next line
		flvRequest.onreadystatechange = finishFLV;
		flvRequest.send(null);
	} catch(exception) {
		$("#FLV").html("Undetermined");
	}
}

function finishFLV() {
	if (flvRequest.readyState == 4){
		if (flvRequest.status == 200) {
			$("#FLV").html("Unblocked");
		} else {
			$("#FLV").html("Blocked");
		}
		$("#flvloading").html("");
	} else if ($("#FLV").html() != "Undetermined") {
		// Get the Dots string and the number of dots
		var dots = $("#flvloading").html();
		

		// If the number of dots is less than 5, add another dot. Else restart the dot string
		if ( dots.length < 5 ) {
			// Add a dot
			$("#flvloading").html(dots + ".");
		} else {
			// Clear out the dots
			$("#flvloading").html("");
		}

		setTimeout ( "finishFLV()" , 300 ); 
	} else {
		// Clear out the dots
		$("#flvloading").html("");
	}
}

