var viewNames = new Array('regionIndex','atozIndex');
document.currentView = viewNames[0];
function selectLeftWsTab(id) {
    for(var i = 0; i < 2; i++) {
        divId = 'leftnav_ws_tab_' + i;
        var div = document.getElementById(divId);
        if (!div) { continue; }
        if (divId == id) {
            div.style.border = 'solid #333366 1px';
            div.style.padding = '1px';
            setCookieValue(COOKIE_LEFTWSTAB,id);
            var iframe = document.getElementById('leftnav_ws');
            switchTab(viewNames[i]);
        } else {
            div.style.border = '0px';
            div.style.padding = '2px';
        }
    }
}
function getLeftWsTab(defaultTab)
{
    var val = getCookieValue(COOKIE_LEFTWSTAB);
    if (!val) { 
        val = defaultTab;
    }
    return val;
}
var printWin;
function doPrint()
{
    printWin = window.open('','printWin','width=600,height=400');
    var title = getSpanContent('title');
    printWin.document.writeln('<link href="print.css" rel="stylesheet" type="text/css">');
    printWin.document.writeln('<title>AncientScripts.com: ' + title + '</title>');
    printWin.document.writeln('<span class=title>');
    printWin.document.writeln(title);
    printWin.document.writeln('</span>');
    printWin.document.writeln('<span class="content">');
    printWin.document.writeln(getSpanContent('content'));
    printWin.document.writeln('</span>');
    printWin.document.close();
    setTimeout('realPrint()', 100);
}
function getSpanContent(name) {
    var span = document.getElementById(name);
    return span.innerHTML;
}
function realPrint() {
    if (printWin) {
        printWin.print();
        printWin.close();
        printWin = 0;
    }
}
function doSearch() {
}
function showFontSize() {
    scroll(0,0);
    var div = document.getElementById('font_size');
    div.style.visibility = 'visible';
}
function hideFontSize() {
    var div = document.getElementById('font_size');
    div.style.visibility = 'hidden';
}
function setFontSize(size) {
    var span = document.getElementById('content');
    if (span) {
        span.style.fontSize = size;
        setCookieValue('fontSize',size,false);
    }
}
function setDefaultFontSize() {
    var fontSize = getCookieValue('fontSize');
    if (fontSize) {
        setFontSize(fontSize);
    }
}

var onLoadHandlers = new Array();
function addOnLoadHandler(handler) {
	onLoadHandlers[onLoadHandlers.length] = handler;
}
function callOnLoadHandlers() {
	for(var i = 0; i < onLoadHandlers.length; i++) {
		onLoadHandlers[i]();
	}
}

var NUM_LOGOS = 6;
function randomLogo() {
	document.write("<img src=\"images/logo"+parseInt(Math.random()*NUM_LOGOS+1)+".gif\">");
}

var LEFT_ALIGN = 1;
var RIGHT_ALIGN = 2;

// implements something like printf
function Format(pattern) {
	this.fragments = new Array();
	var parts = pattern.split("%");
	var i = 1;
	while (i < parts.length) {
		var fragment = null;
		if (parts[i] == "") {
			// double %
			fragment = new FormatFragment(1, "%", LEFT_ALIGN);
		} else if (parts[i].charAt(0) == "-") {
			//parsePadding(parts[i].substring(
		} else if (parts[i].charAt(0) == "0") {
		
		} else {
		
		}
	}
	return this;
}

function parsePadding(token) {

}

function FormatFragment() {

}

function SlideShow(imageId,indexId,totalId) {
	this.pictures = new Array();
	this.imageId = imageId;
	this.indexId = indexId;
	this.totalId = totalId;
	this.index = 0;
	this.addPicture = function(url) {
		var image = new Image();
		image.src = url;
		this.pictures[this.pictures.length] = image;
	}
	this.getPictureCount = function() {
		return this.pictures.length;
	}
	this.gotoPictureAt = function(index) {
		this.index = index;
		var image = document.getElementById(this.imageId);
		if (image) {
			image.src = this.pictures[this.index].src;
			this.updateTextBlocks();
		}
	}
	this.gotoNextPicture = function() {
		this.gotoPictureAt((this.index + 1) % this.pictures.length);
	}
	this.gotoLastPicture = function() {
		var i = this.index - 1;
		if (i < 0) { 
			i += this.pictures.length; 
		}
		this.gotoPictureAt(i);
	}
	this.updateTextBlocks = function() {
		var indexBlock = document.getElementById(this.indexId);
		indexBlock.innerHTML = this.index + 1;
		var totalBlock = document.getElementById(this.totalId);
		totalBlock.innerHTML = this.pictures.length;
	}
	return this;
}

if (navigator.userAgent.indexOf("MSIE")) {
    document.writeln("<style>.u { font-family: Microsoft Sans Serif; }</style>");
}
function unblackout() {
	document.getElementById('blackout').style.display = 'none';
	document.getElementById('page').style.display = 'block';
}
function blackout() {
	var cookies = document.cookie.split(';');
	var ts = 0;
	for(var i = 0; i < cookies.length; i++) {
		var v = cookies[i];
		if (v.indexOf('sopa=') == 0) {
			ts = parseInt(v.substring(5));
		}
	}
	var now = new Date().getTime();
	var diff = now - ts;
	if (diff > 60000) {
		document.getElementById('page').style.display = 'none';
		document.cookie = 'sopa=' + now;
		var div = document.createElement("DIV");
		div.id = 'blackout';
		div.style.position = 'absolute';
		div.style.top = '0px';
		div.style.left = '0px';
		div.style.zIndex = 10000;
		div.style.width = '100%';
		div.style.height = '100%';
		div.style.backgroundColor = '#000000';
		div.style.fontFamily = 'Courier New';
		div.style.textAlign = 'center';
		div.onclick = unblackout;
		div.innerHTML = 
			'<div style="padding-top: 100px; font-size: 24px; color: #EEEEEE; font-weight: bold">DEFEAT SOPA AND PIPA</div>' +
			'<div style="padding-top: 100px; font-size: 16px; color: #CCCCCC; font-weight: bold"><a href=\"http://en.wikipedia.org/wiki/Wikipedia:SOPA_initiative/Learn_more\">Learn More</a></div>' +
			'<div style="padding-top: 100px; font-size: 16px; color: #CCCCCC; font-weight: bold">Contact your <a href=\"http://www.house.gov/representatives/find/\">Representative</a> and your <a href=\"http://www.senate.gov/general/contact_information/senators_cfm.cfm\">Senator</a></div>' +
			'<div style="padding-top: 100px; font-size: 12px; color: #999999; font-weight: bold">Click anywhere to return to Ancient Scripts</div>'
		;
		document.body.appendChild(div);
	}
}
//window.setTimeout(blackout, 1000);

