function onDomLoad() {
	var startButton = document.getElementById('url_start_button');
	startButton.onmouseover = startButtonMouseOver;
	startButton.onmouseout = startButtonMouseOut;
	startButton.onmousedown = startButtonMouseDown;
	startButton.onmouseup = startButtonMouseUp;
	new Image().src="/editor/img/button_hover1.jpeg"; //preload image
}

function selectUrlBox() {
	var urlBox = document.getElementById("url_text_box");
	if ( urlBox.value.match(/\(ex:.*/i) ) {
		urlBox.value = "";
		urlBox.style.color = 'black';
		urlBox.style.fontStyle = 'normal';
		urlBox.style.paddingTop = '7px';
		urlBox.style.paddingBottom = '7px';
		urlBox.style.fontSize = '13pt';
		//url text box name set here
		//otherwise if user clicks start with only default text in url box, app will try to process default text as url
		urlBox.name = "url";
	}
}

/* Start Button */
function startButtonMouseOver() {
	YAHOO.util.Dom.addClass(this, 'start_button_onhover');
}
function startButtonMouseOut() {
	YAHOO.util.Dom.removeClass(this, 'start_button_onhover');
	YAHOO.util.Dom.removeClass(this, 'start_button_onclick')
}
function startButtonMouseDown() {
	YAHOO.util.Dom.addClass(this, 'start_button_onclick');
}
function startButtonMouseUp() {
	YAHOO.util.Dom.removeClass(this, 'start_button_onclick')
}

/* Bookmarklet info */
function showBookmarkletInfo() {
	displayForBrowser('bookmarklet_more_info_install_ie', 'bookmarklet_more_info_install_ie8', 'bookmarklet_more_info_install_ff', 'bookmarklet_more_info_install_safari');
}

/* Utilities */
function displayForBrowser(ie, ie8, ff, safari) {
	document.getElementById(ie).style.display = 'none';
	document.getElementById(ie8).style.display = 'none';
	document.getElementById(ff).style.display = 'none';
	document.getElementById(safari).style.display = 'none';
	if (YAHOO.env.ua.ie >= 8) {
		document.getElementById(ie8).style.display = 'inline';
	}
	else if (YAHOO.env.ua.ie > 0) {
		document.getElementById(ie).style.display = 'inline';
	} else if (YAHOO.env.ua.webkit > 0) {
		document.getElementById(safari).style.display = 'inline';
	} else {
		document.getElementById(ff).style.display = 'inline';
	}
}

function trimUrl(idOfUrl) {
	var elem = document.getElementById(idOfUrl);

	//trim the url
	elem.value = elem.value.replace(/^\s+/, '').replace(/\s+$/, '');

	//make sure a url has been entered
	if (elem.value.search(/^\(ex\:/) >= 0 || elem.value.length == 0) {
		alert("Please enter a url (ex. http://www.google.com)");
		return false;
	}

	return true;
}

/* Frames Page */
function initiateReloadImagesOnFramesPage(){
	pid = setInterval('reloadImagesOnFramesPage()', 2000);
	setTimeout("clearInterval(" + pid + ")", 20000); //stop checking after 20 sec
}

function reloadImagesOnFramesPage() {
	var imgs = document.getElementsByTagName("img");
	for (var i = 0; i < imgs.length; i++) {
		if (imgs[i].className == "preview")	{
			imgs[i].src = imgs[i].src + 1; //add 1 to prevent caching
		}
	}
}

/*-------- Bookmarklet Loader ------------*/
function generateBookmarkletLink(loaderFunctionId, linkId) {
	var loader = document.getElementById(loaderFunctionId).innerHTML;
	loader = loader.replace(/function.*\(\)/, "function()");
	loader = loader.replace(/\s/g, "");
	loader = loader.replace(/\"/g, "\\\"");
	loader = "javascript:(" + loader + ")();";
	document.getElementById(linkId).href = loader;
}

/* Delete Clips Page */
function showDeleteClipsPanel() {
	var url = "/clips/delete";
	window.deleteClipsPanel = new IFramePanel(url, "ppw_delete_clips_bd", "ppw_delete_clips");
	window.scroll(0,0); //if user is scrolled down, window will appear scrolled off the top
	window.deleteClipsPanel.show();
}

function updateClipsAfterDelete(response) {
	// Update clips on dashboard page
	var clips = parent.document.getElementById("clips");
	clips.innerHTML = response;
	var clipsList = parent.document.getElementById("clips_list");
	setClipListWidth(clipsList);
	// Close delete clips panel
	parent.deleteClipsPanel.hide();
}

function setClipListWidth(clipsList) {
	var clips = clipsList.getElementsByTagName("li");
	if (clips.length > 0) {
		var w = clips.length * 165;
		clipsList.style.width = w + 'px';
	}
}