/**
 * @author larz
 */

///////////////////////////////////////////////
// easing
jQuery.extend( jQuery.easing,
{
	easeInOutCirc: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
		return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
	},
});

///////////////////////////////////////////////
// subnav animate  
$(document).ready(function() {	
      $('#subnav li a').hover(function() {
		$(this).animate({ marginTop: '30px' }, { duration: 200, easing: 'easeInOutCirc' });
      }, function() {  
		$(this).animate({ marginTop: '0px' }, { duration: 400, easing: 'easeInOutCirc' }); 
      });
	  // active
	  $('#subnav li a.active').hover(function() {
		$(this).animate({ marginTop: '30px' }, { duration: 100, easing: 'easeInOutCirc' });
      }, function() {  
		$(this).animate({ marginTop: '0px' }, { duration: 200, easing: 'easeInOutCirc' }); 
      });
});	  
	  
///////////////////////////////////////////////	  
// preloader	  
jQuery.fn.onImagesLoaded = function(_cb) { 
  return this.each(function() {
 
    var $imgs = (this.tagName.toLowerCase()==='img')?$(this):$('img',this),
        _cont = this,
            i = 0,
    _done=function() {
      if( typeof _cb === 'function' ) _cb(_cont);
    };
 
    if( $imgs.length ) {
      $imgs.each(function() {
        var _img = this,
        _checki=function(e) {
          if((_img.complete) || (_img.readyState=='complete'&&e.type=='readystatechange') )
          {
            if( ++i===$imgs.length ) _done();
          }
          else if( _img.readyState === undefined ) // dont for IE
          {
            $(_img).attr('src',$(_img).attr('src')); // re-fire load event
          }
        }; // _checki \\
 
        $(_img).bind('load readystatechange', function(e){_checki(e);});
        _checki({type:'readystatechange'}); // bind to 'load' event...
      });
    } else _done();
  });
};

///////////////////////////////////////////////
// image fadein
jQuery(function($){ 
	var totalNum = 3; 
	var rndNum = Math.floor(Math.random() * totalNum);
	 $("div.homepic").html('<img src="medien/home_pic' + rndNum + '.jpg" width="950" height="480" border="0" />');
  $('div.homepic img').onImagesLoaded(function(_img){
    $(_img).fadeIn(2000);
  });
 
}); // end on ready
