$(document).ready(function() 
{
  $(window).resize(function(){
  
	  $('.wrapper').css({
		  position:'absolute',
		  left: ($(window).width() - $('.wrapper').outerWidth())/2,
		  top: ($(window).height() - $('.wrapper').outerHeight())/2
	  });
  
  });
  
  // To initially run the function:
  $(window).resize();
	
    $(".paging").show();
    $(".paging a:first").addClass("active");
        
    var imageWidth = $(".window").width();
    var imageSum = $(".image_reel img").size();
    var imageReelWidth = imageWidth * imageSum;
    
    $(".image_reel").css({'width' : imageReelWidth});
    
    rotate = function(){    
        var triggerID = $active.attr("rel") - 1;
        var image_reelPosition = triggerID * imageWidth;

        hideComment();
        
        $(".paging a").removeClass('active');
        $active.addClass('active');
        
var paging = $("div.paging");
var imageReel = $("div.image_reel");
        
$(".image_reel").fadeOut(0);
$(".image_reel").animate({ left: -image_reelPosition }, 0 );
$(".image_reel").fadeIn(600);
       
        showComment();
    };
    
    rotateSwitch = function(){        
        play = setInterval(function(){
            $active = $('.paging a.active').next();
            if ( $active.length === 0) {
                $active = $('.paging a:first');
            }
            rotate();
        }, 20000);
    };
    
    rotateSwitch();
    
    //On Hover
    $(".image_reel a").hover(function() {
        clearInterval(play);
        play = null;
    }, function() {
        rotateSwitch();
    });    
    
    showComment = function(){
        $(".desc").eq( $('.paging a.active').attr("rel") - 1 ).slideDown("slow");
        return true;
    };
    
    showComment();
    
     hideComment = function(){
        $(".desc").stop(true,true).slideUp('slow');
     };
    
    $(".desc").click(function(){
        hideComment();
    });
    
    $(".paging a").click(function() {    
        $active = $(this);
        clearInterval(play);
        rotate();
        rotateSwitch();
        return false;
    }); 
	
	
  $(".jquerybox").fancybox(
  {
  'width'				: '37%',
  'height'			: '93%',
  'autoScale'			: true,
  'transitionIn'		: 'over',
  'transitionOut'		: 'over',
  'type'				: 'iframe'
  });
	
  $('#bubble_akti').bubbletip($('#popup_akti'), {
	  deltaDirection: 'down',
	  deltaPosition: 50,
	  offsetTop: -5
  });
  
  $('#bubble_arrang').bubbletip($('#popup_arrang'), {
	  deltaDirection: 'down',
	  deltaPosition: 50,
	  offsetTop: -5
  });
  
  $('#bubble_blog').bubbletip($('#popup_blog'), {
	  deltaDirection: 'down',
	  deltaPosition: 50,
	  offsetTop: -5
  });
  
  $('#bubble_borneklub').bubbletip($('#popup_borneklub'), {
	  deltaDirection: 'down',
	  deltaPosition: 50,
	  offsetTop: -5
  });
  
  $('#bubble_priser').bubbletip($('#popup_priser'), {
	  deltaDirection: 'down',
	  deltaPosition: 50,
	  offsetTop: -5
  });
  
  $('#bubble_admin').bubbletip($('#popup_admin'), {
	  deltaDirection: 'down',
	  deltaPosition: 50,
	  offsetTop: -5
  }); 
  
});

Shadowbox.init({
	handleOversize: "drag",
	modal: true,
	enableKeys: true,
	displayCounter: false
});
