// Flash Embed
var loading_map = true;



function initFlash() {

		var so = new SWFObject("/masala.swf", "masala_swf", "100%", "100%", "9", "#000000");
		so.useExpressInstall('expressinstall.swf');
		so.addParam("quality", "high");
		so.addParam("AllowScriptAccess", "always");
		so.addParam("wmode", "opaque");
		so.addParam("menu", "false");

		if (readCookie("northeast") == null || readCookie("northeast") == '' ||
		    readCookie("southwest") == null || readCookie("southwest") == '') {
		    reset_map_cookies();
		}

		// google_version.xml params for first load
		so.addVariable("roadVersion","w2.86");
		so.addVariable("hybridVersion","w2t.86");
		so.addVariable("aerialVersion","35");

		so.addVariable("northeast", readCookie("northeast"));
		so.addVariable("southwest", readCookie("southwest"));
		so.addVariable("provider", "Google Marble Hybrid");
		so.addVariable("throttleSpeedMS", "500");
		so.addVariable("requestsPerCycle", "10");
		so.addVariable("debug", "false");
		so.addVariable("serverpath", "");	// default is "" so it will be relative... detail links will be appended to this path
		so.addVariable("feedpath", "/mapservice/map_feed");		// default is "/main/map_feed"
		so.addVariable("refreshPanDelta", "75"); // distance pan must travel in pixels for a refresh of data
		// location of bluemarble tileset
		//so.addVariable("blueMarblePath", "http://s3.amazonaws.com/com.allvoices.bluemarble/");
		so.addVariable("blueMarblePath", "http://s3.amazonaws.com/com.modestmaps.bluemarble/");
		// Control the spread of markers per zoom level. The first number is the amount of pixels it will spread from the point at
		// the first zoom level. Next number is the spread for the second zoom level and so on.
		so.addVariable("markerSpread", "3,5,8,12,16,20,23,26,28,30,31,32,33,34,35,36,37,38,39,40");

		// thetime delay between each request when a user is double clicking the map
		so.addVariable("doubleClickThrottle","2500");

		// message controlled by cookie
		if(readCookie("returning") != "true"){
			//so.addVariable("message", "/firsttime");
			setCookie ("returning","true");
		} else {
			so.addVariable("message", "/welcome");
		}

		if(readCookie("low_bandwidth_version") != "yes"){
			so.write("map");
		}


}
//disabled carlos 27 June 2008. see fastInitFlashmap() in _flashmap.rhtml
//window.onload = initFlash;


// target flash movie
function getFlashMovie(movieName) {
	try
	{
  	 	 if (navigator.appName.indexOf("Microsoft") != -1)
		 {
             return window[movieName];
         } else
		 {
             return document[movieName];
         }
	}catch(ex)
    {
        log_exceptions(" Method:- getFlashMovie " + ex.message);
    }
	return null;
}


//////////////////////////////////////////////
// Filter Bar

function change_category(cat){

	change_category_selection(cat);
	/*only for precution as sometime user dont wait and click then there will be error alert*/
	try
	{
		switch(cat)
		{
			case -1:
				getFlashMovie("masala_swf").setCategory("all");
				break;
			case 1:
				getFlashMovie("masala_swf").setCategory("political");
				break;
			case 4:
				getFlashMovie("masala_swf").setCategory("business");
				break;
			case 6:
				getFlashMovie("masala_swf").setCategory("conflict_tragedy");
				break;
			case 5:
				getFlashMovie("masala_swf").setCategory("science");
				break;
			case 2:
				getFlashMovie("masala_swf").setCategory("sports");
				break;
			case 3:
				getFlashMovie("masala_swf").setCategory("entertainment");
				break;
		}
	}catch(ex)
    {
        log_exceptions(" Method:- change_category " + ex.message);
    }
	return true;
}



//////////////////////////////////////////////
// type selection

function change_type(type){


	/*only for precution as sometime user dont wait and click then there will be error alert*/
	try
	{
		switch(type)
		{
			case -1:
				getFlashMovie("masala_swf").setType("all");
				break;
			case 0:
				getFlashMovie("masala_swf").setType("events");
				break;
			case 1:
				getFlashMovie("masala_swf").setType("rumors");
				break;
			case 2:
				getFlashMovie("masala_swf").setType("people");
				break;
		}
		change_type_selection(type);
	}catch(ex)
    {
        log_exceptions(" Method:- change_type " + ex.message);
    }
	return true;
}



//////////////////////////////////////////////
// order selection

function change_order(order){

	//setCookie ('order', order);
	/*only for precution as sometime user dont wait and click then there will be error alert*/
	try
	{
		switch(order)
		{
			case 1:
				getFlashMovie("masala_swf").setSort("active");
				break;
			case 2:
				getFlashMovie("masala_swf").setSort("recent");
				break;
		}

		change_order_selection(order);
	}catch(ex)
    {
        log_exceptions(" Method:- change_order " + ex.message);
    }
	return true;
}

function reloadFlash(){
	//esort, rsort, psort, epage, rpage, ppage, masterpage
	// test functon ... send query string to append to xml url
	//(these vars don't mean anything to flash app so it will be easier to change query string if needed)
	/*only for precution as sometime user dont wait and click then there will be error alert*/
	try
	{
		getFlashMovie("masala_swf").reloadFlash("esort=1&rsort=2&psort=3&epage=4&rpage=5&ppage=6&masterpage=7");
		new Ajax.Request('/map/save_map_marker_click?map_action=reload', {method:'get'});
	}catch(ex)
    {
        log_exceptions(" Method:- reloadFlash " + ex.message);
    }
}

//////////////////////////
// set cookie

function onFlashMapMove(north,west,south,east){
	new Ajax.Request('/map/save_map_marker_click?map_action=moved', {method:'get'})

	setCookie ('northeast', north+','+east);
	setCookie ('southwest', south+','+west);

	var aCookie = readCookie("type_category_filter");
	if (aCookie != null) {
		an_arr = aCookie.split(',');
		oRequestHandlers[0].setParameters(1, an_arr[0], an_arr[1], an_arr[2]);
	}

	oRequestHandlers[0].clear_location =  true;
	oRequestHandlers[0].update("all");
	//reloadFlash();
}

// callback from the flash map when a marker is clicked
function mapMarkerClick(url){
	new Ajax.Request('/map/save_map_marker_click?map_action=marker_click&url=' + escape(url), {method:'get'});
}

function map_resize(size) {
    if(size == "expand") {
        new Effect.Scale('map', MAP_EXPANDED_HEIGHT, {scaleY: true, scaleX: false});
        setCookie( 'clickstream_external_url', 'bigger_map' );
        maintain_map_state('bigmap');
    } else {
        new Effect.Scale('map', MAP_DEFAULT_HEIGHT, {scaleY: true, scaleX: false});
        setCookie( 'clickstream_external_url', 'smaller_map' );
        maintain_map_state('smallmap');
    }
}

