function show_search_popup(obj)
{
	
	if(obj.id == "search_span")
	{
		hide_search_popup();
	}
	else
	{
		if($(obj).attr("class") == "city_span" ){
				var txt = $(obj).text();
			$("#search_span").text(txt)
			$("#popup_search").css("left", $(obj).parent().get(0).offsetLeft); 
			$("#popup_search").css("top", $(obj).parent().get(0).offsetTop);
			$("#popup_search").css("margin-top", $(obj).parent().css('margin-top').substr(1)); 
			$("#popup_search").css("margin-left", $(obj).parent().css('margin-left').substr(1));
			$("#search_in_city").attr("value", txt);
			$("#popup_search").show();
			$("#office_href").attr("href", $("#" + $(obj).attr("id") + "_href").text());
		}
		else
		{
			if($(obj).attr("id") != 'keywords'){
				hide_search_popup();
			}
		}
	}
}

var curr_obj;
function moveCountry(obj)
{
	var j = 0;

	coord_array = coord[$(obj).attr("id").substr(12)]
	for(var i = 1; i <= coord.length; i++){
		$("#container_c_" + i).animate({top: coord_array[j], left: coord_array[j+1]}, 600);
		j=j+2;
	} 
	$(".cont").each(function(){
		if($(this).attr("id") == $(curr_obj).attr("id")){
			$(".selcted_country .city_div").each(function(){$(this).animate({opacity: "hide"}, 300);});
		}
	});
	curr_obj = obj;
return coord_array; 
	
}


function switch_country(obj)
{
	
	hide_search_popup();
	
	var coord_array = moveCountry($(obj).parent(".cont"));

$(".selcted_country").removeClass("selcted_country");
$(obj).parent(".cont").addClass("selcted_country");
		setTimeout(function(){$("div.selcted_country div.city_div").each(function(){
			$(this).animate({opacity: "show"}, 300);

				var top_num = 0;
				var left_num = 0;

				var j = 0;
				for(var i = 1; i <= coord.length; i++){
					if($(this).parent().attr("id").substr(12) == i){ 
						top_num = coord_array[j];
						left_num = coord_array[j+1];
					}
					j=j+2;
				} 


		
					

					$(this).css("margin-top", (top_num * (-1) + 'px'));
					$(this).css("margin-left", (left_num * (-1) + 'px'));


	})}, 300);
	
	
	$('#middle2 .disabled').removeClass("disabled");
	$(obj).addClass("disabled");	
}



function hide_search_popup()
{
	$("#popup_search").hide();
}

$(document).ready(function(){

	$("#c_1").addClass("disabled");
	$("#container_c_1").addClass("selcted_country");
	switch_country($("#c_1"));
	$(".country").animate({opacity:"show"}, 600);	
	$(document).click(function(e){
		if( $(e.target).is('span.city_span') ||  $(e.target).is('span.search_span') || $(e.target).is('#keywords') ){
       			show_search_popup($(e.target))}
		else{ 
			if( $(e.target).is('div.country'))
			{
				if($(e.target).attr("class") != "country disabled"){
					switch_country($(e.target))
				}
			}
			else
			{
				hide_search_popup()
			}
		}

			}
		);
	
	
	
	}

);


	
			

