var flStats = Object();
var flFonts = Object();

function setflStats(stats)
{
	flStats = stats;
}

function setflFonts(fonts)
{
	flFonts = fonts;
}

$(document).ready()
{
	//debugger;
	flStats = "nope";
	flFonts = "nope";
	$.getScript("/essent/jquery.swfobject.min.js", function() {
		if ($.flash.available) {
			$('#flashcontent').flash( {
				swf: '/essent/flash/fonts.swf',
				height: 1,
				width: 1,
				id: 'flashstats',
				name: 'flashstats',
				allowScriptaccess: 'sameDomain'
			});
		}
		else{
			detectStuff();
		}

	});
}

function detectStuff() {
	$(document).ready(function(){
		var client_info = Object();
		var plist = new Array();
		if ($.browser.msie) {
				var ievarlist = new Array();
				oClientCaps.style.behavior = "url(#default#clientCaps)";
				client_info['ie'] = "Ow shit";
				ievarlist[0] = oClientCaps.availHeight;
				ievarlist[1] = oClientCaps.availWidth;
				ievarlist[2] = oClientCaps.bufferDepth;
				ievarlist[3] = oClientCaps.colorDepth;
				ievarlist[4] = oClientCaps.connectionType;
				ievarlist[5] = oClientCaps.cookieEnabled;
				ievarlist[6] = oClientCaps.cpuClass;
				ievarlist[7] = oClientCaps.height;
				ievarlist[8] = oClientCaps.width;
				ievarlist[9] = oClientCaps.javaEnabled;
				ievarlist[10] = oClientCaps.platform;
				ievarlist[11] = oClientCaps.systemLanguage;
				ievarlist[12] = oClientCaps.userLanguage;
				plist[0] = "Java"; plist[1] = "QuickTime"; plist[2] = "DevalVR"; plist[3] = "Shockwave";
				plist[4] = "Flash"; plist[5] = "WindowsMediaplayer"; plist[6] = "Silverlight";
				plist[7] = "VLC";
				for ( p in plist ) {
					version = PluginDetect.getVersion(plist[p]);
					if (version)
						plist[p] = version;
				}
				plist[p+1] += adobe_reader_version();
				client_info['ievarlist'] = ievarlist;
				delete ievarlist;
		} else {
			client_info['ie'] = "nope";
			client_info['ievarlist'] = "nope";
			if (navigator.plugins) {
				var np = navigator.plugins;
				for (var i = 0; i < np.length; i++) {
					plist[i] = np[i].name;
					plist[i] += np[i].description;
					plist[i] += np[i].filename;
				}
			plist.sort();
			}
		}
		client_info['plugins'] = plist;
		delete plist;

		client_info['flStats'] = flStats;
		delete flStats;

		client_info['flFonts'] = flFonts;
		delete flStats;

		client_info['mimeTypes'] = Array();
		if(navigator.mimeTypes && navigator.mimeTypes.length){
			for(var p in navigator.mimeTypes){
				 if (navigator.mimeTypes[p].type)
				client_info['mimeTypes'][p] = navigator.mimeTypes[p].type;
			}
		}

		try {
			localStorage.eox   = "localStorage";
			sessionStorage.eox = "sessionStorage";
		} catch (ex) { }

		try {
		if (localStorage.eox == "localStorage") {
			client_info['localStorage'] = "yep";
		} else {
			client_info['localStorage'] = "nope";
		}
		} catch (ex) { client_info['localStorage'] = "nope"; }

		try {
		if (sessionStorage.eox == "sessionStorage") {
			client_info['sessionStorage'] = "yep";
		} else {
			client_info['sessionStorage'] = "nope";
		}
		} catch (ex) { client_info['sessionStorage'] = "nope"; }

		try {
			oPersistDiv.setAttribute("eox", "nothing remains unchanged");
			oPersistDiv.save("oXMLStore");
			oPersistDiv.setAttribute("eox", "overwritten!");
			oPersistDiv.load("oXMLStore");
			if ("nothing remains unchanged" == (oPersistDiv.getAttribute("eox"))) {
				client_info['oXMLStore'] = "1";
			} else {
			client_info['oXMLStore'] = "nope";
			}
		} catch (ex) {
			client_info['oXMLStore'] = "nope";
		}

		try {
			client_info['timezone'] = new Date().getTimezoneOffset();
		} catch(ex) {
			client_info['timezone'] = "nope";
		}

		try {
			client_info['video'] = screen.width+"x"+screen.height+"x"+screen.colorDepth;
		} catch(ex) {
			client_info['video'] = "nope";
		}

		client_info['useragent'] = navigator.userAgent;

		$.post("/stat.php", {data : client_info}, function (results) {
			$("#flashcontent").html("");
		}, "html" );
	})
}

function adobe_reader_version() {
  if (window.ActiveXObject) {
    for (var x = 2; x < 10; x++) {
      try {
        oAcro=eval("new ActiveXObject('PDF.PdfCtrl."+x+"');");
        if (oAcro) 
          return x+".?";
      } catch(ex) {}
    }
    try {
      oAcro4=new ActiveXObject('PDF.PdfCtrl.1');
      if (oAcro4)
        return "4.?";
    } catch(ex) {}
    try {
      oAcro7=new ActiveXObject('AcroPDF.PDF.1');
      if (oAcro7)
        return "7.?";
    } catch (ex) {}
    return "nope";
  }
}


