//
//  CURRENT NAVIGATION ITEM USING DOM
//
// v1.7 Copyright (c) 2006 TJKDesign - Thierry Koblentz
// For help, visit http://www.tjkdesign.com/articles/navigation_links_and_current_location.asp
function TJK_hank(zMenu,defaultPage,classToApply,leaveItAlone){
if (document.getElementById && document.createElement && document.getElementById(zMenu)){
var strLocation = (top.location.pathname.lastIndexOf("/")+1 == top.location.pathname.length) ? top.location.hostname + top.location.pathname+defaultPage : top.location.hostname + top.location.pathname;
	var a = document.getElementById(zMenu).getElementsByTagName("a");
		for (var x=0,i=a.length;x<i;x++){
			var nothingToDo = (a[x] && a[x].className && a[x].className==leaveItAlone) ? true : false;
			if (!nothingToDo && a[x] && a[x].href && a[x].href.lastIndexOf("#")+1!=a[x].href.length){
				if (a[x].href.indexOf(strLocation,0)>0 || a[x].href == top.location.protocol + "//" + top.location.hostname + top.location.pathname){
					if (classToApply==""){
						var objNode = a[x];
						var strLink = objNode.firstChild.data;
						objNode.parentNode.innerHTML="<em>"+strLink+"</em>";
					}else{
						a[x].className += " "+classToApply;
					}
				}
			}
		}
	}
}


//
//  STYLE SHEET SWAPPER
//
function setActiveStyleSheet(title) {
  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;
    }
  }
}

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;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);


//
//  FOLIO SAMPLE NAVIGATION
//
function hidestories() {
			// check if stories div exists
			var nostories=document.getElementById('stories');
			if(!nostories){return;}
	var nojsmsg=document.getElementById('stories');  
 	nojsmsg.className= "folioyesjs";					// These two lines swap the class of the div, changing from overflow:scroll to overflow:hidden if the user has JS enabled.
var divs=document.getElementById('stories').getElementsByTagName('div');
for (j=0; j<divs.length; j++) {
var rE = new RegExp("(^|\\s)" + 'story' + "(\\s|$)");
if (rE.test(divs[j].className)) {
divs[j].style.display="none";
}
}
}

function stories(first) {
			// check if thebuttons div exists
			var nothebuttons=document.getElementById('thebuttons');
			if(!nothebuttons){return;}

var thebuttons=document.getElementById('thebuttons').getElementsByTagName('a');
for (i=0; i<thebuttons.length; i++) {
thebuttons[i].onclick=function() {
hidestories();
var thestory=(this.href).split("#",2)[1];
document.getElementById(thestory).style.display="block";
return false;
}
}
if (first) {
var firstone=document.getElementById('stories').firstChild;
if (firstone.nodeType != 1) {firstone = firstone.nextSibling;}
firstone.style.display="block";
}
}




// This script is (c) copyright 2006 Jim Tucek under the
// GNU General Public License (http://www.gnu.org/licenses/gpl.html)
// For more information, visit www.jracademy.com/~jtucek/email/ 
// Leave the above comments alone!

var decryption_cache = new Array();

function decrypt_string(crypted_string,n,decryption_key,just_email_address) {
	var cache_index = "'"+crypted_string+","+just_email_address+"'";

	if(decryption_cache[cache_index])					// If this string has already been decrypted, just
		return decryption_cache[cache_index];				// return the cached version.

	if(addresses[crypted_string])						// Is crypted_string an index into the addresses array
		var crypted_string = addresses[crypted_string];			// or an actual string of numbers?

	if(!crypted_string.length)						// Make sure the string is actually a string
		return "Error, not a valid index.";

	if(n == 0 || decryption_key == 0) {					// If the decryption key and n are not passed to the
		var numbers = crypted_string.split(' ');			// function, assume they are stored as the first two
		n = numbers[0];	decryption_key = numbers[1];			// numbers in crypted string.
		numbers[0] = ""; numbers[1] = "";				// Remove them from the crypted string and continue
		crypted_string = numbers.join(" ").substr(2);
	}

	var decrypted_string = '';
	var crypted_characters = crypted_string.split(' ');

	for(var i in crypted_characters) {
		var current_character = crypted_characters[i];
		var decrypted_character = exponentialModulo(current_character,n,decryption_key);
		if(just_email_address && i < 7)				// Skip 'mailto:' part
			continue;
		if(just_email_address && decrypted_character == 63)	// Stop at '?subject=....'
			break;
		decrypted_string += String.fromCharCode(decrypted_character);
	}
	
	decryption_cache[cache_index] = decrypted_string;			// Cache this string for any future calls

	return decrypted_string;
}

function decrypt_and_email(crypted_string,n,decryption_key) {
	if(!n || !decryption_key) { n = 0; decryption_key = 0; }
	if(!crypted_string) crypted_string = 0;

	var decrypted_string = decrypt_string(crypted_string,n,decryption_key,false);
	parent.location = decrypted_string;
}

function decrypt_and_echo(crypted_string,n,decryption_key) {
	if(!n || !decryption_key) { n = 0; decryption_key = 0; }
	if(!crypted_string) crypted_string = 0;

	var decrypted_string = decrypt_string(crypted_string,n,decryption_key,true);
	document.write(decrypted_string);
	return true;
}

// Finds base^exponent % y for large values of (base^exponent)
function exponentialModulo(base,exponent,y) {
	if (y % 2 == 0) {
		answer = 1;
		for(var i = 1; i <= y/2; i++) {
			temp = (base*base) % exponent;
			answer = (temp*answer) % exponent;
		}
	} else {
		answer = base;
		for(var i = 1; i <= y/2; i++) {
			temp = (base*base) % exponent;
			answer = (temp*answer) % exponent;
		}
	}
	return answer;
}
// -->


//
//  NON JAVASCRIPT SCRIPTING
//

		function email_dc(nojsid) //checks for Javascript and changes the link if not available
		{
			// check if DOM is available
			if(!document.getElementById || !document.createTextNode){return;}
			// check if there is a "No JavaScript" message
			var nojsmsg=document.getElementById(nojsid);
			if(!nojsmsg){return;}

			var newa=document.createElement('a');
			newa.href='javascript:decrypt_and_email(0)';
			var newtxt='Email Design City';
			newa.appendChild(document.createTextNode(newtxt));
			nojsmsg.parentNode.replaceChild(newa,nojsmsg);		
		}

		function folio_samples() //checks for Javascript and adds class to div if not available, allowing scrolling with scrollbar
		{
			// check if there is a "No JavaScript" message
			var nojsmsg=document.getElementById('stories');
			if(!nojsmsg){return;}

			// create a new paragraph and link to the application and replace
			// the non-JavaScript message with it.
			var nojsmsg=document.getElementById('stories');
 			nojsmsg.className+= " folionojs";
		}

function folio_main_nav_high() //called on all folio pages. Highlights the folio link on the main menu when browsing the sub-folio pages
		{
			// check if nav4 exists
			var nonav4=document.getElementById('nav4');
			if(!nonav4){return;}

			var folio_tab=document.getElementById('nav4');
 			folio_tab.firstChild.className+= " selectfolio";
		}

//
//  FOCUS NAVIGATION
//
function hidestories_f() {
			// check if stories div exists
			var nostories=document.getElementById('stories_f');
			if(!nostories){return;}
			var nojsmsg=document.getElementById('stories_f');  
 			nojsmsg.className= "folioyesjs";					// These two lines swap the class of the div, changing from overflow:scroll to overflow:hidden if the user has JS enabled.
var divs=document.getElementById('stories_f').getElementsByTagName('div');
for (j=0; j<divs.length; j++) {
var rE = new RegExp("(^|\\s)" + 'story_f' + "(\\s|$)");
if (rE.test(divs[j].className)) {
divs[j].style.display="none";
}
}
}

function stories_f(first) {
			// check if thebuttons div exists
			var nothebuttons=document.getElementById('thebuttons_f');
			if(!nothebuttons){return;}

var thebuttons=document.getElementById('thebuttons_f').getElementsByTagName('a');
for (i=0; i<thebuttons.length; i++) {
thebuttons[i].onclick=function() {
hidestories_f();
var thestory=(this.href).split("#",2)[1];
document.getElementById(thestory).style.display="block";
return false;
}
}
if (first) {
var firstone=document.getElementById('stories_f').firstChild;
if (firstone.nodeType != 1) {firstone = firstone.nextSibling;}
firstone.style.display="block";
}
}

function sample_select(Gclass) {  // Add "current' class to sample links
if (typeof inactive_sample != 'undefined')  // removes the previous highlighted sample
		{
			var del_sample_class=document.getElementById(inactive_sample);
 			del_sample_class.className= "";
		}	
	else			//inactive_sample is undefined if user has not clicked on a sample button yet, so 01 class is removed.
		{
			var del_sample_class=document.getElementById('sample_1');
 			del_sample_class.className= "";
		}
			
			var active_sample=document.getElementById(Gclass); //adds 'current' class to clicked sample
 			active_sample.className+= " current";
			inactive_sample=Gclass
}

function select_one(){ // gives current class to 01 on page load
			// adds onfocus attributes to all sample links
			if(document.getElementById('sample_1')){
			var curr_sample=document.getElementById('sample_1');
			curr_sample.setAttribute('onmousedown', 'javascript:sample_select(\'sample_1\')');
			}
			if(document.getElementById('sample_2')){
			var curr_sample=document.getElementById('sample_2');
			curr_sample.setAttribute('onmousedown', 'javascript:sample_select(\'sample_2\')');
			}
			if(document.getElementById('sample_3')){
			var curr_sample=document.getElementById('sample_3');
			curr_sample.setAttribute('onmousedown', 'javascript:sample_select(\'sample_3\')');
			}
			if(document.getElementById('sample_4')){
			var curr_sample=document.getElementById('sample_4');
			curr_sample.setAttribute('onmousedown', 'javascript:sample_select(\'sample_4\')');
			}
			if(document.getElementById('sample_5')){
			var curr_sample=document.getElementById('sample_5');
			curr_sample.setAttribute('onmousedown', 'javascript:sample_select(\'sample_5\')');
			}
			if(document.getElementById('sample_6')){
			var curr_sample=document.getElementById('sample_6');
			curr_sample.setAttribute('onmousedown', 'javascript:sample_select(\'sample_6\')');
			}
			if(document.getElementById('sample_7')){
			var curr_sample=document.getElementById('sample_7');
			curr_sample.setAttribute('onmousedown', 'javascript:sample_select(\'sample_7\')');
			}

	
			// check if sample button 01 exists
			var sample_1_link=document.getElementById('sample_1');
			if(!sample_1_link){return;}
 			sample_1_link.className= "current";
}