Namespace("GF.map.Publish");

GF.map.Publish.init = function(siteUrl, mapLink) {
	GF.map.Publish.code = {};
	GF.map.Publish.code.bb = '[URL="' + siteUrl + mapLink + '"][IMG]' + siteUrl + mapLink + '/publish.gif?width={width}&height={height}[/IMG]\nMore details of this map at Gaiafix.com[/URL]';
	GF.map.Publish.code.html = '<a href="' + siteUrl + mapLink + '"><img width="{width}" height="{height}" src="' + siteUrl + mapLink + '/publish.gif?width={width}&height={height}">\n<br>More details of this map at Gaiafix.com</a>'
	GF.map.Publish.code.dhtml = '<iframe width="{width}" height="{height}" frameborder="0" scrolling="no" marginheight="0" src="' + siteUrl + mapLink + '/publish.html?width={width}&height={height}" marginwidth="0"></iframe><br/><a target="_new" href="' + siteUrl + mapLink + '">More details of this map at Gaiafix.com</a>';
	YAHOO.util.Event.onDOMReady(function () {
		GF.map.Publish.update();
	});
}

GF.map.Publish.updateSize = function(size, html) {
	if(size == "small") {
		return html.replace(/{width}/g, "295").replace(/{height}/g, "295");				
	}
	else if(size == "medium") {
		return html.replace(/{width}/g, "443").replace(/{height}/g, "443");				
	}
	else if(size == "large") {
		return html.replace(/{width}/g, "570").replace(/{height}/g, "570");				
	}
	else if(size == "tall") {
		return html.replace(/{width}/g, "295").replace(/{height}/g, "570");				
	}
	else if(size == "wide") {
		return html.replace(/{width}/g, "570").replace(/{height}/g, "295");				
	}
}

GF.map.Publish.update = function() {
	
	var code = document.getElementById("code");
	var preview = document.getElementById("preview");
	var select = document.getElementById("publish-options");
	var size = document.getElementById("publish-size");

	if(select.value == "bb") {
		code.value = GF.map.Publish.updateSize(size.value, GF.map.Publish.code.bb);
		preview.innerHTML = GF.map.Publish.updateSize(size.value, "<div style=\"width:{width}px; margin-left: auto; margin-right: auto;\">" + GF.map.Publish.code.html + "</div>");
	}
	else if(select.value == "html") {
		code.value = GF.map.Publish.updateSize(size.value, GF.map.Publish.code.html);
		preview.innerHTML = GF.map.Publish.updateSize(size.value, "<div style=\"width:{width}px; margin-left: auto; margin-right: auto;\">" + GF.map.Publish.code.html + "</div>");
	}
	else /* dhtml */ {
		code.value = GF.map.Publish.updateSize(size.value, GF.map.Publish.code.dhtml);
		preview.innerHTML = GF.map.Publish.updateSize(size.value, "<div style=\"width:{width}px; margin-left: auto; margin-right: auto;\">" + GF.map.Publish.code.dhtml + "</div>");
	}
}