function clearText(field){
	if (field.defaultValue == field.value) field.value = '';
	else if (field.value == '') field.value = field.defaultValue;
}

// Get the current date and time

function showDate() {

	var currentTime = new Date();

var months = new
Array('January','February','March','April','May','June','July','August','September','October','November','December');

	var month = months[currentTime.getMonth()];

	var day = currentTime.getDate();

	var year = currentTime.getFullYear();

	var time = "";

	var pmam = "";

	var hours = currentTime.getHours();

	var minutes = currentTime.getMinutes();

	if (minutes < 10) {

		minutes = "0" + minutes;

	}

	if(hours > 11){

	pmam = "PM";

	} else {

	pmam = "AM";

	}

	if(hours >12) {

		hours -= 12;

	}

	time = hours + ":" + minutes + "&nbsp;"+ pmam;

	return(month + "&nbsp;" + day + ",&nbsp;" + year + "&nbsp;" + time);

}

// Cycles through top stories in the sidebar

var ts = 0; // total stories count
var fsi = 0; // The first story to be displayed

function topStories(inst) {

	if (inst == "start") {
		fsi = 0; 
		arrowNext = $('arrow-next');
		arrowPrevious = $('arrow-previous');
		x = $('topStories').childNodes;
		storieslist = new Array();

		for (i=0; i < x.length; i++) {
			if (x[i].className == "story") { 
				storieslist[ts] = x[i].id;
				ts++;
			}
		}
	}

	if (storieslist.length > 2) {
		if (inst == "previous" && fsi != 0) { fsi--; }
		if (inst == "next" && (fsi < (storieslist.length - 2))) { fsi++; }
		lsi = fsi + 2; // Last comment index
		hiddenStories = storieslist.slice();
		hiddenStories.splice(fsi,2);

		for (b=0; b < hiddenStories.length; b++) {
			$(hiddenStories[b]).style.display="none";
		}

		if (fsi == 0) { arrowPrevious.src = "http://cache.dealbreaker.com/images/buttons/back.gif"; 
		arrowNext.src = "http://cache.dealbreaker.com/images/buttons/forward-on.gif"; }

		if (fsi > 0 && fsi < (storieslist.length - 2)) {
			arrowPrevious.src = "http://cache.dealbreaker.com/images/buttons/back-on.gif";
			arrowNext.src = "http://cache.dealbreaker.com/images/buttons/forward-on.gif"; 
		}
		if (fsi == (storieslist.length - 2)) { 
			arrowPrevious.src = "http://cache.dealbreaker.com/images/buttons/back-on.gif"; 
			arrowNext.src = "http://cache.dealbreaker.com/images/buttons/forward.gif"; 
		}
	} else {
		lsi = storieslist.length;
	}

	for (c=fsi; c < (lsi); c++) {
		$(storieslist[c]).style.display="block";
	}
	return false;
}

