/* GENERAL FUNCTIONS
-----------------------------------------------------*/
var bh = String(window.location).split('/');
var baseHref = bh[0]+'//'+bh[2]+'/';
if(!parseInt(getFlashVersion())) {
	$.cookie('flashOff', '1', { expires: 7, path: '/', domain:bh[2].replace('www.','') });
};

function getFlashVersion(){ 
	try { 
		try { 
			var axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6'); 
			try { axo.AllowScriptAccess = 'always'; } catch(e) { return '6,0,0'; };
		} catch(e) {}; 
		return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g, ',').match(/^,?(.+),?$/)[1]; 
	} catch(e) { 
		try { 
			if(navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin){ 
				return (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g, ",").match(/^,?(.+),?$/)[1]; 
			}; 
		} catch(e) {};
	}; 
	return '0,0,0'; 
};

function setupFlashToggle() {
	var toggleText = 'Turn Flash Off';
	if($.cookie('flashOff')=='1') {
		toggleText = 'Turn Flash On';
		$('<span> | <a href="#">'+toggleText+'</a></span>').appendTo('#foot p').click(toggleFlash);
		return;
	};
	$('<span> | <a href="#">'+toggleText+'</a></span>').appendTo('#foot p').click(toggleFlash);

};

function toggleFlash() {
	var loc;
	if($.cookie('flashOff')=='1') {
		$.cookie('flashOff', '0', { expires: 7, path: '/', domain:bh[2].replace('www.','') });
		var p = String(window.location).replace(baseHref,'');
		loc = (p ? baseHref+'#/'+p : baseHref );
	} else {
		$.cookie('flashOff', '1', { expires: 7, path: '/', domain:bh[2].replace('www.','') });
		loc = (String(window.location).replace('/#','').replace('home/',''));	
	};
	window.location = loc;
	return false;
};

function setIphoneFoot() {
	if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
	 	if (document.cookie.indexOf("iphone_redirect=false") == -1) {
			var h = $(window).height();
			if($(document).height()>$(window).height()) {
				h = $(document).height();
			};
			$("#foot").css({ top:h-$('#foot').height(), position:'absolute' }); 
		};
	};
};

$(document).ready(function() {
	$("tbody tr").filter("tr:odd").addClass("odd").end().filter("tr:even").addClass("even"); 								// TABLE STRIPING	
	$("a[href^='https://'],a[href^='http://'],a[href$='.doc'],a[href$='.pdf'],a[href$='.jpg']").attr("target", "_blank");	// EXTERNAL LINKS IN NEW WINDOW
	
	if(parseInt(getFlashVersion())) {
		setupFlashToggle();
	};
});

window.onload = function() {
	setIphoneFoot();
};