
// masthead randomiser

function randomSplash()

{
var splashImage=new Array()

// location of images
splashImage[0]="http://www.desludge.com/images/.jpg"
splashImage[1]="http://www.desludge.com/images/.jpg"
splashImage[2]="http://www.desludge.com/images/.jpg"
splashImage[3]="http://www.desludge.com/images/.jpg"
splashImage[4]="http://www.desludge.com/images/.jpg"
splashImage[5]="http://www.desludge.com/images/.jpg"
splashImage[6]="http://www.desludge.com/images/.jpg"

// date grabber
dateVar = new Date(); 
var todaysImage	= dateVar.getDay()

document.write('<a class=\"imgLink\" href=\"http://www.desludge.com\"><img src=\"'+splashImage[todaysImage]+'" alt=\"Desludge\" title=\"Desludge\" width=\"700\" height=\"190\" border=\"0\" style=\"margin: 0px; padding: 0px;\"/><\/a>')
}



// set up centering information

var h = screen.availHeight, w= screen.availWidth;
var popW = 200, popH = 200;
var leftCoord = (w-popW)/2, topCoord = (h-popH-50)/2;

//imgSrc driven by HREF

function newWindow() 
{

windowDefinition=window.open("","ImageWindow","toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width="+popW+",height="+popH+",left="+leftCoord+",top="+topCoord+"");

windowDefinition.document.open();

// HTML area - if editing, remember to close all quotes or page will die
// font face junk added due to IE 5 Mac bug

windowDefinition.document.write("<html><head><title>Name Video or Image here</title></head>");
windowDefinition.document.write("<body bgcolor=\"black\" style=\"height: 100%; background: #000; margin: 0px;\" leftmargin=\"0\" topmargin=\"0\">");
windowDefinition.document.write("<center><table height=\"100%\"><tr><td valign=\"middle\"><embed src=\"../images/name of image flash or shockwave.dcr\" width=\"144\" height=\"145\" /></td></tr></table>");
windowDefinition.document.write("</body></html>");
windowDefinition.document.close();
}


// div swapper
// This version also toggles a close box

function swap(targetId,buttonId){
  
  if (document.getElementById)
        {
        target = document.getElementById(targetId);
        buttonName = document.getElementById(buttonId);
        
            if (target.style.display == "none")
                {
                target.style.display = "";
                } 
            
            else 
                {
                target.style.display = "none";
                }
                
            if (target.style.display == "none")
                {
                buttonName.src = "images/box_open.gif";
                }
            else 
                {
                buttonName.src = "images/box_close.gif";
                }
        }
}


// image and div swapper for screen grabs

function swapImage(targetId,buttonId,grabName){
  
   if (document.getElementById)
        {
        target = document.getElementById(targetId);
        buttonName = document.getElementById(buttonId);
        
            if (target.style.display == "none")
                {
                target.style.display = "";
                } 
            
            else 
                {
                target.style.display = "none";
                }
                
            if (target.style.display == "none")
                {
                buttonName.src = "images/box_open.gif";
                }
            else 
                {
                buttonName.src = "images/box_close.gif";
                document.images.screenOne.src = "images/grabs/" + grabName + "_1.jpg";
    	  		document.images.screenTwo.src = "images/grabs/" + grabName + "_2.jpg";
 				document.images.screenThree.src = "images/grabs/" + grabName + "_3.jpg";
                }
        }
}


// internal three-screen image swapper 

function internalSwap(grabName){
        document.images.screenOne.src = "images/grabs/" + grabName + "_1.jpg";
    	document.images.screenTwo.src = "images/grabs/" + grabName + "_2.jpg";
 		document.images.screenThree.src = "images/grabs/" + grabName + "_3.jpg";
}



// Font switcher by Eric Costello http://www.glish.com 
// Original version http://www.glish.com/css/blogger/

if (document.getElementById) {

	// read cookie to get font family, set to default Verdana if first timer
	ff = readCookie('fontFamily');
	if (ff=='') ff='Verdana, Arial, Helvetica, sans-serif';

	// read cookie to get font size, set to default 12 if first timer
	fs = parseInt(readCookie('fontSize'));
	if (!fs>0) fs=12;

	// set the appropriate font sizes for the relevant HTML elements
	var body_fs, h1_fs, h2_fs, h3_fs, h4_fs;
	
	setSizes();

	// styles with the changeable values from the cookies
	document.writeln('<style>');
	document.writeln('body{font-size:'+body_fs+'px;}');
	document.writeln('body{font-family:'+ff+';}');
	document.writeln('h1{font-size:'+h1_fs+'px; margin-top: 0px; font-weight: normal;}');
	document.writeln('h2{font-size:'+h2_fs+'px; margin-top: 30px; font-weight: normal;}');
	document.writeln('h3{font-size:'+h3_fs+'px;}');
	document.writeln('h4{font-size:'+h4_fs+'px;}');
	document.writeln('<\/style>');
	}


// called from body onload

	
	
// this changes the sizes of the various elements relative to the fs
function setSizes() {
	body_fs = fs
	h1_fs = body_fs+12;
	h2_fs = body_fs+12;
	h3_fs = body_fs+4;
	h4_fs = body_fs+3;
	}

function changeType() {
	if (!document.getElementsByTagName) {return false;} // unclean! unclean!
	// because NS6 seems to freak out on abs. positionined divs
	// when you change a style property of the body, we have to
	// set the fontFamily and fontSize on div elements and not the body
	setStyleByTag('div','fontFamily',ff);
	setStyleByTag('div','fontSize',body_fs+'px');
	setStyleByTag('h1','fontSize',h1_fs+'px');
	setStyleByTag('h2','fontSize',h2_fs+'px');
	setStyleByTag('h3','fontSize',h3_fs+'px');
	setStyleByTag('h4','fontSize',h4_fs+'px');
	
	// store these values in cookies for subsequent page loads
	setCookie('fontSize',fs);
	setCookie('fontFamily',ff);
	}

// this function is called from the A+ button
function increaseSize() {
	fs+=1;
	setSizes();
	changeType();
	}

// this function is called from the A- button
function decreaseSize() {
	if (body_fs>1) {
		fs-=1;
		setSizes();
		changeType();
		}
	}

// addition called from the default button
function defaultSize() {
	fs=12;
	setSizes();
	changeType();
	}

// controls in sidebar
function writeControls() {	
	if (document.getElementsByTagName) {
		document.writeln('<form style=\"margin: 0px;\" action="" name="targeter" onsubmit="return false;">')
		document.writeln('<p><input type="button" id="textUp" class="buttonHomePage" onclick="increaseSize()" value="T+" \/> ')
		document.writeln('<input type="button" id="textDown" class="buttonHomePage" onclick="decreaseSize()" value="T-" \/> ')
		document.writeln('<input type="button" id="textDefault" class="buttonHomePage" onclick="defaultSize()" value="Default" \/><\/p>')

//		document.writeln('<p><select class= \"fieldHomePage\" onchange="if(this.selectedIndex>0) {ff=this.options[this.selectedIndex].value;changeType()}">')
	//	document.writeln('<option value="">Choose font:<\/option>')
	//	document.writeln('<option value="Verdana, Arial, Helvetica, sans-serif">Verdana<\/option>')
	//	document.writeln('<option value="Arial, Helvetica">Arial<\/option>')
	//	document.writeln('<option value="Georgia, Times Roman, serif">Georgia<\/option>')
	//	document.writeln('<option value="Lucida console, Monaco, monospace">Lucida<\/option>')
	//	document.writeln('<\/select><\/p>')

		document.writeln('<p style=\"padding-top: 4px;\"><input type=\"checkbox\" name=\"targetnewbox\" id=\"targetnew\" onclick=\"doTarget();\" /> Ext. links in new windows<\/p>')
		document.writeln('<\/form>')
		}
	}

// cookie functions modified from code found at Alexei Kourbatov's javascripter.net/faq/
function setCookie(cookieName,cookieValue) {
	var today = new Date();
	var expire = new Date();
	expire.setTime(today.getTime() + 3600000*24*3000);
	document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire.toGMTString();
	}
	
function readCookie(cookieName) {
	var theCookie=""+document.cookie;
	var ind=theCookie.indexOf(cookieName);
	if (ind==-1 || cookieName=="") return ""; 
	var ind1=theCookie.indexOf(';',ind);
	if (ind1==-1) ind1=theCookie.length; 
	return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
	}


// These 2 setstyle functions were modified from code by Steven Champeon found at
// http://developer.apple.com/internet/_javascript/styles.html

// setStyleByTag: given an element type, style property and value
// args:
//  e - element type or id
//  p - property
//  v - value
function setStyleByTag(e, p, v) {
	var elements = document.getElementsByTagName(e);
	for(var i = 0; i < elements.length; i++) {
		elements.item(i).style[p] = v;
		}
	}

// setStyleById: given an element id, style property and 
// value, apply the style.
// args:
//  i - element id
//  p - property
//  v - value
// 
function setStyleById(i, p, v) {
	var n = document.getElementById(i);
	n.style[p] = v;
}


// from http://www.randomwalks.com/links.html




var today = new Date();
var zero_date = new Date(0,0,0);
today.setTime(today.getTime() - zero_date.getTime());
var expiry = new Date(today.getTime() + 365 * 24 * 60 * 60 * 1000); // 3.1536e+10

// var todays_date = new Date(today.getYear(),today.getMonth(),today.getDate(),0,0,0);
//var expires_date = new Date(today.getTime() + (8 * 7 * 86400000)); // 4.8384e+9

// Cookie functions derived from the Bill Dortch code at 
// http://www.hidaho.com/cookies/cookie.txt
function getCookieVal (offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1) { endstr = document.cookie.length; }
	return unescape(document.cookie.substring(offset, endstr));
	}

function GetCookie (name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg) {
			return getCookieVal (j);
			}
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break; 
		}
	return null;
	}

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 SetCookie (name,value,expires,path,domain,secure) {
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
	}


function targetLinks(where) {
	//(!comments || (comments == 'false')) ? wherecomm = "_top" :	wherecomm = "_blank";
	for (linkdex=0; linkdex<=(document.links.length-1); linkdex++) {
		//alert(document.links[linkdex].pathname);
			if ((document.links[linkdex].protocol != "javascript:") && (document.links[linkdex].hostname.indexOf('matt-n-mel') == -1))
				document.links[linkdex].target = where;

		}
}

function doTarget() {

	if (document.targeter.targetnewbox.checked)
		where = "_blank";
	else
		where = "_top";
		
	// cookies = where+" "+wherecomm;
  	// alert(cookies);
	SetCookie('where', where, expiry, "/", ".desludge.com");
	targetLinks(where);

}

