function init()
{
	initAccordions();
}




var sortColumn = 0;


var xmlHttp = false;
try
{
	xmlHttp = new XMLHttpRequest();
}
catch (exception)
{
	try
	{
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch (exception)
	{
		xmlHttp = false;
	}
}

function pm_getLiveSearchResults()
{
	var searchString = document.getElementById('search_query_string').value;
	var divObject = document.getElementById('search_results');
	var url = "http://www.cocoacheerleaders.com/cgi-bin/WebObjects/CocoaCheerleaders.woa/wa/search?searchString=" + searchString;
	xmlHttp.open("GET", url);
	xmlHttp.onreadystatechange = function()
	{
		if ((xmlHttp.readyState == 4) && (xmlHttp.status == 200))
		{
			divObject.innerHTML = "";
			divObject.innerHTML = xmlHttp.responseText;
			window.scrollTo(0, 0);
		}
	}
	xmlHttp.send(null);
}


function pm_getLiveSearchResultsFloating()
{
	var searchString = document.getElementById('search_query_string').value;
	var divObject = document.getElementById('floating_search_results');
	var url = "http://www.cocoacheerleaders.com/cgi-bin/WebObjects/CocoaCheerleaders.woa/wa/search?searchString=" + searchString;
//	var url = "http://195.147.94.26:55555/cgi-bin/WebObjects/CocoaCheerleaders.woa/wa/search?searchString=" + searchString;
	xmlHttp.open("GET", url);
	xmlHttp.onreadystatechange = function()
	{
		if ((xmlHttp.readyState == 4) && (xmlHttp.status == 200))
		{
			if (searchString != "")	
			{
				var contentObject = document.getElementById('content');
				contentObject.className = 'content_in_background';

				var panelObject = document.getElementById('floating_search_panel');
				panelObject.style.visibility = 'visible';

				divObject.innerHTML = "";
				divObject.innerHTML = xmlHttp.responseText;
				window.scrollTo(0, 0);
			}		
			else
			{
				closeSearch();
			}
		}
	}
	xmlHttp.send(null);
}


function closeSearch()
{
//	fade("floating_search_panel", 100, 0, -10, 10);

	
	var contentObject = document.getElementById('content');
	contentObject.className = 'content_in_foreground';

	var panelObject = document.getElementById('floating_search_panel');
	panelObject.style.visibility = 'hidden';

	window.scrollTo(0, 0);
}




//	scripts from moo.fx...

//the main function, call to the effect object
function initAccordions(){
	
	
	var stretchers = document.getElementsByClassName('item_content'); // element that can stretch
	var toggles = document.getElementsByClassName('item_clicker'); // element that can be clicked on

	//accordion effect
	var myAccordion = new fx.Accordion(
		toggles, stretchers, {opacity: true, duration: 200}
	);

	//hash function
		
	function checkHash(){
		var found = false;
		toggles.each(function(h3, i){
			if (window.location.href.indexOf(h3.title) > 0) {
				myAccordion.showThisHideOpen(stretchers[i]);
				found = true;
			}
		});
		return found;
	}
		
	if (!checkHash()) myAccordion.showThisHideOpen(stretchers[0]);	
}




function sort(column)
{
	fade("items", 100, 0, -100, 0);

	//	work out which sort type we want...
	sortColumn = (column.options[column.selectedIndex].value);

	//	get hold of the table, the body, and the rows...
	var table = document.getElementById('items');
	var tableBody = table.getElementsByTagName('tbody')[0];
	var tableRows = tableBody.getElementsByTagName('tr');
	var itemCount = tableRows.length;

	//	create an array of items by cloning each row in the table...
	var items = new Array();
	for (var itemIndex = 0; itemIndex < itemCount; itemIndex++)
	{
		items[itemIndex] = tableRows[itemIndex].cloneNode(true);
	}

	//	sort the array of items (first column is date (number), second is name (text)...
	if (sortColumn == 0)
	{
		items.sort(compareIntReverse);
	}
	else if (sortColumn == 1)
	{
		items.sort(compareText);
	}

	//	create a new table body...
	var newTableBody = document.createElement('tbody');
	for (var itemIndex = 0; itemIndex < itemCount; itemIndex++)
	{
		newTableBody.appendChild(items[itemIndex]);
	}

	//	and swap the new table in...

	
	table.replaceChild(newTableBody, tableBody);

	initAccordions();
	fade("items", 0, 100, 5, 20);

}

function compareInt(firstRow, secondRow)
{
	var firstValue = parseInt(firstRow.getElementsByTagName('td')[sortColumn].firstChild.nodeValue);
	var secondValue = parseInt(secondRow.getElementsByTagName('td')[sortColumn].firstChild.nodeValue);
	return (firstValue == secondValue ? 0 : (firstValue > secondValue ? 1 : -1));
}

function compareIntReverse(firstRow, secondRow)
{
	var firstValue = parseInt(firstRow.getElementsByTagName('td')[sortColumn].firstChild.nodeValue);
	var secondValue = parseInt(secondRow.getElementsByTagName('td')[sortColumn].firstChild.nodeValue);
	return (firstValue == secondValue ? 0 : (firstValue > secondValue ? -1 : 1));
}



function compareText(firstRow, secondRow)
{
	var firstValue = firstRow.getElementsByTagName('td')[sortColumn].firstChild.nodeValue;
	var secondValue = secondRow.getElementsByTagName('td')[sortColumn].firstChild.nodeValue;
	return (firstValue == secondValue ? 0 : (firstValue > secondValue ? 1 : -1));
}




//	setOpacity takes an object and an opacity value (0..100)
//	and sets the appropriate opacity.

function setOpacity(object, opacity)
{
	opacity = (opacity == 100 ? 99.999 : opacity);
	
	//	Safari 1.2, Firefox, Mozilla, CSS3...
	object.style.opacity = opacity / 100;

	//	Old Mozilla, Firefox...
	object.style.MozOpacity = opacity / 100;

	//	Old Safari, Konqueror...
	object.style.KHTMLOpacity = opacity / 100;

	//	IE/Win...
	object.style.filter = "alpha(opacity:"+opacity+")";
}


function setOpacityForId(objectId, opacity)
{
	if (document.getElementById)
	{
		object = document.getElementById(objectId);
		setOpacity(object, opacity);
	}
}

function fade(objectId, opacity, targetOpacity, increment, timeout)
{
	if (document.getElementById)
	{
		object = document.getElementById(objectId);
		if (((increment > 0) && (opacity <= targetOpacity)) || ((increment < 0) && (opacity >= targetOpacity)))
		{
			setOpacity(object, opacity);
			opacity += increment;
			window.setTimeout("fade('" + objectId + "', " + opacity + ", " + targetOpacity + ", " + increment + ", " + timeout + ")", timeout);
		}
	}
}


function pm_loglink(link)
{
	parsedLink = (link.href).replace(/[[:punct:]]/g, '_');
	trackLink = "/outgoing/" + parsedLink;
	urchinTracker(trackLink);
}



