/* Letzte Publizierung: Mittwoch, 22. Februar 2012 23:03 | Seiten-ID: 1146 */
$(document).ready(function() {

  var COOKIE_NAME = 'swbbildungsinitiative_fs_cookie';
  var options = { path: '/', expires: 10 };
  var baseFontSize = 30; 

  setFontSize($.cookie(COOKIE_NAME), false);

  $('#lst-font-nav li a').click(function() {
      setFontSize(this, true);    
      $.cookie(COOKIE_NAME, fntSize, options);
      return false;
  });


  checkSubNaviActiveState();
  
  //Slideshow auf Startseite
  $('#keyvisual').cycle({
    fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
    speed: 1000
  });

  // Druck
  $("a#lnk-popup-print").click(function(e) {
    window.print();
    e.preventDefault();
  });
  
  // Popup schließen
  $("a#lnk-popup-close").click(function(e) {
    window.close();
    e.preventDefault();
  });

});

function setFontSize(lnk, animate)
{  
    lnk = lnk == undefined ? 30 : lnk;    
    var urlParts = lnk.href != undefined ? lnk.href.split('fs=') : Array(0, lnk);
    fntSize = urlParts[1];
    switch (animate) {
      case true:
          $("body").animate({
              fontSize: fntSize+"px"
          }, 400
          );
          
      break;     
      case false:
          $("body").css("font-size", lnk+"px");
          lnk = $("a[href=?fs="+lnk+"]");
          
      break;
    }
    
   $('#lst-font-nav li a').removeClass("active");
   $(lnk).addClass("active");
} 


function checkSubNaviActiveState() {
    var lastActive = null;
    
    $("div#content-navigation").find(".active").each(function(index){
      lastActive = $(this);
      $(this).removeClass("active");      
    });
    $(lastActive).addClass("active");
}


/* sf_forms */

function addCostsPosition(rem_label)
{
    var idName = jQuery("#costsposition").children().last().attr("id");
    
    if(idName != null)
    {
        var mySplitResult = idName.split("_");
        var indexId = parseInt(mySplitResult[2]) + 1;
    }
    jQuery.ajax({
           type: "POST",
           url: "http://www.swb-bildungsinitiative.de/_workflows/sf_forms/web/index.php/verwendungszweck/create",
           data: "index=" + indexId,  
           success: function(data){
                var html_code = '<div style="display:none;" class="added_note_wrap" id="added_note_'+indexId+'"><div class="added_note"></div>'+data+'<div class="remove_costs_position"><a title="Kosten-Position entfernen" href="#" onclick="removeCostPosition('+indexId+'); return false"><img src="/_img/button_loeschen.gif" alt="" /></a></div></div>';
                jQuery("#costsposition").append(html_code);//.slideDown('slow');
                  jQuery("#added_note_"+indexId).show("normal",function() {
          });
                
                var delivery_note = 1;
                jQuery('#costsposition .count_cost_position').each(function(idx, item) 
                {
                    jQuery(item).text(delivery_note);
                    delivery_note++;
                });
           }
       
    });
}

function removeCostPosition(new_index)
{
    jQuery("#costsposition #added_note_"+new_index).remove();   
    
    var delivery_note = 1;
    jQuery('#costsposition .count_cost_position').each(function(idx, item) 
    {
        jQuery(item).text(delivery_note);
        delivery_note++;
    });
}
