function replaceVideo(ytid){
	$('#youtubeplaying').html('<object class="' + ytid + '" width="620" height="473"><param name="movie" value="http://www.youtube.com/v/' + ytid + '&amp;autoplay=1&amp;hl=en&amp;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/' + ytid + '&amp;autoplay=1&amp;hl=en&amp;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" wmode="transparent" width="620" height="473"></embed></object>')
	.attr('class', ytid);
}

$(document).ready(
	function() {
		
		// Open links with rel="external" in new window - like ye ole' target="_blank"
		$('a[rel="external"]').click(function() {window.open( $(this).attr('href') ); return false;});

		// Top Tab Switcher
		$('body.home #mainnav li:not(.deals) a').click(function(){
			if(!$(this).hasClass('active')){
				var showthis = $(this).parent('li').attr('class');
				$('#mainnav li a').removeClass('active');
				$(this).addClass('active');
				$('#content .tab').hide();

				// Remove the movie when switching tabs and put it back when returning to videos.
				if (showthis == "videos"){
					var currentmovie = $('#youtubeplaying').attr('class');
					replaceVideo(currentmovie);
				} else {
					$('#youtubeplaying').html('');
				}

				// IE6 doesn't handle the animation well. Just show/hide instead.
				if (jQuery.browser.msie) {
					if(parseInt(jQuery.browser.version) <= 6) {
						$('#'+showthis).show();
					} else {
						$('#'+showthis).slideDown();
					}
				} else {
					$('#'+showthis).slideDown();
				}
			}
			return false;
		});


		// Set the deals tab active if this is the list or deal detail page.
		if ( $("ul.dealspagelist").length + $("h3.hotelname").length > 0 ) {
			$("#mainnav li.deals a").addClass('active');
		}


		// Non-Home Top Tab Switcher
		$('body.internal #mainnav li a').click(function(){
			var showthis = $(this).parent('li').attr('class');
			$.cookie('activetab', showthis, { expires: .00035 });
			// .0007 days = ~1min
		});
		
		// Initialize Lightbox
		$(".lightbox").lightbox();


		$('#accordian li a.toggleswitch').click(function(){
			if (!$(this).hasClass('active')){
				$('#accordian li a.toggleswitch').removeClass('active');
				$(this).addClass('active');
				$('#accordian .tab').slideUp();
				$(this).next('.tab').slideDown();
			}
			return false;
		});

		$('#youtube li').click(function(){
			$('#youtube li').removeClass('active');
			$(this).addClass('active');
			$(this).children('strong').children('a').click();
		});
		$('#youtube strong a').click(function(){
			var newvideo = $(this).attr('href').replace('http://www.youtube.com/watch?v=','');
			replaceVideo(newvideo);
			return false;
		});
		

	}
);
