$(document).ready(function(){
   
   height = 566; // 554
   
    $("#tk_footer").hide();
    
    $("#tk_footer").click(function(event){
	$("#map").slideUp(1000);

	   var png_pos = $("#terkep_png").position();
	   var swf_pos = $("#terkep_swf").position();
	   
	   var fav_list_link_cont = $("#fav_list_link_cont").position();
	   if ( fav_list_link_cont !== undefined ) $("#fav_list_link_cont").animate({top:fav_list_link_cont.top-height}, 1000);
	   var main_fav_select = $("#main_fav_select").position();
	   if ( main_fav_select !== undefined ) $("#main_fav_select").animate({top:main_fav_select.top-height}, 1000);
	   
	   var start_fav_select = $("#start_fav_select").position();
	   if ( start_fav_select !== undefined ) $("#start_fav_select").animate({top:start_fav_select.top-height}, 1000);
	   if ( png_pos !== undefined ) {
	    $("#terkep_png").animate({top:png_pos.top-height}, 1000);
	    $("#terkep_swf").animate({top:swf_pos.top-height}, 1000);
	   }
	   $("#tk_footer").hide();
    });
    
    $("#terkepes_cont").click(function(event){
	
	if ( $("#map").is(":hidden") ) {
	    
	    $("#map").slideDown(1000);
	    var png_pos = $("#terkep_png").position();
	    var swf_pos = $("#terkep_swf").position();
	    
	    $("#search_help_icon").hide();
	    
	    var start_fav_select = $("#start_fav_select").position();
	    if ( start_fav_select !== undefined ) $("#start_fav_select").animate({top:start_fav_select.top+height}, 1000);
	    	   var fav_list_link_cont = $("#fav_list_link_cont").position();
	   if ( fav_list_link_cont !== undefined ) $("#fav_list_link_cont").animate({top:fav_list_link_cont.top+height}, 1000);
	   var main_fav_select = $("#main_fav_select").position();
	   if ( main_fav_select !== undefined ) $("#main_fav_select").animate({top:main_fav_select.top+height}, 1000);
	    if ( png_pos !== undefined ) {
		$("#terkep_png").animate({top:png_pos.top+height}, 1000);
		$("#terkep_swf").animate({top:swf_pos.top+height}, 1000);
	    }
	    $("#tk_footer").show();
	    
	    bw = navigator.appVersion;
	    if ( bw.indexOf("MSIE 6.0;") != -1 ) {
		/*
		$("#tk_loading_cont").hide();
		$("#ie6_alert").show();
		*/
		setTimeout("showMapF()",2000);
	    } else {
		setTimeout("showMapF()",2000);
	    }
	    
	    // top.frames[0].load();
	    // $("#terkepes_loading_cont").fadeOut(1000);
	    
	    
	} else {
	    
	    $("#tk_footer").hide();
	    $("#terkepes_loading_cont").fadeIn(1000);
	    $("#map").slideUp(1000);
	    var png_pos = $("#terkep_png").position();
	    var swf_pos = $("#terkep_swf").position();
	    var start_fav_select = $("#start_fav_select").position();
	    if ( start_fav_select !== undefined ) $("#start_fav_select").animate({top:start_fav_select.top-height}, 1000);
	    	   var fav_list_link_cont = $("#fav_list_link_cont").position();
	   if ( fav_list_link_cont !== undefined ) $("#fav_list_link_cont").animate({top:fav_list_link_cont.top-height}, 1000);
	   var main_fav_select = $("#main_fav_select").position();
	   if ( main_fav_select !== undefined ) $("#main_fav_select").animate({top:main_fav_select.top-height}, 1000);
	    if ( png_pos !== undefined ) {
		$("#terkep_png").animate({top:png_pos.top-height}, 1000);
		$("#terkep_swf").animate({top:swf_pos.top-height}, 1000);
	    }
	    $("#search_help_icon").show(1000);
	}
	
    });
    
    $("#A_select").change(function() {
	coords = $(this).val();
	$("#B_select").val("0");
	$("#C_select").val("0");
	$("#TOBBI_select").val("0");
	show(coords,1);
    });
    
    $("#B_select").change(function() {
	coords = $(this).val();
	$("#A_select").val("0");
	$("#C_select").val("0");
	$("#TOBBI_select").val("0");
	show(coords,1);
    });
    
    $("#C_select").change(function() {
	coords = $(this).val();
	$("#A_select").val("0");
	$("#B_select").val("0");
	$("#TOBBI_select").val("0");
	show(coords,1);
    });
    
    $("#TOBBI_select").change(function() {
	coords = $(this).val();
	$("#A_select").val("0");
	$("#B_select").val("0");
	$("#C_select").val("0");
	show(coords,1);
    });
    
    $('#c_kiado_a').mouseup(function(){
	var checked = $(this).attr('checked') ? 0 : 1;
	$("#A_select").val("0");
	$("#B_select").val("0");
	$("#C_select").val("0");
	$("#TOBBI_select").val("0");
	if ( checked ) {
	    top.frames[0].show_icon_group('kiado_a_icon.png');
	} else {
	    top.frames[0].hide_icon_group('kiado_a_icon.png');
	}
    });
    
    $('#c_kiado_b').mouseup(function(){
	var checked = $(this).attr('checked') ? 0 : 1;
	$("#A_select").val("0");
	$("#B_select").val("0");
	$("#C_select").val("0");
	$("#TOBBI_select").val("0");
	if ( checked ) {
	    top.frames[0].show_icon_group('kiado_b_icon.png');
	} else {
	    top.frames[0].hide_icon_group('kiado_b_icon.png');
	}
    });
    
    $('#c_kiado_c').mouseup(function(){
	var checked = $(this).attr('checked') ? 0 : 1;
	$("#A_select").val("0");
	$("#B_select").val("0");
	$("#C_select").val("0");
	$("#TOBBI_select").val("0");
	if ( checked ) {
	    top.frames[0].show_icon_group('kiado_c_icon.png');
	} else {
	    top.frames[0].hide_icon_group('kiado_c_icon.png');
	}
    });
    
    $('#c_kiado_tobbi').mouseup(function(){
	var checked = $(this).attr('checked') ? 0 : 1;
	$("#A_select").val("0");
	$("#B_select").val("0");
	$("#C_select").val("0");
	$("#TOBBI_select").val("0");
	if ( checked ) {
	    top.frames[0].show_icon_group('videk_icon.png');
	} else {
	    top.frames[0].hide_icon_group('videk_icon.png');
	}
    });
    
    $("#keruletek_select").change(function() {
      kerulet = $("#keruletek_select").val();
      ber_min = $("#slider-range").slider("values", 0);
      ber_max = $("#slider-range").slider("values", 1);
      $.ajax({
         url: ssw+"lib/objects/Googlemap_filters.php?kerulet="+kerulet+"&ber_min="+ber_min+"&ber_max="+ber_max+"&",
         success: function(ids){
            top.frames[0].show_est_points(ids);
         }
      });
     
    });
    
   $(function() {
      
      $("#slider-range").slider({
         step:1,
         range: true,
         min: 0,
         max: 50,
         values: [8, 16],
         
         slide: function(event, ui) {
            
            $("#amount").html(ui.values[0]+' - '+ui.values[1]+'€');
            
         }
         
      });
      
      $('#slider-range').bind('slidestop', function(event, ui) {
         kerulet = $("#keruletek_select").val();
         ber_min = $("#slider-range").slider("values", 0);
         ber_max = $("#slider-range").slider("values", 1);
         $.ajax({
            url: ssw+"lib/objects/Googlemap_filters.php?kerulet="+kerulet+"&ber_min="+ber_min+"&ber_max="+ber_max+"&",
            success: function(ids){
               top.frames[0].show_est_points(ids);
            }
         });
      });
      
      $("#amount").html($("#slider-range").slider("values", 0)+' - '+$("#slider-range").slider("values", 1)+'€');
   });
    
});

function showMapF() {
    $("#tk_loading_cont").hide(1000);
    top.frames[0].load();
    $("#tk_footer").animate({top:-21}, 1);
    $("#right").show();
}
function show(coords,open) {
	gps = coords.split("|");
	top.frames[0].show_point(gps[0],gps[1],open);
}

function google_load() {
    $("#ie6_alert").hide();
    $("#tk_loading_cont").show();
    setTimeout("showMapF()",200);
}