var rand 		= Math.floor(Math.random()*600000);
var greendimes 	= Sundance.getUrlParam('greendimes');

function checkDeeplink(){
	var deeplink 	= Sundance.getUrlParam('deeplink');
	
	if (deeplink) {
		var url	= window.location.href.split("?");
		window.location = url[0]+'#/'+deeplink;
	}

}
checkDeeplink();

function writeContent(){

	setTimeout( function() { // setTimeout because of Safari
	
		$('ecommunity_flashContent').update('');
	
		var so_map_content = new SWFObject("/minisites/ecommunity/swf/content.swf", "eco_content", "700", "595", "8", "#EBE5CC");
		if (greendimes && greendimes == "1") {	
			so_map_content.addVariable("conf_uri", "/minisites/ecommunity/xml/config-greendimes.xml");
		} else {
			so_map_content.addVariable("conf_uri", "/minisites/ecommunity/xml/config.xml");
		}
		so_map_content.addVariable("conn", rand);
		so_map_content.addParam("allowScriptAccess", "always");
		so_map_content.addParam("swLiveConnect", "true");
		so_map_content.addParam("wmode", "transparent");
		so_map_content.write("ecommunity_flashContent");

	}, 50 );

}

function writeMap(params){	

	//alert('writeMap: params: \n'+Object.toJSON(params));

	var	iframe_url = '/maps/ecommunity/map.php?conn='+rand;

	if (greendimes && greendimes == '1') 					iframe_url += '&greendimes=1';
	if (params  && (params['ixPlacemark'] != undefined)) 	iframe_url += '&ixPlacemark='+params['ixPlacemark'];
	if (params && (params['topics'] != undefined))			iframe_url += '&topics='+params['topics'];

//	alert('writeMap: iframe_url: '+iframe_url);

	source = '<div style="padding: 14px 0 10px 10px;">'
			+'<iframe src="'+iframe_url+'" width="676" height="384" scrolling="no" frameborder="0" id="mapframe" name="mapframe"></iframe>'
			+'</div>'
			+'<div id="eco_map_tabs" style="width:700px; height:212px;"></div>';
			
	setTimeout( function() { // setTimeout because of Safari

		$('ecommunity_flashContent').update(source);

		var so_map_tabs = new SWFObject("/minisites/ecommunity/swf/map_content.swf", "eco_content", "700", "173", "8", "#EBE5CC");
		if (greendimes && greendimes == "1") {	
			so_map_tabs.addVariable("conf_uri", "/minisites/ecommunity/xml/config-greendimes.xml");
		} else {
			so_map_tabs.addVariable("conf_uri", "/minisites/ecommunity/xml/config.xml");
		}
		so_map_tabs.addVariable("conn", rand);
		so_map_tabs.addParam("allowScriptAccess", "always");
		so_map_tabs.addParam("swLiveConnect", "true");
		so_map_tabs.addParam("wmode", "transparent");
		so_map_tabs.write("eco_map_tabs");

	}, 50 );

}

function openBubbleById(id){
	//wrapper for opening bubble in googlemap
//	alert('openBubbleById: id: '+id);
	document.getElementById("mapframe").contentWindow.SunBubble.prototype.openById(id);		
}
function searchFromFlash(params){
	document.getElementById("mapframe").contentWindow.SunMap.searchFromFlash(params);
}
function sendMessageToNav(func,arg){
//	alert("sending message to nav");
	asCall('sc_ecommunity','messageHandler',[func,arg]);
}
function sendMessageToContent(func,arg){
//	alert("sending message to content" + func + "|" + arg + "|");
	asCall('eco_content','messageHandler',[func,arg]);		
}