/*
DEPRECATED 10/22/2008

<b>CustomizeBlocks.js</b>
Written by Matthew Martin 09/2005

<b>What does it do?</b>
Allows reader to customize pages by moving content blocks up and down.

<b>How do I use it?</b>
*/

var BLOCKIDS = new Array();

function CustomizeBlocks(pageId) {
	return;

	// get all blocks from the page that have the class Customize
	var pageBlockIds = new Array();
	var allElements = document.getElementsByTagName("DIV");
	for (var elementNumber = 0; elementNumber < allElements.length; elementNumber++) {
		if (allElements[elementNumber].className == "Customize") {
 			pageBlockIds.push(allElements[elementNumber].id);
		}
	}
		
	// check for cookie
	var cookieValue = GetCookie(pageId);
	if (cookieValue) {
		// rearrange blocks according to cookie value
		var cookieBlockIds = cookieValue.split("+");
		
		BLOCKIDS = cookieBlockIds;		
		for (var pageBlockNumber = 0; pageBlockNumber < pageBlockIds.length; pageBlockNumber++) {
			var pushBlockId = true;
			for (var cookieBlockNumber = 0; cookieBlockNumber < cookieBlockIds.length; cookieBlockNumber++) {
				if (cookieBlockIds[cookieBlockNumber] == pageBlockIds[pageBlockNumber]) {
					pushBlockId = false;
					break;
				}
			}
			if (pushBlockId == true) {
				BLOCKIDS.push(pageBlockIds[pageBlockNumber]);
			}
		}
	
		BuildBlocks();
	} else {
		// copy the page blocks to BLOCKIDS
		BLOCKIDS = pageBlockIds;
	}
}

function MoveBlock(pageId,blockId,direction) {
	return;

	var itemPosition;
	var newPosition;
				
	// get the position of the current block in the BLOCKIDS array
	for (var itemNumber = 0; itemNumber < BLOCKIDS.length; itemNumber++) {
  		if (blockId == BLOCKIDS[itemNumber]) {
  			itemPosition = itemNumber;
 		}
	}
				
	// establish new position
	if (direction == 'Up') {
		newPosition = itemPosition - 1;
	}
	if (newPosition < 0) return;
	if (direction == 'Down') {
		newPosition = itemPosition + 1;
	}
	if (newPosition == BLOCKIDS.length) return;
				
	// move block in BLOCKIDS array
	var temporaryItem = BLOCKIDS[newPosition];
	BLOCKIDS[newPosition] = BLOCKIDS[itemPosition];
	BLOCKIDS[itemPosition] = temporaryItem;
	
	BLOCKIDS = UniqueArray(BLOCKIDS);

	// set block positions into cookie
	var now = new Date(); now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
	SetCookie(pageId,BLOCKIDS.join("+"),now,"/","seattletimes.nwsource.com","");	
		
	BuildBlocks();
}

function BuildBlocks() {
	return;

	var customizeDiv = document.getElementById("Customize");
	var containerDiv = document.createElement('DIV');
	
	for (var itemNumber = 0; itemNumber < BLOCKIDS.length; itemNumber++) {
		if (document.getElementById(BLOCKIDS[itemNumber])) {		
			containerDiv.appendChild(document.getElementById(BLOCKIDS[itemNumber]));
		}
	}
	
	RemoveChildNodes(customizeDiv);
	customizeDiv.appendChild(containerDiv);
}
	
function SetCookie(name,value,expires,path,domain,secure) {
	var cookie = name + "=" + escape(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
	document.cookie = cookie;
}
	
function GetCookie(name) {
	var cookie = document.cookie;
	var prefix = name + "=";
	var begin = cookie.indexOf("; " + prefix);
	if (begin == -1) {
		begin = cookie.indexOf(prefix);
		if (begin != 0) return null;
	} else {
		begin += 2;
	}
	var end = document.cookie.indexOf(";",begin);
	if (end == -1) {
		end = cookie.length;
	}
	return unescape(cookie.substring(begin + prefix.length, end));
}

function UniqueArray(array) {
   var r = new Array();
   o:for (var i = 0, n = array.length; i < n; i++) {
      for (var x = 0, y = r.length; x < y; x++)
         if (r[x] == array[i]) continue o;
      r[r.length] = array[i];
   }
   return r;
}

function RemoveChildNodes(node) {
	if (node.hasChildNodes()) {
		while (node.childNodes.length >= 1) {
			node.removeChild(node.firstChild);       
		} 
	}
}