/*--------------------TABS jQuery-------------------*/
$(function() {
   $('.accordion').accordion({autoHeight:false});
   $('.tableiste').tabs();
   $('.slider').slider();
	 
 });
    
/*--------------------Slide Panel-------------------*/
// f�r Abgeltungssteuer
$(document).ready(function(){

	setAutoComplete("searchField", "results_panel", "results", "/ajax/autocomplete.php?part=");

  $(".btn-slide").click(function(){
    $("#panel").slideToggle("fast");
    return false;
  });  
});

var $j = jQuery;
$j.fn.extend({
  toggleValue : function (defaultText) {
    return this.each(function() {
      $j(this).focus(function() {
        if ($j(this).val() == defaultText) {
          $j(this).val('');
        }
        $j(this).blur(function () {
          if ($j.trim($j(this).val()) == '') {
            $j(this).val(defaultText);
          }
        });
      });
    });
  }
  });
  

var add;
      add = function (object){
          var id = object.attr("id");
          var datastring='instID='+id+'&action=new';
          $.ajax({
           type: "POST",
           url: "/fonds/investmentfonds/fondsvergleich/ajax/helper.php",
           data: datastring,
           dataType:"json",
           beforeSend: function(){
           },
           success: function(data){
            $(".fondsvergleich_anzahl").empty().append(data.anzahl + '/' + data.gesamt).fadeOut(200).fadeIn(200).fadeOut(200).fadeIn(200);
             $("#fondsvergleich_results").empty();
             var html = '<table>';
             $.each(data.ids, function(i,item){
                var link = '<a href="'+ item.url_name +'" style="color:#000">'+item.name+'</a>';
              
                html =html +'<tr><td>' + link + '</td><td><a href="'+item.id+'" class="funds_delete"><img src="/images/fondsvergleich/trash.gif"/></a></td></tr>';
              });
              html = html +'</table>';
           $("#fondsvergleich_results").append(html);
            
            /*Lschen Event binden*/
            $("a.funds_delete").click(function(){
              anfrage($(this));
              return false;
            }); 
            
           },
           error: function(XMLHttpRequest, textStatus, errorThrown){
           alert(textStatus);
           }
          });
        }
 
 var anfrage = function(object){
      var id = object.attr("href").substring(object.attr("href").lastIndexOf("/")+1,object.attr("href").length);
          
      var datastring='instID='+id+'&action=delete';
          /*$("#fondsvergleich_view").slideToggle("slow");*/
          /*$('#fondsvergleich_panel').empty();
          $('#fondsvergleich_panel').append('Bitte warten!');*/
          $.ajax({
           type: "POST",
           url: "/fonds/investmentfonds/fondsvergleich/ajax/helper.php",
           data: datastring,
           dataType:"json",
           success: function(data){
           $(".fondsvergleich_anzahl").empty().append(data.anzahl + '/' + data.gesamt).fadeOut(200).fadeIn(200).fadeOut(200).fadeIn(200);
             $("#fondsvergleich_results").empty();
             var html = '<table>';
             
             $.each(data.ids, function(i,item){
                var link = '<a href="'+ item.url_name +'" style="color:#000">'+item.name+'</a>';
              
                html =html +'<tr><td>' + link + '</td><td><a href="'+item.id+'" class="funds_delete"><img src="/images/fondsvergleich/trash.gif"/></a></td></tr>';
              });
              html = html +'</table>';
           $("#fondsvergleich_results").append(html);
           /*$('#fondsvergleich_panel').empty();
           $('#fondsvergleich_panel').append(msg);*/
           /*$("#fondsvergleich_view").slideToggle("slow");*/   
           
           $("a.funds_delete").click(function(){
              anfrage($(this));
              return false;
            });       
           }
          }); 
      } 
  /* Fondsvergleich */
  

$(document).ready(function(){  

        $("#fondsvergleich_btn").toggle(function(){$('#fondsvergleich_btn').css("background","url(/images/fondsvergleich/up.gif) no-repeat right");},function(){$('#fondsvergleich_btn').css("background","url(/images/fondsvergleich/down.gif) no-repeat right");});
        $("#fondsvergleich_btn").click(function(){
            $("#fondsvergleich_panel").slideToggle("slow");
            $(this).toggleClass("active"); return false;
        });  
      
           
$("a.funds_delete").click(function(){
  anfrage($(this));
  return false;
});

$(".funds_id").click(function(){
  add($(this));
  fondsvergleich_alert('Der Fonds wurde hinzugef&uuml;gt!');
  return false;
});

var fondsvergleich_alert = function (msg) {
  $('#alert').jqmShow().find('div#ex3b table tr td h2').html(msg);
};

$('#alert').jqm({overlay: 50, modal: true, trigger: true});

$('#seite_weiterempfehlen').jqm({zIndex: 3000,ajax: '/ajax/seite-weiterempfehlen.php', trigger: 'span#seite_weiterempfehlen_click'});


$(function () {
  $('.bubbleInfo').each(function () {
    // options
    var distance = 10;
    var time = 250;
    var hideDelay = 500;

    var hideDelayTimer = null;

    // tracker
    var beingShown = false;
    var shown = false;
    
    var trigger = $('.trigger', this);
    var popup = $('.popup', this).css('opacity', 0);

    // set the mouseover and mouseout on both element
    $([trigger.get(0), popup.get(0)]).mouseover(function () {
      // stops the hide event if we move from the trigger to the popup element
      if (hideDelayTimer) clearTimeout(hideDelayTimer);

      // don't trigger the animation again if we're being shown, or already visible
      if (beingShown || shown) {
        return;
      } else {
        beingShown = true;

        // reset position of popup box
        popup.css({
          top: 0,
          left: 60,
          display: 'block' // brings the popup back in to view
        })

        // (we're using chaining on the popup) now animate it's opacity and position
        .animate({
          top: '-=' + distance + 'px',
          opacity: 1
        }, time, 'swing', function() {
          // once the animation is complete, set the tracker variables
          beingShown = false;
          shown = true;
        });
      }
    }).mouseout(function () {
      // reset the timer if we get fired again - avoids double animations
      if (hideDelayTimer) clearTimeout(hideDelayTimer);
      
      // store the timer so that it can be cleared in the mouseover if required
      hideDelayTimer = setTimeout(function () {
        hideDelayTimer = null;
        popup.animate({
          top: '-=' + distance + 'px',
          opacity: 0
        }, time, 'swing', function () {
          // once the animate is complete, set the tracker variables
          shown = false;
          // hide the popup entirely after the effect (opacity alone doesn't do the job)
          popup.css('display', 'none');
        });
      }, hideDelay);
    });
  });
});

});