var Site = {
	start: function() {
		Site.menuHeight();
		if($('carouselHolder')) Site.carousel($('carousel'), 456, $$('#carousel li'));
    if($('galHolder')) Site.gallery();
	},

  menuHeight: function() {
    // some vars
        var menuHolder  = $('menuHolder').getCoordinates();
		var menuCont    = $('menuCont').getCoordinates();
		var footerPos   = $('footer').getCoordinates();
    
	// some calculating
		var smallerCont = menuCont.height + (footerPos.top-menuHolder.bottom) - 24;
        var biggerCont  = menuHolder.bottom - footerPos.top + 20;
    
	// IE 6 shit
		if(Browser.Engine.trident4) {
          smallerCont = (menuHolder.bottom - footerPos.top)+(footerPos.top - menuHolder.height);

		}
    
	// IE 7 shit
    if(Browser.Engine.trident5) {
         //smallerCont = (menuHolder.bottom - footerPos.top)+(footerPos.top - menuHolder.height);
	     smallerCont = menuCont.height;
		 smallerCont = smallerCont-20;
		}
    // change height
	
    if(menuHolder.bottom < footerPos.top) { 
		//alert('footerPos.top:'+footerPos.top);
         // ie 7
		 if(Browser.Engine.trident5) {
			 var nps = footerPos.top -390;
			 //alert(nps);
		    $('menuCont').setStyle('height', nps+'px'); 
		 }else{
		    $('menuCont').setStyle('height', smallerCont+'px');  
		 }

	}else if(footerPos.top < menuHolder.bottom) {
		//alert('hei 2');
		$('footer').setStyle('margin-top', biggerCont+'px'); 
	}

	},
	
	carousel: function(container, containerWidth, items) {
		var max_margin = items.length * containerWidth - containerWidth;
    //if($('carouselHolder')) { var animation  = new Fx.Tween(container, {duration: 1000, transition: Fx.Transitions.Quart.easeOut}); }
		if($('carouselHolder')) { var animation  = new Fx.Tween(container, {duration: 'short'}); }

		function next_item(pos) {
  	  if(pos == - max_margin) { animation.start('left', 0); }
  	  else{ var newposition = pos - containerWidth; animation.start('left', newposition);}
  	}

  	function previous_item(pos) {
  	  if(pos == 0) { animation.start('left', - max_margin);}
  	  else{ var newposition = pos + containerWidth; animation.start('left', newposition);}
  	}

    $('next').addEvent('click', function() {
  	  var position = parseInt(container.getStyle('left'));
  		next_item(position);
  	});

  	$('previous').addEvent('click', function() {
  	  var position = parseInt(container.getStyle('left'));
  		previous_item(position);
  	});
  },

  gallery : function() {
	  var links = $$("a").filter(function(el) { return el.rel; });
	  $$(links).slimbox({counterText: picture+'<b>'+" {x} "+'</b>'+from+'<b>'+" {y}"+'</b>'}, null, function(el) {
		return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
	  });
  }
	
	
};
window.addEvent('domready', Site.start);
