// JavaScript Document
$(document).ready(function(){
						  
						  
	$("a.childrens-policy").click(function (e){
		e.preventDefault();
		$("p#childrens-policy").slideToggle();
	});
						   
	/*search tab*/
	//position search tab
	var windowWidth = $(window).width();
	var searchFormWidth = 246;
	
	function positionSearch() {
		var newWindowWidth = $(window).width();
		var searchButtonWidth = $("#search-form").width();
		var middleScreen = (newWindowWidth/2);
		var mainWidth = $("#main-content").width();	
		mainWidth = mainWidth/2;	
		var searchPos = (middleScreen)-(mainWidth+searchButtonWidth-searchFormWidth)
		$("#search-form").css({'left': searchPos});
		var windowWidth = $(window).width();		

		// reset form on resize
	}
	
	positionSearch()
	//position search tab on resize
	$(window).resize(function(){
		positionSearch();
		$('#search-form').css("z-index", "1");		

	}); 
	
	//show search box
	var viewSearch = 0;

	var searchTabPos = 	parseInt($("#search-form").css("left").replace('px',''));	
	// check for IE6 as the search tab needs hiding in IE6 due to drop downs having a massive z-index	
	var isIE6 = $.browser.msie && parseFloat($.browser.version) < 7;		
	if (isIE6) {
		$('#search-box select').hide();
	}
	
	$('.search-tab').click(function() {
		searchTabPos = 	parseInt($("#search-form").css("left").replace('px',''));	
		windowWidth = $(window).width();
		if(windowWidth > 1525) {
			if(viewSearch == 0) {
				$('#search-form').stop(true, true).animate({left: searchTabPos - searchFormWidth}, 1000);	
				if (isIE6) {
					$('#search-box select').show();
				}
				viewSearch=1;
			} else {
				$('#search-form').stop(true, true).animate({left: searchTabPos}, 1000);	
				if (isIE6) {
					$('#search-box select').hide(200);
				}
				viewSearch=0;
			}
		} else {
			if(viewSearch == 0) {
				$('#search-form').css("z-index", "1000");
				if (isIE6) {
					$('#search-box select').show();
				}
				viewSearch=1;
			} else {
				$('#search-form').css("z-index", "1");	
				if (isIE6) {
					$('#search-box select').hide(200);
				}
				viewSearch=0;
			}
		}
	 });		

						   
	//$(document).pngFix();					   
						   
	$("input:checkbox").uniform();
	if (!$.browser.opera) {

		// select element styling
		$('select.select').each(function(){
			var title = $(this).attr('title');
			if( $('option:selected', this).val() != ''  ) title = $('option:selected',this).text();
			$(this)
				.css({'z-index':10,'opacity':0,'-khtml-appearance':'none'})
				.after('<span class="select">' + title + '</span>')
				.change(function(){
					val = $('option:selected',this).text();
					$(this).next().text(val);
					})
		});

	};
	
	
	

	
	/*hotel image transition */
	
	var maxCount= $('#image-images').children('img').length;
	var count=2;
	var previous=1;
	var timerval;
	var originalTitle;
	var title;
	var currentRel;
	
	
	originalTitle = $('#image-images img:first').attr('title');
	$('#image-info').html(originalTitle);
	Cufon.replace('#image-info');

	
	timeron();
	
	function timeron(){
		if(maxCount >1 ){
			clearInterval(timerval);	
			timerval = setInterval(imageRotation,5000);			
		}
	} 
		
	function imageRotation() {
		$('#image-'+previous).fadeOut(500); //fade out speed this is set to 0.5 seconds at the moment
		$('#image-'+count).fadeIn(500); //fade in speed this is set to 0.5 seconds at the moment
		
		//show and hide room name
		title = $('#image-'+count).attr('title');
		$('#image-info').html(title);
		Cufon.replace('#image-info');
		
		previous = count;
		count ++;
		if(count==maxCount+1) {
			count=1;
		}
	};	
		
	$('#image-thumbs a').click(function (event) {
		event.preventDefault();

		count = $(this).attr('rel').replace('image-','');
		
		title = $(this).attr('title');
		$('#image-info').html(title);
		Cufon.replace('#image-info');
		
		imageRotation();
		timeron();
		return false;
    });



	
	//highlight room type and show book now on hotel page
	//hide book now button
	var hoverClass = 'hover';
	var selectedClass = 'selected';
	
	$('input.booknow').hide();		
	$('.room-type-row').hover(function () {
			$('.room-information').hide();								
			$('.room-type-row').removeClass('row-hover');		
			$('.room-type-row').children().removeClass('hover');	
			$('.room-type-info img').attr("src","/images/hotels/room-info.gif");
			$(this).find('.room-type-info img').attr("src","/images/hotels/room-info-select.gif");
			$(this).addClass('row-hover');		
			$(this).children().addClass('hover');		
	});
	
	
	$('.room-type-row').click(function () {
		$('.room-information').hide();								
		$('input.booknow').hide();								
		$('.room-type-row').removeClass('row-selected');		
		$('.room-type-row').children().removeClass('selected');		
		$(this).addClass('row-selected');		
		$(this).addClass('row-selected');		
		$(this).children().addClass('selected');		
		$(this).find('input.booknow').show();
		$(this).find('input[name=room]:eq(0)').attr('checked', 'checked');
	 });
	
	$('.info').hover(function () {
		$(this).children('.room-information').show();		
	});
	
	/* hotels room image and description show and hide on click */
	$('a.make-booking').hide();
	// select the first room as selected
	$('#our-rooms .room-row:first').children('.room-tab').addClass('room-tab-selected');
	$('#our-rooms .room-row:first').children('.make-booking').show('');
	var imgTitle = $('#room-images img:first').attr('title');
	$('#image-info').html(imgTitle);
	Cufon.replace('#image-info');
	
	$('.room-tab').click(function () {
		var buttonID = $(this).attr('id');
		$('a.make-booking').hide();
		$('.room-tab').removeClass('room-tab-selected');
		$('.room-details').hide();
		$('#room-images img').hide();
		$(this).addClass('room-tab-selected');		
		$(this).siblings('a.make-booking').show();		
		$('.'+buttonID).show();
		
		var imgTitle = $('#room-images img.'+buttonID).attr('title');
		$('#image-info').html(imgTitle);
		Cufon.replace('#image-info');
		
    });
		
	
	/*home page map */
	var viewmap = 0;
	$('.maplink').click(function() {
		if (viewmap == 0) {		
			$('#home-ourhotels').stop(true, true).animate({	height: '45px'}, 1000);		
			$('.maplink').text('Show Map');	
			$(".maplink").css("background-image", "url(/images/home/map-show.gif)");
			viewmap = 1;
		} else {
			$('#home-ourhotels').stop(true, true).animate({	height: '558px'}, 1000);
			$(".maplink").css("background-image", "url(/images/home/map-hide.gif)");
			$('.maplink').text('Hide Map');				
			viewmap = 0;
		}
	});
	
	
	
	
	
	$('.our-hotels-maps ul li').hover(function () {
		removeMapSelection();
		$('#our-hotels-details #'+$(this).attr('class')).addClass('selected');
	} , function() { 
		removeMapSelection();	
	});	
	


	
	$('#our-hotels-details .area-outer').hover(function () {
		removeMapSelection();
		$(this).addClass('selected');
		$('.our-hotels-maps .'+$(this).attr('id')+' a').addClass('selected');
	} , function() { 
		removeMapSelection();	
	});	
	
	function removeMapSelection () {
		$('.our-hotels-maps').find('a').removeClass('selected');
		$('#our-hotels-details').find('.area-outer').removeClass('selected');			
	}
	//map select
	
	$('.selected-area').click(function() {
		$('#our-hotels-outer').stop(true, true).animate({	height: '65px'}, 500);			
	});	
	
	$(".southern .our-hotels-outer").css("background-image", "url(/images/map-dropdown-bg-select.png)");
	$(".southern").stop().animate({opacity:0.7},500)

	

});

	function showLondonMap () {
		$('.southern-map, .southern-area').hide();
		$('.london-map, .london-area').fadeIn(500);
		/*$('.southern-drop, .london-select').hide();
		$('.london-drop, .southern-select').show();		
		hideDropdown();*/
		$(".southern").stop().animate({opacity:0.7},500)
		$(".london").stop().animate({opacity:1},500)
		$(".southern .our-hotels-outer").css("background-image", "url(/images/map-dropdown-bg-select.png)");
		$(".london .our-hotels-outer").css("background-image", "url(/images/map-dropdown-bg.png)");
		
	}
	function showSouthernMap () {
		$('.london-map, .london-area').hide();
		$('.southern-map, .southern-area').fadeIn(500);
		/*$('.london-drop, .southern-select').hide();
		$('.southern-drop, .london-select').show();
		hideDropdown();		*/	
		$(".london").stop().animate({opacity:0.7},500)
		$(".southern").stop().animate({opacity:1},500)
		$(".london .our-hotels-outer").css("background-image", "url(/images/map-dropdown-bg-select.png)");
		$(".southern .our-hotels-outer").css("background-image", "url(/images/map-dropdown-bg.png)");
	}
	function hideDropdown() {
		$('#our-hotels-outer').stop(true, true).animate({	height: '25px'}, 1);			
	}


	/* Hotel Booking */
	/*
	$('.booknow').click(function(event) {
		event.preventDefault;
		alert('test');
		$('#choose_room').submit();
	});
	*/
	
	/* HOTEL SELECT BOX */
	var hotelBox = 0;
	function showHotelSelect () {
		if(hotelBox == 0) {
			$('.view-hotels-container').slideDown('slow');
			/*$('.view-hotels-container').fadeIn(500);
			$(".view-hotels-outer").addClass("view-hotels-container-bg");*/		
			hotelBox = 1;
		} else {
			$('.view-hotels-container').slideUp('slow');
			/*$(".view-hotels-outer").removeClass("view-hotels-container-bg");*/
			hotelBox = 0;
		}
	}
