/* site.js */
/* 121509080911 */
jQuery(document).ready(function($) {
    // $() will work as an alias for jQuery() inside of this function
    /* home link hover state */
    $('#site-title a').hover(function(){
    	$('#menu-main-nav li.homeLink a').css('background-color', '#444134');
    },function(){
    	$('#menu-main-nav li.homeLink a').css('background-color', 'transparent');
    });
    
     /* slideshows */
     var slideHeight = $('.wsImageHolder img').attr('height');
     var slideWidth = $('.wsImageHolder img').attr('width');
        $('.wsImageHolder').cycle({
       		fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
       		timeout: 4000,
       		speed: 1600,
       		height: slideHeight,
       		width: slideWidth
       	});
    
    /* Dropdown Nav opacity interaction */
    $('#access ul ul').hover(function(){
    	$('#access ul ul a').stop().fadeTo(300, 0.68);
    	
    	$('#access ul ul a').hover(function(){
    		var $this = $(this);
    		$this.stop().fadeTo(300, 1);
    		}, function(){
    			var $this = $(this);
    			$this.stop().fadeTo(300, 0.68);
    		});
    	}, function(){
    		$('#access ul ul a').stop().fadeTo(300, 1);
    	}
    );
    
    $('.roomNavCat a').click(function(event){
    	event.preventDefault();
    });
    
    /* Takes out the last | in the footer nav string */
    var lastNavHtml = $('#menu-footer-nav li:last-child').html();
    var navStringArray = lastNavHtml.split(' ');
    navStringArray.pop();
    var navNewString = navStringArray.join(' ');
    $('#menu-footer-nav li:last-child').html(navNewString);
    
    /* allows click slide for the Tescher's blog feature on the home page */
    var nextPost = $('.nextBlogPost');
    var prevPost = $('.prevBlogPost');
    prevPost.fadeTo(0, 0.3);
    
    var blogFeature = $('.blogFeature');
    var clickCount = 1;
    var listCount = $('.blogFeature li').length;
    var topMargin = 0;
    
    function list_move(direction){
    	if(direction == 'down'){
    		if(clickCount < listCount){
    			topMargin =  -65 * clickCount;
    			blogFeature.animate({
    				marginTop: topMargin
    			}, 700, function(){});
		    	clickCount++;
    		}
    	}
    	
    	if(direction == 'up'){
    		if(clickCount >= 2){
    			topMargin+= 67;
    			blogFeature.animate({
    				marginTop: topMargin
    			}, 700, function(){});
		    	clickCount--;
    		}
    	}
    	
    	if(clickCount >= 2){
    		prevPost.fadeTo(500, 1.0);
    		prevPost.css('cursor', 'pointer');
    	}else{
    		prevPost.fadeTo(500, 0.3);
    		prevPost.css('cursor', 'default');
    	}
    	
    	if(clickCount >= listCount){
			nextPost.fadeTo(500, 0.3);
			nextPost.css('cursor', 'default');
    	}else{
    		nextPost.fadeTo(500, 1.0);
			nextPost.css('cursor', 'pointer');
    	}
    }
    
    nextPost.click(function(){ 
    	var direction = 'down';  	
    	list_move(direction);
    });
    
    
    prevPost.click(function(){
    	var direction = 'up';  	
    	list_move(direction);
    });
       
    
    /* loads tabs and calls jQuery Cycle for each room */
    var roomTabs = $('#roomsTabs').tabs({
    	load: function(event, ui){
    		$('.wsRoomHoverImage').cycle({ 
		        fx: 'scrollHorz', 
		        startingSlide: 0,  // start on the slide that was in the markup 
		        timeout:  3000, 
		        speed:    800,
		        prev:    '.prev', 
		        next:    '.next'		        
		    });
		    //$('.roomSlidePrevNext').hide();
		    $('.roomImageWrapper').hover(function(){
		    	$('.roomSlidePrevNext').stop().fadeIn(500);
		    }, function(){
		    	$('.roomSlidePrevNext').stop().fadeOut(500);
		    });
		    var tableName = '.rateChart'
			table_row(tableName);
			
			 $('.rateChart .roomName').click(function(){
		    	
		    	$this = $(this);
		    	var roomTableID = $this.attr('id');
		    	var roomTableArray = roomTableID.split('-');
		    	var roomTableNum = roomTableArray[1];
		    	roomTabs.tabs('select', roomTableNum);
		    });
		    
			$('.readMore').hide();
			$('.readMoreLink').click(function(){
				var $thisClick = $(this);
				$thisClick.prev('.readMore').slideToggle();
			});
			
			$('.readMoreLink').toggle(function(){
				var $thisClick = $(this);
				$thisClick.text('Hide');
			}, function(){
				var $thisClick = $(this);
				$thisClick.text('Read More…');
			});
			
			var specialCount = 0
			$('.spcContainer').each(function(){
				$thisSpecial = $(this);
				console.log(specialCount);
				if(specialCount >= 3){
					$thisSpecial.hide();
				}				
				specialCount++
			});    
    	}
    });
    
    
   
    
    /* On the initial page load, goes to the first Room in the list */
    
    
    /* Tabs loading from dropdown nav */
    if($("#roomsTabs") && document.location.hash){
	  $.scrollTo("#primary");
	}else {
		$('#roomsTabs').tabs('select', 5);
	}
	
	$("#roomsTabs ul").localScroll({ 
	  target:"#roomsTabs",
	  duration:0,
	  hash:true
	});
	
	var roomListCount = $('#menu-rooms-and-suites').length;
	
	
	function changeTab(){
		var currentHash = document.location.hash;
		
		if($('.entry-content').children().hasClass('stayWrapper')){
			var stayTabs = $('#stayTabs').tabs();
			var hashSplit = currentHash.split('-');
			stayTabs.tabs('select', hashSplit[2]);
			var thisID = $('a[href="'+currentHash+'"]').attr('id');
			
			$('.activity').slideUp();
			$('.activity.'+thisID).slideDown();
			$('.activityCat a').removeClass('currentActiveCat');
			$('#'+thisID).addClass('currentActiveCat');
			$.scrollTo("#primary", 700);
			window.removeEventListener("hashchange", changeTab, false);
		}	
		
		if($('.entry-content').children().hasClass('roomListContainer')){
			var $tabs = $('#roomsTabs').tabs();
			var hashSplit = currentHash.split('-');
			$tabs.tabs('select', hashSplit[2]);
			$.scrollTo("#primary", 700);
			window.removeEventListener("hashchange", changeTab, false);
		}
		
		if($('.entry-content').children().hasClass('petTabsWrapper')){
			var $tabs = $('#petsTabs').tabs();
			var hashSplit = currentHash.split('-');
			$tabs.tabs('select', hashSplit[2]);
			$.scrollTo("#primary", 700);
			window.removeEventListener("hashchange", changeTab, false);
		}
	
	}
	
	/* checks if hash tag changes, and if so calls the correct tab */
	$('#menu-main-nav').click(function(){
		if(window.addEventListener){
			window.addEventListener("hashchange", changeTab, false);
		}else if(window.attachEvent){
			window.attachEvent("hashchange", changeTab, false);
		}else{}
	});
	
	$('.petsLinksWrapper').click(function(){
		if(window.addEventListener){
			window.addEventListener("hashchange", changeTab, false);
		}else if(window.attachEvent){
			window.attachEvent("hashchange", changeTab, false);
		}else{}
	});
    
    /* loads activites via ajax from order list of tabs */  
    $('#stayTabs').tabs({
		load: function(event, ui){
			var tableName = '.activityTable'
			table_row(tableName);
		}
	});
	
	/* Activites elements slider */
	$('.activity').hide();
	
	if($('.activityCat').hasClass('ui-state-active')){
		var $this = $('.activityCat.ui-state-active a');
		var thisID = $this.attr('id');
		$('.'+thisID).slideDown();
		$this.addClass('currentActiveCat');
	}
	
	
	$('.activityCat a').click(function(){
		var $this = $(this);
		var thisID = $this.attr('id');
		if(!$this.hasClass('currentActiveCat')){
			$('.activity').slideUp();
		}
		$('.activity.'+thisID).slideDown();
		$('.activityCat a').removeClass('currentActiveCat');
		$this.addClass('currentActiveCat');
	});
	
	/* Plan your stay hash tag linking */
	if($("#stayTabs") && document.location.hash){
	  $.scrollTo("#primary");
	}else {
		$('#stayTabs').tabs('select', 0);
	}
	
	$("#stayTabs ul").localScroll({ 
	  target:"#stayTabs",
	  duration:0,
	  hash:true
	});
	
	$('.readMore').hide();
	$('.readMoreLink').click(function(){
		var $thisClick = $(this);
		$thisClick.prev('.readMore').slideToggle();
	});
	
	$('.readMoreLink').toggle(function(){
		var $thisClick = $(this);
		$thisClick.text('Hide');
	}, function(){
		var $thisClick = $(this);
		$thisClick.text('Read More…');
	});
	
	
	/* Pets Tabs */
	$('#petsTabs').tabs({
		load: function(event, ui){
			$('td.mealCol').each(function(){
				var $this = $(this);
				if($this.text() == 'x'){
					$this.text('');
					$this.addClass('yup');
				}
			});
			var tableName = '.petsTable'
			table_row(tableName);
			
		}
	});
	
	/* Plan your stay hash tag linking pets tabs */
	if($("#petsTabs") && document.location.hash){
	  $.scrollTo("#primary");
	}else {
		$('#petsTabs').tabs('select', 0);
	}
	
	$("#petsTabs ul").localScroll({ 
	  target:"#petsTabs",
	  duration:0,
	  hash:true
	});
	
	$('.petTabsWrapper').hide();

	$('.petsLinksWrapper').click(function(){
		$(this).fadeOut(1000).hide();
		$('.petTabsWrapper').fadeIn(700);
	});
	  
   var currentPageHash = document.location.hash;
	if(currentPageHash){
		var currentLI = $('a[href="'+currentPageHash+'"]').parent();
		if(currentLI.hasClass('activityCat')){
			var parentCatSelected = currentLI;
		}else{
			var parentCat = $(currentLI).prevUntil('.activityCat');
			
			if(parentCat.length < 1){
				var parentCatSelected = $(currentLI).prev();
			}else{
				var parentCatLength = parentCat.length-1;			
				var parentCatSelected = $(parentCat[parentCatLength]).prev();
			}
		}
		
		var thisID = $(parentCatSelected).children().attr('id');
		$('.activityCat a').removeClass('currentActiveCat');
		$('#'+thisID).addClass('currentActiveCat');
		$.scrollTo("#primary", 700);
		$('.'+thisID).slideDown();
		
		/* for pets tabs display */
		$('.petsLinksWrapper').hide();
		$('.petTabsWrapper').show();
	}
	
	/* maps tabs */
	$('#directionsTab').tabs();
	$('#directionsTab').tabs('select', 3);
	
	function table_row(tableClassName) {
		var tableRowCount = 0;
		$(tableClassName+' tr').each(function(){
			var thisRow = $(this);
			if(tableRowCount%2 == 0 || tableRowCount == 0){
				thisRow.addClass('oddRow');				
			}else{
				thisRow.addClass('evenRow');
			}	
			tableRowCount++;		
		});
		
		return null;
	}
});
