/*
Mootools more:
Assets, Tips
*/

window.addEvent('domready', function() {

  // sIFR
  // var times = {src:'/_scripts/times.swf'};
  // sIFR.activate(times);
  // sIFR.replace(times, {
    // selector: 'h1'
  // });
   sIFR.replaceElement('h1', named({
    sFlashSrc:'/_scripts/times.swf',
    sColor:'#B7042C',
    sCase:'upper',
    sWmode:'transparent'
  }));

  // replace all rel=external links with target=_blank
  $$('a[rel=external]').setProperty('target', '_blank');
  // replace all rel=mediaitem links (media related to page) with target=blank
  $$('a[rel=mediaitem]').setProperty('target', '_blank');

  if (Browser.Engine.trident) {
    $('header').getElements('.AspNet-Menu-Horizontal li:odd').each(function(li) {
      li.setStyle('background-image','url(/_images/menu2-bg1.png)');
    });
  }
  
  // Margin by some nav items
  $$('#nav ul.AspNet-Menu li:nth-child(first)').setStyle('margin-bottom','10px');
  $$('#nav ul.AspNet-Menu ul li:nth-child(first)').setStyle('margin-bottom','0px');
  $$('#nav ul.AspNet-Menu li:nth-child(4)').setStyle('margin-bottom','10px');
  $$('#nav ul.AspNet-Menu ul li:nth-child(4)').setStyle('margin-bottom','0px');
  
  /* add Flash to page header */
 /*  var obj = new Swiff('/_images/flash/header.swf', {
		id:'flashHeader',
		width:938,
		height:254,
		params: {
			wmode:'opaque',
			bgcolor:'#FFFFFF'
		}
	}).inject($('header')); */
  //To fix 'ExternalInterface' call in Flash for IE
  //window.flashHeader = $('flashHeader');

  if ($('headerfoto')) {
    var currentImg = $('headerfoto').getElement('img');

    if (currentImg.get('src') == '/imgHandler.ashx?img=/_images/flash/images/1.jpg&h=254') {
        new Element('img', {
            src : '/imgHandler.ashx?img=/_images/flash/images/pand_denhaag.jpg&h=254',
            styles : {
                opacity : 0
            }
        }).inject($('headerfoto'), 'bottom');

        new Element('div', {
            'class' : 'vestiging', 
            styles : {
                opacity : 0
            }, 
            html : 'Vestiging Leiden'
        }).inject($('headerfoto'), 'bottom').clone().set('html', 'Vestiging Den Haag').inject($('headerfoto'), 'bottom');

        $('headerfoto').getElement('.vestiging').fade('in', {duration : 2000});

        (function() {
            $('headerfoto').getElement('img').fade('out', {duration : 2000}).inject($('headerfoto'), 'bottom')
            $('headerfoto').getElement('img').fade('in', {duration : 2000})
            $('headerfoto').getElement('.vestiging').fade('out', {duration : 2000}).inject($('headerfoto'), 'bottom')
            $('headerfoto').getElement('.vestiging').fade('in', {duration : 2000})
        }).periodical(Math.round((Math.random() * 5000 + 8000)));
    }
  }

  $('netlaw').addEvents({
    'mouseover':function() {this.getElement('img').setProperty('src','/_images/netlaw1.gif')},
    'mouseout':function() {this.getElement('img').setProperty('src','/_images/netlaw2.gif')}
  });
  
  // Different color for some menu items
  // $('nav').getElement('.AspNet-Menu li:nth-child(2) a').setStyle('color','#FF0000');
  // $('nav').getElement('.AspNet-Menu li:nth-child(3) a').setStyle('color','#FF0000');
  // $('nav').getElement('.AspNet-Menu li:nth-child(4) a').setStyle('color','#FF0000');
  
  if($$('.employeeImg')) {
    $$('.employeeImg').each(function(emp) {
      if(emp.hasClass('hidden')) {
        emp.addEvent('mouseout',function() {SwapImage(this);});
      } else {
        emp.addEvent('mouseover',function() {SwapImage(this);});
      }
    });
  }
  
  // Dirty back links
  $$('.dirtyBackLink').each(function(link) {
    link.addEvent('click',function(e) {
      var ev = new Event(e);
      ev.stop();
      window.history.go(-1);
    });
  });
  
});

function SwapImage(img) {
  if(img.getParent().getElement('.employeeImg.hidden')) {
    img.getParent().getElement('.employeeImg.hidden').removeClass('hidden');
    img.addClass('hidden');
  }
};
