(function($) { /* some code that uses $ */ 
	
	$( ".calendar input" ).datepicker({ 
		dateFormat: 'yy-mm-dd',
		dayNames: ['Söndag', 'Måndag', 'Tisdag', 'Onsdag', 'Torsdag', 'Fredag', 'Lördag'],
		dayNamesMin: ['Sö', 'Må', 'Ti', 'On', 'To', 'Fr', 'Lö'], 
		dayNamesShort: ['Sö', 'Må', 'Ti', 'On', 'To', 'Fr', 'Lö'],
		firstDay: 1,
		monthNames: ['Januari','Februari','Mars','April','Maj','Juni','Juli','Augusti','September','Oktober','November','December'],
		nextText: 'Nästa',
		prevText: 'Föregående'
	});
	
	$('#Content a[href^="#"]').click(function(event){		
		event.preventDefault();
		var scrollTo = (this.hash == '') ? 0 : $(this.hash).offset().top;
		$('html,body').animate({scrollTop:scrollTo}, 500);
	});
	
	/* start toggle menu in mobile  */
	$('#togglemenu').click(function() {
		$('.mainMenu').slideToggle('slow', function() {
		// Animation complete.
		});
	});
	var cufonWidth = browserWindowWidth();
	$(window).resize(function() {
		if ($("#togglemenu").css('visibility') == 'hidden' && $(".mainMenu").css('display') == 'none') {
			$(".mainMenu").css('display', '');
		}
		if ((browserWindowWidth() > 768 && cufonWidth <= 768) || 
			(browserWindowWidth() <= 768 && cufonWidth > 768) ||
			(browserWindowWidth() > 300 && cufonWidth <= 300) || 
			(browserWindowWidth() <= 300 && cufonWidth > 300)  ) {
			cufonWidth = browserWindowWidth();
			Cufon.refresh();
			Cufon.now();
		}
	});
	/* end toggle menu in mobile  */
	
		
		
		if (jQuery.browser.mobile) {
			
			(function(window, PhotoSwipe){
				document.addEventListener('DOMContentLoaded', function() {
					
					var allHotels = $(".hotels-hotel"), options = {}, instances = {};
					
					allHotels.each( function(i) {
						var photos = $(this).find('a.colorbox');
						if (photos.length > 0) {
							instances[i] = PhotoSwipe.attach( photos, options );
							//instance = PhotoSwipe.attach( window.document.querySelectorAll('.hotels-hotel .colorbox'), options );
						}
					});
						
				}, false);
			}(window, window.Code.PhotoSwipe));
			
		} else {
			$(document).ready(function(){
			
				$(".colorbox").colorbox({
					slideshow: true,
					slideshowAuto: false,
					opacity: 0.5,
					maxWidth: '100%',
					maxHeight: '100%',
					current: "bild {current} av {total}",
					slideshowStart: false,
					onComplete: function() {
						Cufon.replace('#cboxCurrent', { fontFamily: 'Interstate' });
						Cufon.now();
					}
				});
			});
		}
		
		/* to show a flexslider inside a colorbox, not very flexible... 
		$(".colorbox").colorbox({
			inline : true,
			maxWidth : '650px',
			maxHeight : '400px',
			width: '80%',
			height: '80%',
			onComplete : function() {
				$('#cboxLoadedContent .flexslider').flexslider({
					slideshow: false
				});
			}
		});
		*/
	
	$(".zoom").click(function() {
		$(this).prev('.colorbox').trigger('click');
	});
	
	$(".open-to-display").click(function() {
		var i = 0;
		var hotel = $(this).closest('.hotels-hotel');
		hotel.toggleClass('opened');
		$(this).fadeToggle('fast', function() {
			hotel.find('.display-on-open').slideToggle();
			hotel.find('.hide-on-open').fadeToggle();
			if ($(this).hasClass('more-hotel-info')) {
				hotel.find(".less-hotel-info").fadeIn();
			} else {
				hotel.find(".less-hotel-info").fadeOut();
				hotel.find(".more-hotel-info:hidden").fadeIn();
			}
		});
	});
	
	$(".tripstype, .tripscountry, .puff, .hotelscountry").biggerlink();
	
	function browserWindowHeight() {
		var browserWinHeight = 0;
		if( typeof( window.innerWidth ) == 'number' ) {
			//Non-IE
			browserWinHeight = window.innerHeight;
		} else if( document.documentElement && ( document.documentElement.clientHeight ) ) {
			//IE 6+ in 'standards compliant mode'
			browserWinHeight = document.documentElement.clientHeight;
		} else if( document.body && (  document.body.clientHeight ) ) {
			//IE 4 compatible
			browserWinHeight = document.body.clientHeight;
		}
		return browserWinHeight;
	}
	
	function browserWindowWidth() {
		var browserWinWidth = 0;
		if( typeof( window.innerWidth ) == 'number' ) {
			//Non-IE
			browserWinWidth = window.innerWidth;
		} else if( document.documentElement && ( document.documentElement.clientWidth ) ) {
			//IE 6+ in 'standards compliant mode'
			browserWinWidth = document.documentElement.clientWidth;
		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			//IE 4 compatible
			browserWinWidth = document.body.clientWidth;
		}
		return browserWinWidth;
	}
	
	
	$(".tripstype").hover(function() {
		if (browserWindowWidth() > 768) {
			var h = $(this).find('.elevated').height();
			var parentH = $(this).height();
			var newTop = 100 - ((h / parentH) * 100);
			$(this).find('.elevator').stop().animate({
				'top' : newTop + '%'
			}); 
		}
			
	}, function() {
		if (browserWindowWidth() > 768) {
			$(this).find('.elevator').stop().animate({
				'top' : '86.3%'
			}); 
		}
	});
	
	$('select[name="travellers-total"]').change(function() {
		var value = $(this).val();
		var disable = false;
		
		$('select[name="traveller-kids"] option').each(function(i) {
			if ($(this).val() == value && value != '>6') {
				disable = true;
			}
			if ($(this).attr('selected') == 'selected' && disable) {
				$(this).removeAttr('selected');
			}
			if (disable) {
				$(this).attr('disabled', 'disabled');
			} else {
				$(this).removeAttr('disabled');
			}
		});
		
	});

})(jQuery)
