var tag_array = new Array("tag_search", "tag_categories");
var flashProxy;
var cur_data_file;

$(document).ready(function() {
	//alert("ready");
	$("#fsc_map_radio0").attr("checked", "checked");
	cur_data_file = "http://www.globalforestrisk.org/router.php?service=map_cat_0";
	createDIY("http://www.globalforestrisk.org/router.php?service=map_cat_0&");
	//openCountryInfo("AF");
	$("#search_string").val("");
	$("#search_string").jSuggest({url: "http://www.globalforestrisk.org/router.php?service=search",type: "GET",data: "searchdata",autoChange: false});
	$("#search_string").attr("name", Math.random() + "__" + Math.random());
});




$(window).resize(function(){
	//resize();
});


function resize(){
	/*
	var winH = $(window).height();
	var q_h = winH - (190 + 100 + 4);
	$("#all_questions").height(q_h);
	*/
}

function createDIY(data_file){
	var uid = new Date().getTime();
	flashProxy = new FlashProxy(uid, 'js/JavaScriptFlashGateway.swf');
    var tag = new FlashTag('diy/world.swf?data_file=' + data_file, 500, 350);
    tag.setFlashvars('lcId='+uid);
	$("#mapdiv").html(tag.write());
}

function removeDIY() {
	swfobject.removeSWF("mapdiv");
}

function change_data_file(data_file){
	flashProxy.call('refreshData', data_file)
}


function zoomToCountry(country_fips){
	flashProxy.call('zoomTo',country_fips);
	openCountryInfo(country_fips);
}


function searchSelected(country_fips){
	zoomToCountry(country_fips);
}


function openCountryInfo(country_fips){
	$("#country_files").html("");
	$("#notice").html("");
	$.ajax({
		url: "http://www.globalforestrisk.org/router.php?service=country_info&country_fips=" + country_fips,
		cache: false,
			success: function(html){
				if($("#result").is(':hidden')){
					$("#result").html(html);
					$("#result").show("slow", function(){
						//goto report
						$('html,body').animate({scrollTop: 890}, 500);
						switch(country_fips){
							case "AS":
							case "CI":
								$("#notice").html("<u>1. Official approved by FSC, Mandatory for Chain of Custody  certified companies with Controlled Wood in scope.</u>");
								break;
							case "SZ":
								$("#notice").html("<u>Only Category 3 is officially approved by FSC, Mandatory for Chain of Custody certified companies with Controlled Wood in scope; other categories are draft prepared by NEPCon, for guidance only.</u>");
								break;
							default:
								$("#notice").html("3. Draft prepared by NEPCon, for guidance only");
								break;
						}
						getCountryFiles(country_fips);
					});
				} else {
					$("#result").hide("slow", function(){
						$("#result").html(html);
						$("#result").show("slow", function(){
							$('html,body').animate({scrollTop: 890}, 500);
							switch(country_fips){
								case "AS":
								case "CI":
									$("#notice").html("<u>1. Official approved by FSC, Mandatory for Chain of Custody  certified companies with Controlled Wood in scope.</u>");
									break;
								case "SZ":
									$("#notice").html("<u>Only Category 3 is officially approved by FSC, Mandatory for Chain of Custody certified companies with Controlled Wood in scope; other categories are draft prepared by NEPCon, for guidance only.</u>");
									break;
								default:
									$("#notice").html("3. Draft prepared by NEPCon, for guidance only");
									break;
							}
							getCountryFiles(country_fips);
						});
					});
				}
			}
	});
}

function getCountryFiles(country_fips){
	$.ajax({
		url: "?page=get_country_files&country_fips=" + country_fips,
		cache: false,
			success: function(html){
				$("#country_files").html(html);
			}
	});
}


function show_help(){
	if($("#help_div").is(':hidden')){
		$("#help_div").show("slow");
	} else {
		$("#help_div").hide("slow");
	}
}

function printWin(){
	window.print();
}