jQuery.noConflict();
jQuery(function() {
	var $j = jQuery;
	
	
	
	
/*

	
	
		
		$j('a.nyroModalMyImage').click(function(){
			
			$.nyroModalManual({
				forceType: 'image',
				type:'image',
				image: '<div class="wrapperImg nyroModalMyImage"></div>',
				url : '/assets/images/press/modal/'+this.title+'.jpg'
			});
		});
		
	*/
	
	
	// clear out form fields with reset as class name
	$j("input[type=text].reset, textarea.reset").bind("blur", function() {
			if (!this.defaultValue) return;
			if (this.value == '')
				this.value = this.defaultValue;
	}).bind("focus", function() {
			if (!this.defaultValue) return;
			if (this.value == this.defaultValue)
				this.value = '';
	});
	
	var looking = $j('div.looking');
	if (looking.length == 1) {
		var firstLooking = true;
		var panes = $j('.pane-gutter').hide();
		/*
		if (isIe6()) {
			panes.show();
			looking.show();
			$j('div.scroll-pane').jScrollPane({scrollbarWidth: 12, showArrows: true});
			looking.hide();
			panes.hide();
			firstLooking = false;
		} else
			panes.hide();
		*/
		if (isIe6()) {
			$j('div.scroll-pane').css({overflow: 'auto'});
		}
		$j('#choose-help a').click(function(e) {
			e.preventDefault();
			if (firstLooking) {
				looking.slideToggle(400, function() {
					panes.show();
					$j('div.scroll-pane').jScrollPane({scrollbarWidth: 12, showArrows: true});
				});
				firstLooking = false;
			} else {
				panes.toggle();
				looking.slideToggle(400);
			}
			return false;
		});
	}
	
	$j('#t-search a').click(function(e) {
		e.preventDefault();
		$j('#qsearch').slideToggle(400);
		return false;
	});
	var limTxt = 450;
	$j('.moreable').each(function() {
		var cont = $j(this);
		var txt = cont.text();
		if (txt.length > limTxt) {
			var splitLim = Math.min(txt.indexOf('.', limTxt), txt.indexOf(' ', limTxt)) + 1;
			var sp = txt.substring(splitLim);
			cont
				.text(txt.substring(0, splitLim))
				.append('<span style="display: none">'+sp+'</span>')
				.append('<br /><a class="plus" href="#"> read more &raquo;</a>');
			var span = $j('span', cont);
			$j('a.plus', cont).click(function(e) {
				e.preventDefault();
				span.toggle();
				if (span.is(':visible'))
					$j(this).html(' show less &laquo;');
				else
					$j(this).html(' read more &raquo;');
				return false;
			});
		}
	});
	
	$j('#formNewsletter').submit(function(e) {
		e.preventDefault();
		$j.ajax({
			url: this.action,
			type: 'POST',
			data: $j(this).serializeArray(),
			success: function() {
				$j('#formNewsletter').hide();
				$j('#newsletterConfirm').show();
			},
			error: function() {
				$j('#formNewsletter').hide();
				$j('#newsletterError').show();
			}
		});
		return false;
	});
	
	$j('#newsletterConfirm a').click(function(e) {
		e.preventDefault();
		$j('#scoop-signup').get(0).value = $j('#scoop-signup').get(0).defaultValue;
		$j('#newsletterConfirm').hide();
		$j('#formNewsletter').show();
		return false;
	});
	
	$j('#newsletterError a').click(function(e) {
		e.preventDefault();
		$j('#newsletterError').hide();
		$j('#formNewsletter').show();
		return false;
	});
	
	$j.fn.nyroModal.settings.bgColor = '#A59B8F';
	$j.fn.nyroModal.settings.endShowContent = function(elts, settings) {
		jQuery('#close', elts.contentWrapper).show();
	};
	$j.fn.nyroModal.settings.endFillContent = function(elts, settings) {
		fixPng(elts.contentWrapper);
		initOver(elts.contentWrapper);
		if (settings.type == 'gallery') {
			var div = $j('div', elts.content);
			if (div.length == 1) {
				var text = div.text().split(',,');
				var tower = text[2] || '';
				div.html('<h1>'+text[0]+'</h1><h2>'+text[1]+'<span>'+tower+'</span></h2><p class="edits" id="flag">Flag This Photo</p>');
				$j('p', div).click(function(e) {
					e.preventDefault();
					var pCl = $j(this);
					$j.ajax({
						data: {img: $j('img', elts.content).attr('src')},
						type: 'post',
						complete: function() {
							pCl
								.unbind('click')
								.addClass('flagConfirm')
								.text('This image has been successfully flagged.');
						}
					});
					return false;
				});
			}
		}
	}
	fixPng();
	initOver();
	stripBorders();
	initTabNav();
});

Event.observe(window,'load', function() {
	Ajax.Responders.register({onComplete: function() {fixPng();}});
});

function initTabNav()
{
	jQuery('#snav li a.view_tab').click(function(e) 
	{
		e.preventDefault();
		
		var link = jQuery(this);
		
		jQuery('#snav li a').removeClass('active');
		link.addClass('active');
		
		jQuery('#hotelInfos').load(link.attr('rel'));
		
		return false;
	});
}

function isIe6() {
	return (jQuery.browser.msie && parseInt(jQuery.browser.version.substr(0,1)) < 7);
}

function fixPng(elt) {
	if (!isIe6())
		return;
	
	jQuery('img[src$=.png], input[src$=.png]', elt).each(function() {
		this.src = this.src.substring(0, this.src.length - 3)+'gif';
	});
}

function helpful(id, request) {
	jQuery("#helpful"+id).text("Thanks for your input.");
	jQuery("#helpfulPC"+id).html("<br />&nbsp;("+request.responseText+"% found this review helpful.)");
}

function initOver(elt) {
	jQuery('a.rollover > img:not([src$=-over.gif]), input[type=image].rollover', elt).each(function() {
		this.srcOver = this.src.replace(/(\.[^.]+)$/, '-over$1');
		this.srcOut = this.src;
		preloadImg(this.srcOver);
	}).hover(function() {
		this.src = this.srcOver; 
	},function() {
		this.src = this.srcOut;  
	});
}

function stripBorders() {
	// change bg image for last row in your experience
	jQuery('#experience div.row:last').addClass('row-lc');
	// remove unwanted borders on last elements
	jQuery('ul.basics-listing li:last, div#experience div.show-comments div.row').addClass('bored');
}

function preloadImg(image) {
	var img = new Image();
	img.src = image;
}
	
function initPrint() {
	jQuery('a:has(#print)').click(function(e) {
		e.preventDefault();
		jQuery('.moreable span').show();
		jQuery('.moreable a').hide();
		window.print();
		jQuery('.moreable span').hide();
		jQuery('.moreable a').show();
		return false;
	});
}

var nbImage = 1;
function addImage() {
	if (nbImage < 5) {
		$("add-more").insert("<input type=\"file\" name=\"image[]\" /><br />");
		nbImage++;
	}
	if (nbImage == 5) {
		$("addMorePhotosLink").update();
	}
}

var imgs;
var on;
var off;
function initRating() {
	imgs = $$('.rating img');
	on = imgs.first().readAttribute('src');
	off = imgs.last().readAttribute('src');
	var reviewRate = $('RoomReviewRate');
	imgs.each(function(elt, i) {
		elt.val = i+1;
		elt.observe('mouseover', function() {
			elt.writeAttribute('src', on);
			elt.previousSiblings().each(function(elt) {
				elt.writeAttribute('src', on);
			});
			elt.nextSiblings().each(function(elt) {
				elt.writeAttribute('src', off);
			});
		});
		elt.observe('mouseout', makeRating);
		elt.observe('click', function() {
			reviewRate.writeAttribute('value', elt.val);
			makeRating();
		});
	});
}
function makeRating() {
	var val = $F
	imgs.each(function(elt) {
		if (elt.val <= $F('RoomReviewRate'))
			elt.writeAttribute('src', on);
		else
			elt.writeAttribute('src', off);
	});
}
function activeTab(v) {
	jQuery('#snav a').removeClass('active');
	jQuery('#'+v+' a').addClass('active');
}

(function() {
	
	function press (elm) {
		elm.observe('mouseover', function() {
			this.down().show();
		});
		elm.observe('mouseout', function() {
			this.down().hide();
		});
	}
		
	function init () {
		$$('div.press-bite-top a span').invoke('hide');
		$$('div.press-bite-top a').each(press);
	}

document.observe('dom:loaded', init);
	
})();
