var mouseover = {
	init: function(){
		$$('.rollover').each(function(el){
			Element.observe(el, 'mouseover', function(e){
				el.setStyle({'background': '#292929'});
			});
			Element.observe(el, 'mouseout', function(e){
				el.setStyle({'background': 'none'});
			});
			Element.observe(el, 'click', function(e){
				this.descendants().each(function(el){
					if(el.hasClassName('location')){
						window.location = el.href;
					}
				});
			});
		});
		
		$$('.shop-spotlight img').each(function(el){
			Element.observe(el, 'mouseover', function(e){
				this.ancestors()[0].next().showIt = true;
			});
			Element.observe(el, 'mouseout', function(e){
				this.ancestors()[0].next().showIt = false;
			});
		});
		
		$$('.shop-spotlight div.overlay').each(function(el){
			Element.observe(el, 'mouseover', function(e){
				this.showIt = true;
			});
			Element.observe(el, 'mouseout', function(e){
				this.showIt = false;
			});
		});
		
		new PeriodicalExecuter(mouseover.checkOverlay, 0.3);
		
	},
	
	checkOverlay: function(){
		
		$$('.shop-spotlight div.overlay').each(function(el){
			if(el.showIt == true){
				el.showIt = 'done';
				new Effect.Move(el, { x: 0, y: 110, mode: 'absolute', duration: 0.2 });
			}else if(el.showIt == false){
				el.showIt = 'done';
				new Effect.Move(el, { x: 0, y: 151, mode: 'absolute', duration: 0.2 });
			}
		});
	}
}

var googleMaps = {
  init: function()
  {
    if($('map-expand'))
    {
      Element.observe($('map-expand'), 'click', function(e){
        e.stop(e);
        el = $('map-expand');

        if(this.shown)
        {
          this.shown = false;
          $('map-content').morph('height:150px;',{duration: 0.5});
          onComplete: 
        	el.className = 'expand';
        	el.innerHTML = 'Kaart uitschuiven';
        }
        else
        {
          this.shown = true;
          $('map-content').morph('height:400px;',{duration: 0.5});
          onComplete:
        	el.className = 'collapse';
          el.innerHTML = 'Kaart inschuiven';
        }
      });
    }
  }
}

var strictNewWindows = {
	init: function(){
		$$('a').each(function(el) {
			if(el.rel.split(' ').indexOf('external') > -1) {
				el.target = '_blank';
			}
		});
	}
}

function toggleSlide(el)
{
	new Effect.toggle(el, 'blind', { duration: 0.6 });
}

document.observe('dom:loaded', function () {
	mouseover.init();
	googleMaps.init();
	strictNewWindows.init();
});