$(document).ready(function() {

	var refreshIntervalId = setInterval( "slideSwitch()", 6000 );
	
	$(".banner_thumbnails > li").mouseover(function() {
		clearInterval(refreshIntervalId);
		
		$(this).find('img').addClass('hover', 100);
		
		var current_thumb = $(this).find('img').attr('name');
		
		$('#slideshow').find('img').each(function(){
			
			if($(this).hasClass('active') || $(this).hasClass('last-active'))
			{
				$(this).removeClass('active last-active');
			}
			$(this).addClass('non-active');
			
		  });
		  
		$('#slideshow').find('img').each(function(){
			
			$(this).removeClass('non-active')

			if($(this).attr('name') == current_thumb)
			{
				$(this).addClass('active');
			}
			
		  });
		  
		refreshIntervalId = setInterval( "slideSwitch()", 6000 );
		
	  }).mouseout(function(){
		$(this).find('img').removeClass('hover', 100);
	  });
	  
	  $(".room_image").mouseover(function() {
			$(this).find('span').css({'display' : 'block'});
	  }).mouseout(function(){
			$(this).find('span').css({'display' : 'none'});
	  });
	  
	  $("#corporate").click(function(){
		  
		  $.fancybox({
			'padding'		: 10,
			'autoScale'		: true,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'title'			: this.title,
			'width'			: 900,
			'height'		: 600,
			'href'			: this.href,
			'type'			: 'iframe'
			});

			return false;
		  
	  });
	  
	  $(".faq").accordion({ animated: 'blind', autoHeight: false });
	  	  
	  $(".room_text").find('a').click(function(){
		  
		  $.fancybox({
			'padding'		: 10,
			'autoScale'		: true,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'title'			: this.title,
			'width'			: 900,
			'height'		: 600,
			'href'			: this.href,
			'type'			: 'iframe'
			});

			return false;
		  
	  });
	  
	  $(".book_online").click(function(){

			// set default autoScale on
			var autoScale = true;

			// detect iPad/ iPod/ iPhone and turn off autoScale
			var ua = navigator.userAgent;
			var IsiPad = /iPad/i.test(ua) || /iPhone/i.test(ua) || /iPod/i.test(ua);

			if ( IsiPad ) {
				autoScale = false;
			}
		  
		  $.fancybox({
			'padding'		: 10,
			'autoScale'		: autoScale,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'title'			: this.title,
			'width'			: 900,
			'height'		: 6600,
			'href'			: this.href,
			'type'			: 'iframe'
			});

			return false;
		  
	  });
		  
	  
	  var config_gb = {
		toolbar:
		[			
			['Bold','Italic','Underline','Strike','-','NumberedList','BulletedList','-','Smiley','-','SelectAll','RemoveFormat']
		],
		
		uiColor: '#E0D3C2',
		
		height: "200"
		
	};
	
	$( '.editor_gb' ).ckeditor(config_gb); 

	$('.book_discount').tipTip({
		maxWidth: "220px", 
		edgeOffset: 10,
		defaultPosition: "right",
		delay: 0
	});
	
	$('.pagination a').click(function() {
		var pagenumber = $(this).text();
		var scroll_ammount = -1 * ( (pagenumber-1) * 628 );
		
		$('#amsterdam_overview_scroll').animate({
			top: scroll_ammount
		}, 1000);
		
		$('.pagination li').each(function(index) {
			$(this).removeClass('current');
		});
		$(this).parent().addClass('current');
		
		return false;
	});
	
});

function slideSwitch() {
    var $active = $('#slideshow IMG.active');
 
    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');
 
    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');
 
    // uncomment the 3 lines below to pull the images in random order
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );
 
 
    $active.addClass('last-active');
 
    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 3000, function() {
            $active.removeClass('active last-active');
        });
}
