// 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',
  'jquery',
  'labelizor',
  'mailtoenabler',
  'mediaplayer',
  'imgpop',
  //'tabswitcher',  // <-- we seem to be using the old tabSwitch script.
  'x/easing',
  'x/flashembed',
  'x/ifixpng',
  'x/ui-accordion',
  'x/ui-core',
  'x/ui-fxcolor',
  'x/ui-fxcore',
  Req.joinUrl.split('%{s}')[0] + 'utils_1.1.js;ragga_1.0.js;ragga_1.0-e2.js;tabswitch_1.3.js|||utf-8||||v3',
  { src: Req.baseUrl+'../js/datepicker/1.0/dp.js',  charset: 'iso-8859-1' },

  
  function(){

    var $ = jQuery;
    $.noConflict();

    $('form').autoValidate();
    $('#qstr, .imgalbum-bigimage .fi_txt input:not(.fi_qty input)').labelizor();

    if (window.datePicker) {  datePicker.init();  }

    if (window.RaggaEasy) {
      RaggaEasy.removeSelector += ', div.cattitle';
      RaggaEasy.init();
    }

    if (window.tabSwitcher) {
      $.extend(tabSwitcher.config, {
        'ul.tabs' : {
          tabSelector : 'li',
          setFragment : false,
          monitorFragment : true
        },
        'div.imgalbum div.tabnav ul' : {
          tabSelector : 'li',
          setFragment : false,
          monitorFragment : true,
          showFirst: false
        }
      });
      tabSwitcher.init();
    }

    $('#noflickerCSS').remove();
    $('div.pagestyle').fontsizer();

    if (!window.EPLICA_loggedin) {

      $('.netfang').mailtoEnabler();
      $('img').ifixpng();
      $('div.people table tr:odd, table.zebra tr:odd').addClass('alt');

      if ($('body.home').length)
      {
        // clean-up/modify the summary in frontpage tab articles
        $('div.tabbox div.nobullets div.summary')
            .each(function(){
                var imgElm = $('img', this).clone(), // cause the innerHTML
                    moreBtnParent = $('span.more', this),
                    moreBtn = $('a', moreBtnParent).clone().addClass('meira').text('meira');

                moreBtnParent.remove();

                var tabtext = $(this).text();
                if (tabtext.length > 175) {
                  //only use first 180 letters of summary in frontpage tab articles
                  tabtext = tabtext.substr(0,175) + '... ';
                }

                $(this).text( tabtext ).prepend( imgElm ).append(moreBtn);
              });


        // Random tab opened on each reload (only tabs 1 & 2)
        if(!$('body').hasClass('grunnskoli')) {
          $('ul.tabs li.tab'+ Math.ceil(Math.random()*2) +' a').trigger('click');
        }
      }

      // Add "send to facebook" link to articles
      $('p.buttons').append(
              $('<a class="btnfacebook">Senda á Facebook</a>')
                  .attr(
                      'href',
                      'http://www.facebook.com/sharer.php?u='+encodeURIComponent(document.location.href)+'&t='+encodeURIComponent($('h1').text()+' | '+$('img.logo:first').attr('alt') )
                    )
                    .bind('click', function() {
                        window.open(this.href,'sharer','toolbar=0,status=0,width=626,height=436');
                        return false;
                      })
            );


      $('div.row1 div.boxbody').equalizeHeights();
      $('div.row1 div.boxbody').equalizeHeights();
      $('div.row2 div.boxbody').equalizeHeights();
      $('div.row3 div.boxbody').equalizeHeights();
      $('div.imgalbum-folders li').equalizeHeights();

      $('div.yearindex ul').accordion({
              header:    'h4',
              animation: 'easeslide',
              event:     'mouseover'
            });

    }

    // bokasafn
    $('div.bokasafn')
        .each(function(){

            var homeHref = '/bokasafn2';

            $('.brand a, .breadcrumbs a.home').attr('href', homeHref);

            var homebtn = $('<li class="home"><a href="' + homeHref + '">Forsíða</a></li>');

            if($('body').hasClass('home')) {
                homebtn.addClass('current');
            }

            $('.mnav ul').prepend(homebtn);


            $('.galleryitem, .gallery', this)
                .find('a[href$=".mp3"], a[href$=".MP3"]')
                    .addClass('aud')
                    .mediaPlayer()
                    .bind('click', function(){
                        $(this).hide();
                    });

            $('.home .galleryitem .boxhead').wrapInner('<a href="' +homeHref+ '/fugl-manadarins/" />');

            $('.event-link').appendTo($('.monthlist .boxbody'));

            $('div.dateinfo')
                .hover(
                    function(){

                        $(this).parent().find('> a').addClass('hover');

                    },
                    function(){

                        $(this).parent().find('> a').removeClass('hover');

                    });

        });


        
    $('div.grunnskoli')
        .each(function(){
          
                  // ATH : Þarf að laga þegar nýjar myndir eru settar inní myndaalbúmið!!!
            $('div.imgalbum-images ul a')
            // $('ul.project-images ul a, div.imagelist ul a') // FIXME: might be needed later
                .each(function(){
                    var img = $(this).find('img')[0];
                    this.href = img.src.replace(/\/[^\/]+\/([^\/]+)$/, '/xlarge/$1');
                    img.title = img.alt;
                    img.alt = $(this).parent().find('p.imgtext').text();
                  })
                  .imgPopper({
                      curtainColor : '#000',
                      curtainOpacity : '0.75'
                    });

          
        });


    //init videolist script
    $('.videolist').Req(
        'http://codecentre.eplica.is/jquery/quickies/quicky-videoplayer-min.js',
        function() {
          $(this).videoList({ 
              vidWidth: 464,
              vidHeight: 370,
              autostart: 'all',
              defaultImg: '/media/baejarstjornarfundir/defaultimg.png'
            });
        }
      );

    // initialize the accordion widget (on the front page).
    $('div.accordion')
        .find('.boxhead')
            .wrapInner('<a href="#"></a>')
            .find('a')
                .bind('click', function(e){ e.preventDefault(); })
            .end()
        .end()
        .accordion({
            header:        '.boxhead',
            selectedClass: 'boxhd-open',
            animation:     'easeslide'
          });


    $('a.flashapp')
        .bind('click', function (e) {
            var popWrapper = $('<div class="flashapp-curtain"></div>'
                            + '<div class="flashappwrap">'
                            + '<object width="1024" height="768" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0">'
                            +   '<param name="movie" value="/media/flash/brunnur/application.swf" /><param name="base" value="/media/flash/brunnur/" /><param name="wmode" value="transparent" /><param name="allowfullscreen" value="true" />'
                            +   '<embed src="/media/flash/brunnur/application.swf" base="/media/flash/brunnur/" width="1024" height="768" allowfullscreen="true" wmode="transparent" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'
                            + '</object>'
                            + '<a class="close" href="#">Loka</a>'
                            + '</div>');
                    popWrapper
                        .filter('.flashapp-curtain, ')
                            .add( $('a.close', popWrapper) )
                                .bind('click', function(e){ popWrapper.remove(); })
                            .end()
                        .end()
                        .appendTo('body');
            return false;
          });


    // newslist
    $('.home div.newslist h2.boxhead').wrapInner('<span />');



    // Lækningaminjar skráningareyðublað
    $('.laeknminjar-reg').Req( Req.localPath+'js/laeknminjar-reg.js' )


  }
);

