$().ready(function(){
	var change_destination = function(){
		window.location = baseURL;
	}
	var change_level = function(e){
		var option_id = $(this).attr("id").replace("option_","");
		$(this).parent().parent().find("li").removeClass("activ");
		$(this).parent().addClass("activ");
		var a_el = this;
		$.ajax({
			url : baseURL+"home/ajax_related_options",
			type: "POST",
			data: {"option_id":option_id,"compare":1},
			success: function(data){
				try{
					var result = eval("("+data+")");
					var ul = $(a_el).parent().parent().next("ul");
					ul.find("li").remove();
					$.each(result.data,function(k,v){
						if(k > 4 && result.type == "Country"){
							return false;
						}
						var el_class = "";
						if(k == 0){
							el_class = ' class="activ"';
						}
						ul.append("<li"+el_class+"><a href=\""+v.url+"\" id=\"option_"+v.id+"\" title=\""+v.name+"\">"+v.name+" ("+v.count+" oferte)</a></li>");
					})
					if(result.type == "Country"){
						ul.find("li a").click(change_level);
						ul.find("li a:first").click();
						$("#country_link").attr("href",result.data[0].url);
						$("#country_link").text("Toate destinatiile din "+result.data[0].name);
					} else {
						$("#country_link").attr("href",$(a_el).attr("href"));
						$("#country_link").text("Toate destinatiile din "+$(a_el).attr("title"));
					}
				} catch(e){
					alert(e);
				}
			}
		});
		e.preventDefault();
		return false;
	}
	$(".colCont li a, .colCountry li a").click(change_level);
	$("ul.menu li.first").addClass("firstOv").unbind("mouseout");

	var holder_flash_height = (Number)($('#holderFlashMap').height());
	var holder_flash_real_height = (Number)($('#holderFlashMap').innerHeight());
	if(holder_flash_height < holder_flash_real_height){
		$('#holderFlashMap').css("height", holder_flash_real_height);
		holder_flash_height = holder_flash_real_height;
	}
	var computed_height = (Number)($('.boxSearch').height())+(Number)($('.boxRecomandations').height());
	if(holder_flash_height < computed_height){
		$('#holderFlashMap').css("height", computed_height+7);
	}else{
		$('.boxRecomandations .boxContent').css("height", holder_flash_height - (Number)($('.boxSearch').height()) - 17);
	}
});

