(function($) {

    $('div.tabbox').tabSwitcher();
    
    
    $('div.dropdown h3')
        .wrapInner('<a href="#"></a>')
        .bind('click', function(e) {
            $(this).parent().find('ul').slideToggle(300);
            return false;
          })
        .parent()
        .bind('mouseleave', function(e){
            $(this).find('ul').slideUp(300);
          });
    
    $('div.productitem span.tilbod')
        .wrapInner('<li class="discount"></li>')
        .find('li')
        .prependTo('div.price ul.attr');
    
    
    $('body.twocol').find('div.pageextra1 div.wrapper, div.pagebody div.wrapper > div.box > div').equalizeHeights();
    $('body.threecol').find('div.pageextra1 div.wrapper, div.pageextra2 div.wrapper, div.pagebody div.wrapper > div.box > div').equalizeHeights();
        
        
    //zebra
    $('div.people table tr:odd, table.zebra tr:odd').addClass('alt');
    
    
    $(document).ready(function() {
        
        $('#noContentFlashHack').remove();
        
        //center images in product lists
        $('body.threecol div.products div.item img')
            .each(function(){
            
                $(this).bind('load readystatechange', function() {

                    $(this).css({ 'margin-top' : 53 - ( $(this).height() / 2 )  })

                });

              this.src += ''; // IE force readystate hack
            
            });
            
        
        //init image popup
        var imgboxes = $('div.productitem div.imgbox');
        if(imgboxes.length) {
          if(!imgboxes.find('a').length) {
            var ahref = imgboxes.find('img').attr('src').replace(/medium/,'large');
            imgboxes.find('img').wrap('<a href="' + ahref + '"></a>')
          }
          imgboxes.find('a:has(img)').fancybox({
            'fancyLoading' : true,
            'overlayShow' : false,
            'zoomSpeedIn' : 300,
            'zoomSpeedOut' : 200,
            'hideOnContentClick' : true
          });
        
        }
    });
    
    
    /* Splash screen
    
    var splash = $('<div class="ipopup-curtain" title="Smelltu til aš loka"></div>' +
                  '<div class="splash">' +
                  '<div class="boxbody">' +
                    '<img src="/media/ellingsen/overlay.jpg" title="Smelltu til aš loka" />' +
                  '</div>' +
                '</div>');
                  
    function closeSplash() { splash.fadeOut(500); }
    
    if(!$.cookie('splash'))
    {
      $('body.home')
          .append(splash)
              .click(function(){
                  closeSplash();
              });
    }
    
    $.cookie('splash', '1', { expires: 1, path: '/' });
    
    setTimeout(function(){ closeSplash(); }, 15000);
    */
    
    $('fontsizer').fontsizer();
    
    $('form').autoValidate();
      
    
})(jQuery);