$(document).ready(function() {

  /* Google Maps stuff */  
  if (GBrowserIsCompatible()) 
  {
    map = new GMap2($("#map_box_content")[0]);
    
    var lng = $("#geo span.lng").text();
    var lat = $("#geo span.lat").text();
    
    map.setCenter(new GLatLng(lat, lng), 16);
    var marker = new GMarker(new GLatLng(lat, lng));
    
    current = marker;
    map.addOverlay(marker);  
    map.addControl(new GLargeMapControl());  
    map.addControl(new GMapTypeControl());
  }
  
  // This is the jQuery equivalent of <body onunload="GUnload();">
  $(window).unload(function() { 
      GUnload();
  });

  new DialogBox2({
    link_id: "link_ad_comment",
    handle_id: "link_ad_comment_handle",
    text: "<p>Du musst angemeldet sein, um zu kommentieren</p><p>&nbsp;</p>",
    action_link_name: "LOG IN",
    cancel_link_name: "ÄNDERN",
    x: 430,
    y: 25
  }).show();
  new DialogBox2({
    link_id: "ad_delete",
    text: "<p>Willst Du die Anzeige wirklich beenden?</p><p>&nbsp;</p>",
    action_link_name: "Löschen",
    cancel_link_name: "ÄNDERN",
    y: -30,
    x: 10
  }).show();
  /*
  $("a.submit").click(function(e){
    alert("adsfasfsdf");
    e.preventDefault();
  });
  */
  
  new DialogBox2({
    link_id: "ad_report",
    text: "<p>Hallo,</p> <p>möchtest Du uns diese Anzeige melden?</p>",
    action_link_name: "JA",
    cancel_link_name: "ÄNDERN"
  }).show();
  $('.subscribe-notice').delay(3000, function() {
    $(this).remove();
  });
  /*
  $("a.report").bind("click", function(e){
    link = $(this);
    $.prompt(link.attr("name"),
      { buttons: { JA: true, Ändern: false }, opacity: 0, 
        top: link.offset().top, 
        left: link.offset().left,
        callback: function(v,m) {
          if(v){
           $.post(link.attr("href"), {  ad_id: $("a.report").attr("href").match(/\d/g)[0] }, null, 'script'); 
          }
      }
    });
    e.preventDefault();
  });
  */
  
  jQuery.each($('.ad_image_link'), function() {
  
    jQuery(this).bind("click", function() {
      $('.actual_image img').attr("src", this.href);
      return false;
    });
  
  });
  
  $('.email_link a').bind("click", function() {
    $("#password_reminder_red").attr("value", "replay_ad");
    $('.description').hide();
    $('.notice_area').hide();
    $('.email_form').show();
    return false;
  });
  
  $('a.comment_reply_link').each(function(i) {
      wrapped = jQuery(this);
      wrapped.attr("href","#");
      wrapped.bind("click", function() {
        jQuery(this).siblings("form").show();
        return false;
    });
  });
  
  new DialogBox2({
    link_id: "bookmark_ad_link",
    text: "<p>Hallo " + CurrentUser.first_name + "</p><p>Willst Du Dir diese Kleinanzeige wirklich auf Deine Merkliste setzen?</p>",
    action_link_name: "Merkliste"
  }).show();
  new DialogBox2({
    link_id: "guest_bookmark_ad_link",
    text: "<p>Du musst eingeloggt sein, um… zu tun</p><p>&nbsp;</p>",
    action_link_name: "LOG IN",
    cancel_link_name: "ZURÜCK"
  }).show();
  $('a.destroy_link').each(function(){
    new DialogBox2({
      link_id: this.id,
      handle_id: this.id + "_handle",
      text: "<p>Hi " + CurrentUser.first_name + "</p><p>are you sure you want to delete this comment?</p>",
      action_link_name: "Delete",
      y: 30
    }).show();
  });

});
