// PARSES QUERY STRING INTO VARIABLES

if (location.search.length != 0) {
var get_vars = new Object();
get_vars.varName = new Array();
get_vars.varValue = new Array();
var q_str = location.search.substring(1);
var temp_var = q_str.split("&");
for (x=0;x<temp_var.length;x++) {
parts = temp_var[x].split("=");
get_vars.varName[x] = parts[0];
if (isNaN(parseFloat(parts[1]))) {
get_vars.varValue[x] = '"' + parts[1] + '"';
} else get_vars.varValue[x] = parts[1];
eval(get_vars.varName[x] + "=" + get_vars.varValue[x]);
}
}

var HOST = 'mikeindustries.com';

// BEGIN MT COMMENT UTILITIES

function isValidEmail(email) {
	if (email.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) {
		return true;
	} else {
		alert ('This does not appear to be a valid e-mail address.  Please enter your e-mail address in the form: you@you.com');
		return false;
	}
}

function setCookie (name, value, expires, path, domain, secure) {
    var curCookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
    document.cookie = curCookie;
}

function getCookie (name) {
    var prefix = name + '=';
    var c = document.cookie;
    var nullstring = '';
    var cookieStartIndex = c.indexOf(prefix);
    if (cookieStartIndex == -1)
        return nullstring;
    var cookieEndIndex = c.indexOf(";", cookieStartIndex + prefix.length);
    if (cookieEndIndex == -1)
        cookieEndIndex = c.length;
    return unescape(c.substring(cookieStartIndex + prefix.length, cookieEndIndex));
}

function deleteCookie (name, path, domain) {
    if (getCookie(name))
        document.cookie = name + "=" + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
}

function fixDate (date) {
    var base = new Date(0);
    var skew = base.getTime();
    if (skew > 0)
        date.setTime(date.getTime() - skew);
}

function rememberMe (f) {
    var now = new Date();
    fixDate(now);
    now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
    setCookie('mtcmtauth', f.author.value, now, '/', HOST, '');
    setCookie('mtcmtmail', f.email.value, now, '/', HOST, '');
    setCookie('mtcmthome', f.url.value, now, '/', HOST, '');
}

function forgetMe (f) {
    deleteCookie('mtcmtmail', '/', HOST);
    deleteCookie('mtcmthome', '/', HOST);
    deleteCookie('mtcmtauth', '/', HOST);
    f.email.value = '';
    f.author.value = '';
    f.url.value = '';
}

//END MT COMMENT UTILITIES

// BEGIN STYLESWITCHER SCRIPTS

  var now = new Date();
  fixDate(now);
  now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);

function setActiveStyleSheet(title) {
  setCookie('style', title, now, '/', HOST, '');
  self.location.href=self.location.href;
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

var cookie = getCookie("style");
var currentstyle = cookie;
var title = cookie ? cookie : getPreferredStyleSheet();

  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }

// END STYLE SWITCHER SCRIPTS

// BEGIN INMAN FLASH REPLACEMENT

var required = 6;
var hasFlash = false;
if(navigator.appVersion.indexOf("MSIE") != -1 && navigator.appVersion.indexOf("Windows") != -1){
	document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
	document.write('on error resume next \n');
	// AFAIK creating an instance of an older version of the Flash object 
	// will return succeed even if the actual installed version is newer.
	document.write('hasFlash = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & required))) \n');  
	document.write('<'+'/scr' + 'ipt\> \n');
	}
else {
	var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"])?navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin:0;
	if (plugin) {
		var isVersion2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
		var flashDescription = navigator.plugins["Shockwave Flash" + isVersion2].description;
		var flashVersion = parseInt(flashDescription.charAt(flashDescription.indexOf(".") - 1));
		hasFlash = flashVersion >= required;
		}
	}


/******************************************************************************
 This classes the <html> element as `hasFlash` if flash is found. This style
 hook can be used to hide our to-be-replaced content before it even comes down
 the datapipe and eliminate the FOPSC ("Flash of Partially Styled Content")
 
 I've determined that the lighter the page weight the greater chance of a FOPSC.
 ******************************************************************************/
if (hasFlash && document.getElementsByTagName && document.getElementsByTagName('html')[0]) {
	document.write ('<style type="text\/css">h2 {visibility: hidden}<\/style>');
	document.getElementsByTagName('html')[0].className += (document.getElementsByTagName('html')[0].className=='')?'hasFlash':' hasFlash';
	}
	
	
/******************************************************************************
 Some utility functions. Look at them--aren't they useful?
 ******************************************************************************/
 
function SI_normalizeWhiteSpace(txt) {
	var rE = /\s+/gi;
	return txt.replace(rE,' ');
}
function SI_forceRedraw() {
	// Corrects a margin-bottom sum bug in Mozilla
	var d = document;
	if (d.body && d.body.style && d.body.className != 'center') {
		d.body.style.height = "1px";
		d.body.style.height = "auto";
	}
}
	

function SI_replaceElement(elem,swf,w,h,afv) {

	var d = document;
	
	if (!hasFlash || !d.getElementsByTagName) return;
	
	var r = new Object();
	r.p = new Object();
	r.e = new Object();
	
	if (elem.indexOf('>')!=-1) {
		// alert('Reference to parent found...');
		elemArray = elem.split('>');
		elem = elemArray[1];
		if (elemArray[0].indexOf('#')!=-1) {
			// alert('Reference to parent's id found...');
			parentArray = elemArray[0].split('#');
			r.p.id 		  = parentArray[1];
			r.p.tagName	  = parentArray[0];
			r.p.className = false;
			}
		else if (elemArray[0].indexOf('.')!=-1) {
			// alert('Reference to parent's className found...');
			parentArray = elemArray[0].split('.');
			r.p.id 		  = false;
			r.p.tagName	  = parentArray[0];
			r.p.className = parentArray[1];
			}
		else {
			r.p.id		  = false;
			r.p.tagName	  = elemArray[0];
			r.p.className = false;
			}
		}
	else {
		// alert('No reference to parent found...');
		r.p.id		  = false;
		r.p.tagName	  = false;
		r.p.className = false;
		}
	
	if (elem.indexOf('#')!=-1) {
		// alert('Reference to element's id found...');
		elemArray = elem.split('#');
		r.e.id 		  = elemArray[1];
		r.e.tagName	  = elemArray[0];
		r.e.className = false;
		}
	else if (elem.indexOf('.')!=-1) {
		// alert('Reference to element's className found...');
		elemArray = elem.split('.');
		r.e.id 		  = false;
		r.e.tagName	  = elemArray[0];
		r.e.className = elemArray[1];
		}
	else {
		r.e.id		  = false;
		r.e.tagName	  = elem;
		r.e.className = false;
		}
	
	if (afv!='') {
		afv = SI_normalizeWhiteSpace(afv);
		// afv = escape(afv);
		afv+= '&'+afv;
		}
	
	var elems = d.getElementsByTagName(r.e.tagName);
	var count = elems.length;
	for (var i=0; i<count; i++) {
		e = elems[i];
		
		if (!r.p.tagName || (((r.p.tagName && !r.p.id && !r.p.className && e.parentNode.nodeName==r.p.tagName.toUpperCase()) || ((r.p.id && e.parentNode.id==r.p.id) || (r.p.className && e.parentNode.className==r.p.className))))) {
			if ((r.e.tagName && !r.e.id && !r.e.className) || (r.e.id && e.id==r.e.id) || (r.e.className && e.className==r.e.className)) {
				
				// alert('Make replacement');
				var txt;
				txt = SI_normalizeWhiteSpace(e.innerHTML);
				var c = d.createElement('div');
				c.className = 'replaced-'+r.e.tagName;
				e.parentNode.replaceChild(c,e);
				// The replaceChild acts like shift() on the
				// array that holds all of our elems. Meaning it
				// removes the first index and the remaining indexes
				// move up one.
				// The length or our elems array decreases by one
				count--;
				// Override the increment on loop index too.
				// We could just use e = elems[0]; above if we knew that
				// every instance of this particular element was going 
				// to be replaced--but there's no way of knowing that's
				// how it will play out.
				i--;

				txt = txt.replace(/&amp;/g, '%26');
				txt = txt.replace(/"/g, '%22');
				fv = 'txt='+txt+afv;

				var swfHTML;
				swfHTML  = '<div class="h2replaced"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+w+'" height="'+h+'">';
				swfHTML += '	<param name="movie" value="'+swf+'" />';
				swfHTML += '	<param name="flashvars" value="'+fv+'" />';
				swfHTML += '	<embed src="'+swf+'" flashvars="'+fv+'" width="'+w+'" height="'+h+'" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer" />';
				swfHTML += '<'+'/object>'+'<'+'/div>';
				c.innerHTML = swfHTML;
				txt='';
				}
			}
		
		}
	}
	
	
/******************************************************************************
 This is where the magic happens. This should really be the only part of this
 script you need to modify. Just add the necessary SI_replaceElement() calls 
 and make sure this sucker is called onload.
 ******************************************************************************/
function SI_flashReplacement() {

	SI_replaceElement('h2','http://www.mikeindustries.com/blog/swfs/txt.swf', 450, 30,'');
	
	// Another Sample:
	// Replace all occurances of `<h3 class="author">` inside `<div class="comment">`
	// Also pass the additional variable `type` a value of `2` to Flash
	// SI_replaceElement('div.comment>h3.author','swf/txt.swf',236,24,'type=2');
	
	SI_forceRedraw();

self.window.focus();

}


/******************************************************************************
 This sets the entire thing in motion. Place any other scripts that need to run
 onload in the SI_onload() function or add SI_flashReplacement to your own 
 onload handler.
 ******************************************************************************/
function SI_onload() {
	SI_flashReplacement();
	}
window.onload = SI_onload;

// END INMAN FLASH REPLACEMENT

// BEGIN TOP NAV

function renderTopNav (topnavmode) {
	var topnavSWF;
	topnavSWF  = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="698" height="30">';
	topnavSWF += '	<param name="movie" value="/blog/swfs/topnav.swf" />';


	topnavSWF += '	<param name="FlashVars" value="mode='+topnavmode+'" />';
	topnavSWF += '	<embed src="/blog/swfs/topnav.swf" width="698" height="30" FlashVars="mode='+topnavmode+'" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer" />';
	topnavSWF += '<'+'/object>';
	document.getElementById('topnav').innerHTML = topnavSWF;
}

// END TOP NAV

// BEGIN WEBCAM

function renderWebCam (epoch,weather) {
	var headerSWF;
	headerSWF  = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="698" height="158">';
	headerSWF += '	<param name="movie" value="/blog/swfs/webcam.swf" />';
	headerSWF += '	<param name="FlashVars" value="epoch='+epoch+'&weather='+weather+'" />';
	headerSWF += '	<embed src="/blog/swfs/webcam.swf" width="698" height="158" FlashVars="epoch='+epoch+'&weather='+weather+'" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer" />';
	headerSWF += '<'+'/object>';
	document.getElementById('header').innerHTML = headerSWF;
}

// END WEBCAM

// BEGIN WINDOW FUNCTIONS

var kingy = null;

function FullScreener(url) {
  if (window.screen) {
  var chasm = screen.availWidth;
  var mount = screen.availHeight;
  kingy = window.open(url,'k1','top=0,left=0,width=' + (chasm - 10) + ',height=' + (mount - 30));

  }
}

function blowOut() {
  if (kingy != null && kingy.open) kingy.close();
}

// END WINDOW FUNCTIONS

// BEGIN DYNAMIC COMMENT PREVIEW FUNCTIONS

// live comment preview  - comment body

function ReloadTextDiv() {
	document.getElementById('TextDisplay').innerHTML = '<p>'+document.getElementById('text').value.replace(/(\r\n|\n)/g,'<br />').replace(/(<br \/>){2,}/gi,'<'+'/p><p>')+'<'+'/p>';
}

// live comment preview - author

function ReloadNameDiv() {
document.getElementById('NameDisplay').innerHTML = document.getElementById('author').value;
}

// END DYNAMIC COMMENT PREVIEW FUNCTIONS

// BEGIN FONT SELECTOR FUNCTIONS

function renderReadability () {
	var typefaces = new Array('Lucida Grande', 'Verdana', 'Helvetica', 'Gill Sans', 'Trebuchet', 'Georgia', 'Times');
	document.write('<h4>Readability:<\/h4><form>');
	document.write('<span id="fontsizemenu">Size:<select name="fontsize" style="font-size: 10px; margin: 2px 0 2px 3px" onChange="changeFontSize(this.options[selectedIndex].value);">');
	for ( var x=9; x <= 24; x++) {
		if (Number(x) == Number(fontsize)) {
			document.write('<option value="'+x+'" selected="selected">'+x+'<\/option>');
		} else {
			document.write('<option value="'+x+'">'+x+'<\/option>');
		}
	}
	document.write('<\/select><\/span>');
	document.write('<span id="fontfamilymenu"><br />Font:<select name="fontfamily" style="font-size: 10px; margin: 2px 0 2px 3px" onChange="changeFontFamily(this.options[selectedIndex].value);">');
	for (i=0; i<typefaces.length; i++) {
		if (fontfamily == typefaces[i]) {
			var notcustom = true;
			document.write('<option value="'+ typefaces[i]+'" selected="selected">'+typefaces[i]+'<\/option>');
		} else {
			document.write('<option value="'+ typefaces[i]+'">'+typefaces[i]+'<\/option>');
		}
	}
	if (!notcustom) {
		document.write('<option value="'+ fontfamily+'" selected="selected">'+fontfamily+'<\/option>');
	}
	document.write('<\/select><\/span><\/form>');
	document.write('<br \/><form onsubmit="changeFontFamily(escape(document.getElementById(\'customfontfield\').value)); self.location.href=self.location.href;"><a href="#" onclick="document.getElementById(\'customfont\').style.display = \'block\'; document.getElementById(\'fontfamilymenu\').style.display = \'none\'; return false" style="text-decoration: underline">Or, specify your own...<\/a>');
	document.write('<div id="customfont" style="display: none; margin: 0; padding: 0">Font: <input id="customfontfield" name="customfontfield" size="8" style="width: 50px; font-size: 10px; margin: 6px 6px 0 0" /><input type="submit" value="Set" style="font-size: 10px" /><\/div>');
	document.write('<\/form>');
}

var fontfamily = getCookie('fontfamily');
var fontsize = getCookie('fontsize');

if (!fontfamily && navigator.userAgent.toLowerCase().indexOf("mac") > -1) {
	var fontfamily = 'Lucida Grande';
} else if (!fontfamily) {
	var fontfamily = 'Verdana';
}
if (!fontsize) {
	var fontsize = 11;
}


function changeFontFamily (fontfamily) {
	setCookie('fontfamily', fontfamily.replace(/%20/g,unescape('%20')), now, '/', HOST, '');
	self.location.href = self.location.href;
}

function changeFontSize (fontsize) {
  setCookie('fontsize', fontsize, now, '/', HOST, '');
  self.location.href = self.location.href;
}

var fontfamilyadjusted;

	if (fontfamily == 'Times') {
		fontfamilyadjusted = '"Times New Roman", Times';
	} else if (fontfamily == 'Trebuchet') {
		fontfamilyadjusted = '"Trebuchet MS", Trebuchet';
	} else {
		fontfamilyadjusted = '"'+fontfamily+'"';
}

document.write('<style type="text/css">');
document.write('#mainpane {font-family:'+fontfamilyadjusted+'; font-size:'+fontsize+'px; line-height: 1.6em}');
document.write('<\/style>');

