// This script includes various functions for the Tomb site

/* Adopts code written by Eric Costello.
Original unmodified version at: http://www.glish.com/css/blogger/

Also see:
http://www.schwa.com
http://www.glish.com
*/

// cookie functions modified from code found at Alexei Kourbatov's javascripter.net/faq/

function ms_setCookie(cookieName,cookieValue) {
	var today = new Date();
	var expire = new Date();
	expire.setTime(today.getTime() + 3600000*24*3000);
	cookieToSet = cookieName+"="+escape(cookieValue) + "; expires="+expire.toGMTString()+"; path=/";
	document.cookie=cookieToSet;
	}
	
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));
	}

function init() {

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

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

	headsize = parseInt(readCookie('headlineSize'));
	if (!headsize>0) headsize=16;

	
	changeType();
	
	}

function changeType() {
	setStyleByTag('body','fontFamily',ff);
	setStyleByTag('body','fontSize',fs+'px');
	setStyleByTag('h3','fontSize',headsize+'px');

	// store these values in cookies for subsequent page loads
	ms_setCookie('fontSize',fs);
	ms_setCookie('fontFamily',ff);
	ms_setCookie('headlineSize',headsize);

	}
	
function defaultFonts() {
	fs = 13;
	headsize = 16;
	ff='Univers, Zurich, Helvetica, Arial, sans-serif';
	changeType();
	}

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

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

// this function is called from the A- button
function normalSize() {
		fs=13;
		changeType();
		}


// this function is called from the A+ button
function increaseHeadline() {
	headsize+=1;
	changeType();
	}

// this function is called from the A- button
function decreaseHeadline() {
	if (headsize>1) {
		headsize-=1;
		changeType();
		}
	}

// this function is called from the A- button
function normalHeadline() {
		headsize=16;
		changeType();
		}
// 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;
		}
	}

function setStyleById(i, p, v) {
	var n = document.getElementById(i);
	n.style[p] = v;
}


function togglecustomizedisplay() {
	isvis = document.getElementById('customizecontrols').style['display'];
	if(isvis == 'none') {isvis = 'block';} else {isvis = 'none';}
	setStyleById('customizecontrols','display', isvis);
	}

function writeControlHeader() {
		document.writeln('<p class="rightlinkheader"><a id="customizelink" href="#" onclick="togglecustomizedisplay()" class="nohighlight">Customize »\<\/a><\/p>')
	}

function writeControls() {
	document.writeln('<span class="rightlink"><span class="widelines"><p>Body text: <br\/>')
	document.writeln('<a href="#" onclick="decreaseSize()">smaller<\/a> | ')
	document.writeln('<a href="#" onclick="normalSize()">normal<\/a> | ')
		document.writeln('<a href="#" onclick="increaseSize()">larger<\/a><\/p>')
		document.writeln('<p>Headlines: <br\/>')
		document.writeln('<a href="#" onclick="decreaseHeadline()">smaller<\/a> | ')
		document.writeln('<a href="#" onclick="normalHeadline()">normal<\/a> | ')
		document.writeln('<a href="#" onclick="increaseHeadline()">larger<\/a><\/p>')		
		document.writeln('<form action="" name="targeter" onsubmit="return false;">')
		document.writeln('<p>Font: <br\/>')
		document.writeln('<select onchange="if(this.selectedIndex>0) {ff=this.options[this.selectedIndex].value;changeType()}">')
		document.writeln('<option value="">choose:<\/option>')
		document.writeln('<option value="Univers, Zurich, Helvetica, Arial">Univers (default)<\/option>')
		document.writeln('<option value="Helvetica Neue, Helvetica, Arial">Helvetica<\/option>')
		document.writeln('<option value="Arial, Helvetica">Arial<\/option>')
		document.writeln('<option value="Verdana, Arial, Helvetica, sans-serif">Verdana<\/option>')
		document.writeln('<option value="Georgia, Times Roman, serif">Georgia<\/option>')
		document.writeln('<\/select>')
		document.writeln('<p>» <a href="#" onclick="defaultFonts()">Restore defaults<\/a><\/p>')
		document.writeln('<\/span><\/span><\/form>')
	}

// This is Max's attempt to write a print function

function printBlogEntry(theID) {
	var theElement = document.getElementById(theID);
	var theContent = theElement.innerHTML;	
	var _w = null;
	_w = window.open();
	_w.document.open();
	_w.document.write('<html><head><title>Print Version</title>');
	_w.document.write('<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" \/>');
	_w.document.write('<link href="http://www.dorsoduro.plus.com/lenin/leninstyles.css" rel="stylesheet" type="text/css" \/>');
	_w.document.write('<\/head><body><div class="printbox">');
	_w.document.write('<img src="http://www.dorsoduro.plus.com/lenin/printlogo.gif" width="269" height="41"><br \/><br \/>');
 	_w.document.write(theContent);
	_w.document.write('<\/div><\/body><\/html>');
 	_w.document.close();
	_w.print();
	_w.close();
	}

function ms_openwindow(theURL) { //v2.0
  	window.open(theURL,'TombComments','status=yes,scrollbars=yes,resizable=yes,width=440,height=450');
	}
