jQuery(function($){ 

   $('#container').fadeIn('slow', function() {
     $('#tabs').slideDown(800,function(){
       $('a',this).click(function(){ // set handlerz

         $('a.sel').removeClass('sel');
         $(this).addClass('sel');

         var _div = $('#'+this.id.split('_')[1]);
         var _id  = this.id.split('_')[1];

         $('.curDiv').slideIn(220, function(){
           _div.slideOut(200,400,function(){

             (_id=='show') ? (
               $('.galleria img:first').mouseover(),
               $('#heading').show(),
               $('#postcard').css('position','absolute').fadeOut(400),
               $('#floating_info').fadeOut(400)
             ) : (
               $('#postcard,#floating_info').fadeIn(),
               $('#heading').hide(),
               $('.galleria_wrapper').empty()
             );

           }).addClass('curDiv');
         }).removeClass('curDiv');

         return false;
       });
     });

     $('#show').slideOut(200,5000,function(){ 
       //$('#t_info').click(); 
     }).find('ul').galleria(g_opts, function(){
    // set-up img container........
       $(g_opts.insert).css({
         position:'relative',
         margin  :'20px',
         cursor  :'pointer',
         'float' :'left',
         width   : g_opts.gwidth,
         height  : g_opts.gheight
       });
     });
   });
});



jQuery.fn.slideIn = function(speed, callback) {
  return this.each(function(){
    $(this).animate({width:0,opacity:'hide'},speed,callback);
  });
};

jQuery.fn.slideOut = function(_width, speed, callback) {
  return this.each(function(){
    $(this).animate({width:_width,opacity:'show'},speed,callback);
  });
};


jQuery.fn.onImagesLoaded = function(_cb, dbg) { 
  return this.each(function() {
    dbg = dbg || 0;

    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,
           _prev = 0,
        _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'));
          }
        }; // _checki

        $(_img).bind('load readystatechange', function(e){_checki(e);});
        _checki({type:'readystatechange'});
      });
    } else _done();
  });
};
