/***********************************************
* Encrypt Email script- Please keep notice intact.
* Tool URL: http://www.dynamicdrive.com/emailriddler/
    caffeinated by mr_coffee ...
    btw... document.write is lazy.
* **********************************************/
function copyrightemaillink() {
	var aLink = $('copyrightemail');
	if (aLink){
    var emailarray7933= new Array(109,114,99,111,102,102,101,101,64,109,114,99,111,102,102,101,101,46,119,115);
    var postemail7933='';
    for (var i=0;i<emailarray7933.length;i++) {
      postemail7933+=String.fromCharCode(emailarray7933[i]);
    }
    var altLink = document.createElement("span");
    altLink.innerHTML = '<a href="mailto:'+postemail7933+'" class="copyrightemaillink" title="Contact mr_coffee"> </a>';
    aLink.parentNode.replaceChild(altLink, aLink);
  }
}
function msnlink() {
  var aLink = $('msnlink');
  if (aLink){
    var emailarray7933= new Array(109,114,99,111,102,102,101,101,64,109,114,99,111,102,102,101,101,46,119,115);
    var postemail7933='';
    for (var i=0;i<emailarray7933.length;i++) {
      postemail7933+=String.fromCharCode(emailarray7933[i]);
    }
    var altLink = document.createElement("span");
    altLink.innerHTML = '<a href="mailto:'+postemail7933+'" title="Contact mr_coffee">'+postemail7933+'</a>';
    aLink.parentNode.replaceChild(altLink, aLink);
  }
}
function mrcoffeeemail() {
  var aLink = $('mrcoffeeemail');
  if (aLink){
    var emailarray7933= new Array(109,114,99,111,102,102,101,101,64,109,114,99,111,102,102,101,101,46,119,115);
    var postemail7933='';
    for (var i=0;i<emailarray7933.length;i++) {
      postemail7933+=String.fromCharCode(emailarray7933[i]);
    }
    var altLink = document.createElement("span");
    altLink.innerHTML = '<a href="mailto:'+postemail7933+'" title="Contact mr_coffee">'+postemail7933+'</a>';
    aLink.parentNode.replaceChild(altLink, aLink);
  }
}
/*
	End obufscated e-mail functions
*/


/* title request function */
function choosetitle(thetitle) {
	var page_title = "";
	switch (thetitle) {
	  case "":									page_title = "Home"; break;
		case "index.htm":   			page_title = "Home"; break;
		case "info.htm":   				page_title = "Info/Pic"; break;
		case "coffee.htm": 				page_title = "Coffee"; break;
		case "links.htm":  				page_title = "Links"; break;
		case "info/aspire.htm":  	page_title = "Aspire"; break;
		case "info/walk.htm":  		page_title = "Took a walk around the block one day..."; break;
		case "info/work.htm":  		page_title = "Where I live and work"; break;
		case "info/oscar.htm":  	page_title = "The coolest cat in the known universe."; break;
		case "info/mypics.htm":  	page_title = "My Pictures"; break;
		default:									page_title = thetitle;
	}
	return page_title;
}

/* History Variables */
var baseUrl = "http://mrcoffee.ws/index.php";
var history_man = new Array();
var history_num = 0;
history_man[0] = baseUrl + "#" + "index.htm";

/* History Functions */
var loccheck = function() {
	var testUrl = (top.location.href == baseUrl ? history_man[0] : top.location.href);
	if (window.ie) {	
		var loc = window.frames['iehistoryframe'].document.getElementById('iehistorylocation').innerHTML;		
		testUrl = (loc == '' ? history_man[0] : baseUrl + '#' + loc);
	}
	if ( testUrl != history_man[history_num]) {
		if (testUrl == history_man[history_num-1]) {
			history_num--;
			updateAjax(history_man[history_num],true);
		}	else updateAjax(history_man[history_num+1]);
	}
};

var iehistoryfix = function() {
	var iehistory = top.document.createElement('iframe');
	iehistory.src = 'blank.htm';
	iehistory.id = 'iehistoryframe';
	iehistory.style.display = 'none';
	top.document.getElementsByTagName('body')[0].appendChild(iehistory);
}

var updateiehistory = function(page) {	
	var ieDoc = window.frames['iehistoryframe'].document;
	ieDoc.open();
	ieDoc.write('<html><body id="iehistorylocation">' + page + '</body></html>');
	ieDoc.close();		
}

/*
Ajax Request Functions
*/
function updateAjax(requrl,historycall){	
	if ($defined(requrl)){
		// gather 'hash'	
		var requested = requrl.match(/(?:http\:\/\/mrcoffee\.ws\/index\.php)(?:.)(.+)/)[1];
		// gather title
		var page_title = choosetitle(requested);
	
		// update hash
		top.location.hash = requested;
	
		// update titles
		$('logotitle').innerHTML = page_title;
		document.title = 	"InProgress... " + page_title
	
		// update history
		if (!historycall) {
			history_num++;
			history_man[history_num] = baseUrl + "#" + requested;
			if (window.ie) updateiehistory(requested);
		}
	
		// make ajax request
		req.url = baseUrl + "/" + requested;
		req.request();
	}
}

var req = new Ajax('',{
	method: 'get',
	update: 'wrapper',
	evalScripts: true,
	onComplete: function(){
		if ( this.url.match('info.htm') ){  // this is the page the pic links are on, they have their own history
			$$('a.ajaxreq').each( function(el) {
				el.addEvent('click', function(e) {
					if (e) new Event(e).stop();
					updateAjax(el.href);
				});
			});
		}
		if ( this.url.match('info') ){  // picture pages need special js and css for slimbox.
			Window.addEvent('domready', Lightbox.init.bind(Lightbox));
		}
		if (window.ie) fixietransparency();
	}
});

// small function to correct CSS for smaller screen resolutions.
function fixwrapperwidth(){	
	if (window.getWidth() <= 800) {  // trying to detect 800px screen width.  Safe bet as a number.
	  $('wrapper').style.width = "536px";
	  $('wrapper').style.maxWidth = "536px";		 
	}
}

function fixietransparency() {		
	$$('#wrapper hr').setStyle('filter','alpha(opacity="0")');	
	$$('.tool-tip').setStyle('filter','progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod="image", src="http://images.mrcoffee.ws/bubble2-ie.png")');	
}

Window.addEvent('domready', function() {
	fixwrapperwidth();
	var myTips = new Tips($$('.toolTipElement'), {
		timeOut: 700,
		maxTitleChars: 70, 
		maxOpacity: .9 /*let's leave a little transparancy in there */						
	});
	
	

	// convert nav links to ajax links.
	$$('a.toolTipElement').each(function(el, i) {
		if (i <= 3) {  // if it's not my external links (news.mrcoffee.ws/inprogress.us)
			el.addEvent('click', function(e) {
				if (e) new Event(e).stop();
				updateAjax(el.href);
			});
		}
	});

  new SmoothScroll();
  
  if (window.ie) {
  	iehistoryfix();  // initiate history for IE
		fixietransparency(); // fix transparency in IE
	}
	
	// history checking on interval
	setInterval(loccheck, 1000);
	// refresh/bookmark check
	if (top.location.hash) updateAjax(baseUrl + "/" + top.location.hash.slice(1));
});