jQuery(document).ready(function($) {
    // $() will work as an alias for jQuery() inside of this function
    
    /* hover fade ins for sidebar box elements */
    $('.wsHoverLink').hover(function(){
    	var currentLink = this;
    	var hoverHeight = $(currentLink).children('img').attr('height');
    	var hoverWidth = $(currentLink).children('img').attr('width');
    	$(currentLink).children('.wsHoverText').css('height', hoverHeight);
    	$(currentLink).children('.wsHoverText').css('width', hoverWidth);
    	$(currentLink).children('.wsHoverText').stop(true, true).fadeIn();
    	var textHeight = $(currentLink).children('.wsHoverText').children().outerHeight();
    	$(currentLink).children('.wsHoverText').children().css('margin-top', -(textHeight/2));
    }, function(){
    	var currentLink = this;
    	$(currentLink).children('.wsHoverText').stop(true, true).fadeOut();
    });
    
     /* slideshows */
        $('.wsImageHolder').cycle({
    		fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
    		timeout: 4000,
    		height: 444,
    		width: 980
    	});
    	
     /* Home page slideshow with text reveal */     
        function beforeSlide(){
        	var textElement = $(this).children()[1];
          	$(textElement).hide();
          	var imageWidth = $(textElement).children().children().attr('width');
        	$(textElement).css('margin-left', -(imageWidth/2));
        }
        
        function onAfter(){
        	var textElement = $(this).children()[1];
        	$(textElement).delay(1500).fadeIn(1500, function(){});
			/* Grabs text image width and possitions the margin left half it's width (used in conjunction with absolute position 50%) */
        	var imageWidth = $(textElement).children().children().attr('width');
        	$(textElement).css('margin-left', -(imageWidth/2));
        }
        
        $('.homeSlides').cycle({
            fx:     'fade',
            speed:   1700,
            timeout: 8000,
            before: beforeSlide,
            after: 	onAfter,
    		height: 444,
    		width: 980
        });
        
        /* Room overview swap */
        $('.room-name').hover(function(){
            	ws_this = this;
            
            	if($(ws_this).hasClass('activeRoom')){
            		
            	}else{
            		$('.room-list-name').removeClass('activeRoom');
            		$('.room-name').removeClass('activeRoom');
            		$('.wsRoomSumContainer').fadeOut().removeClass('activeRoom');
            		$(ws_this).addClass('activeRoom');
            		$(ws_this).siblings('.wsRoomSumContainer').fadeIn().addClass('activeRoom');
            		$(ws_this).parent().addClass('activeRoom');
            	}
        });
        
    /* directions  */  
    $('.scListButton#south').addClass('directActive');
    $('div#south').addClass('directActive');
     
    
	$('.scListButton').click(function(){
		var clickedHere = this;
		
		var clickedID = $(clickedHere).attr('id');
		
		if(!$('div#'+clickedID).hasClass('.directActive')){
			$('.directions').removeClass('directActive');
			$('.scListButton').removeClass('directActive');
			$('li#'+clickedID).addClass('directActive');
			$('div#'+clickedID).addClass('directActive');
		}
	});    
	
	/* our area */
	$('.areaListButton#mendButton').addClass('areaActive');
    $('div#mendButton').addClass('areaActive'); 
    
    $('.areaListButton').click(function(){
		var clickedHere = this;
		
		var clickedID = $(clickedHere).attr('id');
		
		if(!$('div#'+clickedID).hasClass('.areaActive')){
			$('.wsOurArea').removeClass('areaActive');
			$('.areaListButton').removeClass('areaActive');
			$('li#'+clickedID).addClass('areaActive');
			$('div#'+clickedID).addClass('areaActive');
		}
	});

	/* Specials slider */
	$('.wsSpecialContainer').before('<div id="nav">');
	$('.wsSpecialContainer').cycle({
		fx:     'scrollHorz', 
	    speed:  'slow', 
	    timeout: 14000, 
	    pager:  '#nav',
	    pause: true
	});
	
	/* Packages Slider */
	$('.wsPackagesContainer').before('<div id="nav">');
	$('.wsPackagesContainer').cycle({
		fx:     'scrollHorz', 
	    speed:  'slow', 
	    timeout: 14000, 
	    pager:  '#nav',
	    pause: true
	});
	
	/* Media Slider */
	$('.wsMediaContainer').before('<div id="nav">');
	$('.wsMediaContainer').cycle({
		fx:     'scrollHorz', 
	    speed:  'slow', 
	    timeout: 18000, 
	    pager:  '#nav',
	    pause: true,
	    height: 300 
	});
	
	/* Popups */
	/* pop-ups via fancybox */
	    /* map fancybox */
		var siteWidth = 684;
		
		$('.popFancy').fancybox({
		 	'type'		:'iframe',
			'width' 	:siteWidth,
			'height' 	:810,
			'padding' 	:3,
			'scrolling'	: 'auto'			
		});
	
});


