// encoding: utf-8
/*@cc_on/*@if(@_jscript_version<5.7)try{document.execCommand('BackgroundImageCache',0,1)}catch(e){}/*@end@*/

Req.localPath = Req.localPath || '/skin/basic/';
Req(
  'autovalidate',
  //'equalizeheights',
  'eutils',
  'fontsizer',
  'labelizor',
  'tabswitcher',
  Req.localPath+'js/jquery.fancybox.js',

  function(){

    var $ = jQuery,
        msie6 = $.browser.msie && $.toInt('0'+$.browser.version) < 7,
        body = $('body').addClass('js-active')
    
    $('#qstr').labelizor();

    $('div.tabbox').tabSwitcher();

    $('div.dropdown')
        .find('h3')
            .wrapInner('<a href="#" />')
            .bind('click', function(e) {
                $(this).parent().find('ul').slideToggle(300);
                return false;
              })
        .end()
        .bind('mouseleave', function(e){
            $(this).find('ul').slideUp(300);
          });

    $('div.productitem span.tilbod')
        .wrapInner('<li class="discount" />')
        .find('li')
        .prependTo('div.price ul.attr');
    

/** // Not sure if this is even supposed to be active.. (-- Már 2010-01-04)
    if (body.is('.twocol, .threecol'))
    {
      $('.pgextra1 div.wrap, div.pgmain div.wrap > div.box > div'+ (body.is('.threecol') ? ', div.pgextra2 div.wrap' : '') )
          .equalizeHeights();
    }
/**/


    //zebra
    $('div.people table, table.zebra').find('tbody tr:nth-child(2n)').addClass('alt');


    $(window).bind('load', function() {
        
        //center images in product lists
        $('div.products div.item')
            .each(function() {
                _item = $(this),
                _img = $(this).find('img')
                
                if( !$('body').hasClass('home') ) {
                  var mt = parseInt( (_item.height() - _img.height()) / 2, 10 );
                  _img.css('margin-top', mt + 'px');
                }
                
                _item.bind('click', function() {
                      window.location = _item.find('a').attr('href')
                    })
            
            });
        
    });
    
    //init image popup
    var imgboxes = $('div.productitem div.imagebox');
    if (imgboxes.length)
    {
      if (!imgboxes.find('a')[0])
      {
        imgboxes.find('img')
            .each(function(i){
                var img = $(this),
                    imgUrl = img.attr('src'),
                    largeUrl = imgUrl
                                  .replace(/\/medium\//,'/large/')
                                  .replace(/\/400\//,'/600/');
                img.wrap('<a href="'+largeUrl+'" />')
                if (i > 0)
                {
                  img.attr({ src: imgUrl.replace(/\/400\//,'/78/') });
                }
                else if (msie6)
                {
                  img.closest('li').addClass('first-child');
                }
                  
              });
      }
      imgboxes.find('a:has(img)').fancybox({
        fancyLoading:       true,
        overlayShow:        false,
        zoomSpeedIn:        300,
        zoomSpeedOut:       200,
        hideOnContentClick: true
      });
    
    }


    // creditcard v2 img popup
    var ccv2img = $('#ccdigits');
    ccv2img
        .hide()
        .parent()
            .append('<a href="#">Hjálp</a>')
            .bind('click', function (e) {
                ccv2img.toggle(0);
                return false;
              });

    $('#noflickerCSS').remove();


    $('.toggleforgotten')
        .bind('click', function (e) {
            $('.forgottenpassword').slideToggle('normal');
          });

    
    
    $('.pagestyle').fontsizer();
    
    $('form').autoValidate();
      
    
  }
);
