		
	/* trigger when page is ready */
	$(document).ready(function () {

		/*-------------------------------------------    
			Print Button	
		-------------------------------------------*/
		
		$('.print-button').click(function() {
			
			window.print();
			
			return false;
		});
		
		var $container = $('.award-ads ul');
		
		if($container.length > 0) {
			$container.imagesLoaded( function(){
				$container.masonry({
					itemSelector : '.award-ads li'
				});
			});
		}
		
		$('.grid').masonry({
			itemSelector: '.grid .city'
		});
		
		/*-------------------------------------------    
			jQuery Cycle
		-------------------------------------------*/
		var currentSlide = 0;
		
		$('.cycle').cycle({
			activePagerClass: 'current',
			pager: '.thumbnails ol',
			timeout: 4000,
			pauseOnPagerHover: true,
			pause: true,
			pagerAnchorBuilder: function(index, slide) { 
				var src = $(slide).find('img').attr('src');
				
      		  	return '<li><div><a href="#"><img src="' + src + '" width="50" height="50" /></a></div></li>'; 
   			},
   			onPagerEvent: function(slide) {
   				
   			},
   			before: function(currentSlide, nextSlide) {
   				if(Carousel) {
   					var goto = parseInt($(nextSlide).attr('data-index')) - 1;
   					
   					Carousel.goto(goto);
   				}
   			}
		});
	
		var $hotels = $('.hotels .list');
		
		if($hotels.find('li').length > 1) {
			$hotels.cycle({			
				activePagerClass: 'current',
				containerResize: 1,
				fit: 1,
				timeout: 0,
				width: '100%', 
				pager: '.hotels .pager',
				pagerAnchorBuilder: function(index, slide) { 
					var src = $(slide).find('img').attr('src');
					
	      		  	return '<li><a href="#'+index+'"></a></li>';
	      		} 
			});
		}
		
		/*-------------------------------------------    
			Carousel	
		-------------------------------------------*/
		
		var Carousel = $('.featured-photos .thumbnails ol').Carousel({
			nextButton: $('.thumbnails .paging .next'),
			prevButton: $('.thumbnails .paging .prev'),
			css: {
				height: 70,
				width: 548,
				left: 35
			}
		});
		
			$.scrollTo = function(target, duration, easing) {
				if(!parseFloat(duration))		
					var duration=1000;
				
				if(!easing)
					var easing='swing';
					
				var oldLocation	= window.location.href.replace(window.location.hash, '');
				var newLocation	= target;
				
				if(!target) target = 'body';
				
				var target		= $(target).offset().top;
				
				// animate to target and set the hash to the window.location
				$('html:not(:animated),body:not(:animated)').animate({ scrollTop: target }, duration, easing, function() {
					// add new hash to the browser location
					window.location.href=newLocation;
				});
			
				return false;			
			}
			
		
		/*-------------------------------------------    
			Validate
		-------------------------------------------*/
		
		$('form.validate').attr('novalidate', 'novalidate');
		
		var validateOptions = {
			reset: false,
			appendToParents: 'li'
		};
		
		$('form .validate').validate(validateOptions);
		
		$('form.validate').submit(function() {
			var $t = $(this)
			var valid = $('form .validate').isValid(validateOptions);
			var $globalErrors = $('.global-errors');
				
			if(!valid) {
				
				if($globalErrors.length == 0) {
					var html = [
						'<div class="global-errors" id="errors">',
							'<h3>Fix the following errors:</h3>',
							'<ul></ul>',
						'</div>'
					].join(' ');
					
					$(html).insertBefore('#publishForm > *:first-child');
					//$(html).insertBefore('#publishForm button');
					
					var $globalErrors = $('.global-errors');
				}
				
				$('.global-errors ul').html('');
				
				$('.invalid').each(function() {
					var error = $(this).find('.error').html();
					
					if(error != null) 
						$globalErrors.find('ul').append('<li>'+error+'</li>');
				});
				
				$.scrollTo('#errors')
			}
			else {
				$globalErrors.remove();
				
				if($t.hasClass('print-form'))
					window.print();
				else
					return true;
			}
			
			return false;
		});
		
		/*-------------------------------------------    
			Play Videos
		-------------------------------------------*/
		
		$('.play-video').colorbox({
			iframe:true,
			innerWidth:700,
			innerHeight:500,
			current:'Video {current} or {total}'
		});
	
		
		/*-------------------------------------------    
			Modified Photo Scroller	
		-------------------------------------------*/
		
		$('.show-list').pager({
			next: $('.paging .next'),
			prev: $('.paging .prev'),
			photo: $('.show'),
			init: function($t, $items) {
				$('.show').activity();
				
				return true;
			}
		});	
		
		/*-------------------------------------------    
			Media Gallery
		-------------------------------------------*/
		
		$('.js.gallery .photo a').colorbox({rel:'group1'});
		
			
		/*-------------------------------------------    
			Smooth Scrolling
		-------------------------------------------*/
	
		$('.return-to-top a').click(function() {
					
			$.scrollTo(this.hash);
			
			return false;
		});
		
		//$('nav .dropdown .carousel').jCarouselLite();		
	});

