/*!
 * jQuery.dkoester - Plugin for www.dirkoester.de
 * Copyright 2011, Dirk Koester 
 * Version 0.7
 * http://www.dirkoester.de
 */
(function( $ )
{
  //Hintergrundbild austausachen
  $.fn.loadBGImage = function(url)
  {
    var t = this;
    $('<img />').attr('src', url).load(function()
    { 
      t.each(function()
      { 
        $(this).css('backgroundImage', 'url(' + url + ')');
        $(this).hide().fadeIn('slow');
      });
    });
    return this;
  }

  //Pixel-Effekt bei Hover
  $.fn.pixelHover = function()
  {
    return this.each(function()
    { 
      $(this).hover(function () 
      {
        if($(this).data('lock') != 'true')
        {
          var host = $(this).find('.hovern');
          $(this).data('lock', 'true');
          var a = new Image();
          var filename = host.data('jpg');
          var b = "img/" + filename + ".jpg";
          //var host = $(this);
          $(a).load(function () 
          {
            $(this).hide();
            $(host).append(this);
            $(this).fadeIn("normal", function () {})
          }).attr('src', b)
        }
      }, function () 
      {
        var host = $(this);
        $(this).find('img').fadeOut(function(){ $(host).data('lock', 'false'); $(this).remove();});
      });
    });
  }
  
  //Hover für nav-Elemente
  $.fn.navHover = function()
  {
    return this.each(function()
    { 
      if($(this).attr('class') == 'nav active') { return;};
      $(this).hover(function () 
      {
        if($(this).data('lock') != 'true')
        {
          $(this).data('lock', 'true');
          var host = $(this);
          $(this).animate(
          {color: 'rgb(240,157,25)', backgroundColor: 'rgba(255, 255, 255, 1.0)', height: '111px'}, 200, function()
            {
            }
          ); 
        }
      }, function () 
      {
        var host = $(this);
        $(this).animate(
          {color: 'rgb(5,34,52)', backgroundColor: 'rgba(255, 255, 255, 0.5)', height: '91px'}, 200, function()
          {
            $(this).data('lock', 'false');
          }
        );        
      });
    });
  }
 
  //Zeigt Spinner
  $.spinOn = function ()
  {

  }
  
  //Versteckt Spinner
  $.spinOff = function()
  {

  }
    
  //Scrollt zum Seitenende
  $.toBottom = function ()
  {
    var y = $('html').height();
    $('html, body').animate({scrollTop: y}, 400);
  }
 
  //Vorladen von Bildern
  $.preload = function() 
  { 
    var args_len = arguments.length;
    for (var i = args_len; i--;) 
    {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
  
  //Kommentare laden
  $.showComment = function (b)
  {
      var c = "#ENTRY_" + b;
      var d = "#ENTRY_" + b + "_COMMENTS";
      //$(c).find(".blogSpin").show();
      $.get("../src/getComments.php", {
          eId: b
      }, function (a) 
      {
        $(d).slideDown("fast", function () 
        {
            $(d).html(a).hide().fadeIn();
            //$(c).find(".blogSpin").hide();
            //$(c).find(".iconComments").html("<a href='javascript:hideComment(" + b + ");'>Kommentare ausblenden</a>")
        });
      });
  }
  
  //Kommentar machen
  $.doComment = function (c)
  {
    Shadowbox.open(
    {
        width: "460px",
        height: "469px",
        content: "../src/dc.php?id=" + c,
        player: "iframe"
    });
  }
  
})( jQuery );

