/*
Script Name: si_tracking
Version: 2.0
Author: Nathan Bagley
Copyright 2004 Imagery Graphics
*/

var trackFlash = true;
var trackDirector = true;
var trackReal = true;
var trackWindowsMedia = true;
var trackQuickTime = true;
var detectableWithVB = false;
var pluginFound = false;

function detectFlash(){
	pluginFound = detectPlugin('Shockwave','Flash'); 
	if(!pluginFound && detectableWithVB){ pluginFound = detectActiveXControl('ShockwaveFlash.ShockwaveFlash.1'); }
	return pluginFound;
}

function detectDirector(){ 
	pluginFound = detectPlugin('Shockwave','Director'); 
	if(!pluginFound && detectableWithVB) { pluginFound = detectActiveXControl('SWCtl.SWCtl.1'); }
	return pluginFound;
}

function detectQuickTime(){
	pluginFound = detectPlugin('QuickTime');
	if(!pluginFound && detectableWithVB) { pluginFound = detectQuickTimeActiveXControl(); }
	return pluginFound;
}

function detectReal(){
	pluginFound = detectPlugin('RealPlayer');
	if(!pluginFound && detectableWithVB) { pluginFound = (detectActiveXControl('rmocx.RealPlayer G2 Control') || detectActiveXControl('RealPlayer.RealPlayer(tm) ActiveX Control (32-bit)') || detectActiveXControl('RealVideo.RealVideo(tm) ActiveX Control (32-bit)')); }
	return pluginFound;
}

function detectWindowsMedia(){
	pluginFound = detectPlugin('Windows Media');
	if(!pluginFound && detectableWithVB) { pluginFound = detectActiveXControl('MediaPlayer.MediaPlayer.1'); }
	return pluginFound;
}

function detectPlugin(){
	var pi = detectPlugin.arguments;
	var found = false;
	if (navigator.plugins && navigator.plugins.length > 0) {
		var pi_len = navigator.plugins.length;
		for (i=0; i < pi_len; i++){
			var numFound = 0;
			for(x=0; x < pi.length; x++){
				if( (navigator.plugins[i].name.indexOf(pi[x]) >= 0) || (navigator.plugins[i].description.indexOf(pi[x]) >= 0)){
					numFound++;
				}
			}
	
			if(numFound == pi.length) {
				found = true; break;
			}
		}
	}
	return found;
}

if ((navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1)){
    document.writeln('<script language="VBscript">');
    document.writeln('\'do a one-time test for a version of VBScript that can handle this code');
    document.writeln('detectableWithVB = False');
    document.writeln('If ScriptEngineMajorVersion >= 2 then');
    document.writeln('  detectableWithVB = True');
    document.writeln('End If');
    document.writeln('\'this next function will detect most plugins');
    document.writeln('Function detectActiveXControl(activeXControlName)');
    document.writeln('  on error resume next');
    document.writeln('  detectActiveXControl = False');
    document.writeln('  If detectableWithVB Then');
    document.writeln('     detectActiveXControl = IsObject(CreateObject(activeXControlName))');
    document.writeln('  End If');
    document.writeln('End Function');
    document.writeln('\'and the following function handles QuickTime');
    document.writeln('Function detectQuickTimeActiveXControl()');
    document.writeln('  on error resume next');
    document.writeln('  detectQuickTimeActiveXControl = False');
    document.writeln('  If detectableWithVB Then');
    document.writeln('    detectQuickTimeActiveXControl = False');
    document.writeln('    hasQuickTimeChecker = false');
    document.writeln('    Set hasQuickTimeChecker = CreateObject("QuickTimeCheckObject.QuickTimeCheck.1")');
    document.writeln('    If IsObject(hasQuickTimeChecker) Then');
    document.writeln('      If hasQuickTimeChecker.IsQuickTimeAvailable(0) Then ');
    document.writeln('        detectQuickTimeActiveXControl = True');
    document.writeln('      End If');
    document.writeln('    End If');
    document.writeln('  End If');
    document.writeln('End Function');
    document.writeln('</script>');
}

function ut(id,c){
	var d = new Date();
	var isqt = (trackQuickTime) ? detectQuickTime() : false;
	var isfl = (trackFlash) ? detectFlash() : false;
	var isdir = (trackDirector) ? detectDirector() : false;
	var iswm = (trackWindowsMedia) ? detectWindowsMedia() : false;
	var isrl = (trackReal) ? detectReal() : false;
	var isjava = navigator.javaEnabled();
	var n = navigator.appName;
	var res = (screen.width && screen.height) ? screen.width +"x"+ screen.height : '';
	var sc = (!screen.pixelDepth) ? screen.colorDepth : screen.pixelDepth; if (sc == 'undefined') sc = '';
	var ud = new Date(Date()); var gd = new Date(ud.getUTCFullYear(), ud.getUTCMonth(), ud.getUTCDate(), ud.getUTCHours(), ud.getUTCMinutes(), ud.getUTCSeconds());
	var u ="a=1001&js=1&sid="+id;
	var p = "&qt="+ isqt +"&fl="+ isfl +"&dir="+ isdir +"&wm="+ iswm +"&rl="+ isrl +"&java="+ isjava;
	var s ="&res="+ res +"&color="+ sc;
	var tz = "&tzOffset="+ Math.round(((((ud.valueOf() - gd.valueOf()) / 1000) / 60) / 60));
	var uc = "&c="+ c;
	var r =(document.referrer) ? "&referer="+ escape(document.referrer) : "&referer=false";
	var si_uti = new Image();si_uti.src = "http://inbound.imagerygraphics.com/inbound_v2.php?"+ u+p+s+tz+uc+r+"&"+d.getMilliseconds();
}

function st(id){
	var d = new Date();
	var u ="a=1001&js=1&sid="+id;
	var si_sti = new Image();si_sti.src = "http://inbound.imagerygraphics.com/inbound_v2.php?"+ u +"&sh=true&"+d.getMilliseconds();
}

function session(){
	var d = new Date();
	var c = 'false';
	var cn = 'sitrackingsidv2';
	var id = 'false';
	var cookies = document.cookie;
	var ex = new Date(); ex.setTime(ex.getTime() +900000);

	if (cookies.indexOf(cn +'=') != -1){
		var s = (cookies.indexOf(cn +'=')) + cn.length + 1;
		var e = (cookies.indexOf(';', s) != -1) ? cookies.indexOf(';', s) : cookies.length;
		id = cookies.substring(s,e);
	}

	if(id == 'false'){
		document.cookie = cn +'=true;path=/;expires='+ ex.toGMTString();
		c = (document.cookie == '') ? 'false' : 'true';
	} else {
		c = 'true';
	}
	
	if (c == 'true'){
		if (id == 'false'){
			var r ='';
			var k = "f19958B0Ab72162163b75A6aED8356FB75465964E2966279F78C3d509ABBCbFC9EBC4";
			k += "B0AAFF29F0E7157784DBDFB829F77aA686CFbB5F943B2Bd9921ED0C0E12f0c03d4368Cf7732c227F727De83aB97";
			k += "D243D69093D5F70D4EbBC1DF3869c567C8E3335C4048DABb39E265FC118044A631B2E6AaBA99B877A8556EF534E00EE0";
			id = Math.round(d.valueOf()/1000);
			for(var i = 0; i < 10;  i++){ r = Math.round(Math.random() * 255); id += k.substr(r, 1);}
			document.cookie = cn +'='+ id +';path=/;expires='+ ex.toGMTString();
			ut(id, true);
		} else {	
			st(id);
		}
	} else {
		ut(id, false);
	}
	
	return id;
}

var si_flashID = session();