jQuery(document).ready(function() {

  jQuery("#layer #arrow").toggle(function(){
      jQuery("#layer").animate( { left:"-=269px"}, { duration: "medium" });
      jQuery("#arrow").css({backgroundImage: "url(/images/bg/arrow_right.gif)"});
    },
    function () {
      jQuery("#layer").animate( { left:"+=269px"}, { duration: "medium" });
      jQuery("#arrow").css({backgroundImage: "url(/images/bg/arrow_left.gif)"});
    }
  );
  
  // Zählpixel für Download Tracks
  // Direkte Verlinkung entfernen. Ansonsten Problem mit 
  // Ajax-Request wegen Header des Download-Request
  // Zuvor href in Variable speichern 
  strDownloadUrl = ""; 
  strDownloadUrlGPX = jQuery("a.cntdownload.gpx").attr("href");
  strDownloadUrlKML = jQuery("a.cntdownload.kml").attr("href");
  
  jQuery("a.cntdownload.gpx").removeAttr("href");
  jQuery("a.cntdownload.gpx").attr('href', '#');

  jQuery("a.cntdownload.kml").removeAttr("href");
  jQuery("a.cntdownload.kml").attr('href', '#');


  // Click Event definieren
  jQuery(".cntdownload").click(function () {
  
    var str = jQuery(this).attr('class');
    
    var regEx = /gpx/;
    var result = regEx.exec(str);
    if (result !== null) {
        strDownloadUrl = strDownloadUrlGPX;
    }
    
    regEx = /kml/;
    result = regEx.exec(str);

    if (result !== null) {
        strDownloadUrl = strDownloadUrlKML; 
    }   
 
    var cntid = jQuery("#cntdownload").attr("cntid");
    var mytemp = "/trackdowncnt/" + cntid;    

        
    // Load mit Callback aufrufen
    jQuery("#pixel").load(mytemp, function(response, status, xhr) {
        
        if(status === 'success') {
              // Den Download ausliefern   	          
              document.location.href=strDownloadUrl;
        } else {
            var strMsg='<span style="color: #DC150F">Die Datei kann zur Zeit leider nicht heruntergeladen werden.</span>';
            jQuery("div.box").html(strMsg);
        }	
    });
  });
  


  //jQuery(".cntdownload").click(function () { 
  // var cntid = jQuery("#cntdownload").attr("cntid");
  //  jQuery("#pixel").load("http://www.tourwerk.com/trackdowncnt/" + cntid);
  //});

});

function init()	{
/*
    var gesBreite = jQuery("body");
    neueBreite = gesBreite.width();
    if (neueBreite < 1000) neueBreite = 1000;
    jQuery("#map").width(neueBreite-168);
    var gesHoehe = jQuery("body");
    neueHoehe = gesHoehe.height() - 309;//200
    if (neueHoehe < 309) neueHoehe = 309;
    jQuery("#map").height(neueHoehe); 
    jQuery("#layer").height(neueHoehe);  
    jQuery("#layertext").height(neueHoehe-50); 

    
 var gesHoehe = jQuery("body");
//alert(gesHoehe.height());
       neueHoehe = gesHoehe.height() - 309;
       if (neueHoehe < 309){
	 neueHoehe = 500;
	}
	else {
	neueHoehe = 700;

	}
       jQuery("#layer").height(neueHoehe);  
       jQuery("#layertext").height(neueHoehe-50); 
*/	
}

function msgBox(url, text) 
{ 
	var box=window.confirm(text);
	if(box==true){ 
		window.location.href = url; // wenn OK gedrueckt wird. 
	} 
	else if(box==false){ 
		return false;
	} 
} 


function route_uebernehmen($maproute){
	//alert($maproute);
	var data_json = document.getElementById("tourwerk_track_data_json");
	data_json.value = $maproute;
}

	
window.onresize = init;
window.onload = init;
