//REQUIRES jQuery for jQuery.cookie
//BUGBUG: reading cookies set by the popup won't work once we attempt to widgetize
//this for 3rd party sites
//BUGBUG: popup URL will have to be absolute for full domain for widgetization

function parseCookieAsInt(cookieName, defaultValue)
{
	var cookieStringValue = $.cookie(cookieName);
	
	if(cookieStringValue == null)
		return defaultValue;
	
	var cookieIntValue = parseInt(cookieStringValue);
	
	if(isNaN(cookieIntValue))
		return defaultValue;
	
	return cookieIntValue;
}

function launchEditor()
{			
	var preferredWidth = parseCookieAsInt("editor_preferred_width", 0);
	var preferredHeight = parseCookieAsInt("editor_preferred_height", 0);
							
	var params = {
		width : Math.max(preferredWidth, 1000), //minimum supported
		height : Math.max(preferredHeight, 650), //minimum supported
		resizable : 1 //to indicate no scrollbars, and minimal chrome						
	};	

	params.left = (screen.width - params.width) / 2;
	params.top = (screen.height - params.height) / 2;		

	var paramString = "";
	var first = true;
	for ( param in params ) 
	{
		if(first == true) {
			first = false;
		} else {
			paramString += ",";
		}
		
		paramString += param + "=" + params[param];
	}
	
	var windowName = "create" + (new Date().getTime()); //generate a unique name so multiple create opens don't hit the same target
	popup = window.open("/create", windowName, paramString);
	setTimeout('popup.focus();', 250);
	return false;
}
