//$(window).bind('resize',function(){
    // window.location.href = window.location.href;
//});

$(document).ready(function(){

			$('.unclose').click(function(){
				$('.closed').css({'display' : 'none'})
			})			  			   
// this from index page and load information into the session
		/*$('#availbility').submit(function(){

			var arrdate = $('#arrivedate').val();
			var depdate = $('#departdate').val();
			var carret =$('#carreturndate').val();
			if ((arrdate.indexOf('?') == -1)){
	//			alert("test")
			var room1 = $('#roomtype').val();
			var room2 = $('#roomtype2').val();
			var holparking = $('#holidayparking').val();
			var tok = $('#token').val();
			var loc = $('#location').val();
			
			$('.costdisplay').each(function(){
				$(this).html("<img src='images/ajax-loader.gif'>");
			})
    		$.post('incfiles/hxxmlfeed.php', {arrivedate : arrdate, DepartDate : depdate, carreturn: carret, RoomType: room1, holidayparking: holparking, token :tok, location : loc, RoomType2 : room2   }, function(data){
    			
    		//alert(data);
    			$.post('incfiles/content-center-2.php', {arrivedate : arrdate, DepartDate : depdate, carreturn: carret, RoomType: room1, holidayparking: holparking, token :tok, location : loc, sortby : '-3' , contentlocale : '1'}, function(data){
    				$('#content1 #contentcolumnmover').html(data);
    				fn_centerdivwidth()
    				$.post('incfiles/content-center-2.php', {arrivedate : arrdate, DepartDate : depdate, carreturn: carret, RoomType: room1, holidayparking: holparking, token :tok, location : loc, sortby : '-7', contentlocale : '2' }, function(data){
    					$('#content2 #contentcolumnmover').html(data);
    					//fn_centerdivwidth()
    					fn_centerdivwidth()
    					$.post('incfiles/content-center-2.php', { arrivedate : arrdate, DepartDate : depdate, carreturn: carret, RoomType: room1, holidayparking: holparking, token :tok, location : loc, sortby : '-5', contentlocale : '3' }, function(data){
    						$('#content3 #contentcolumnmover').html(data);
    						fn_centerdivwidth()
	    					$.post('incfiles/content-center-2.php', { arrivedate : arrdate, DepartDate : depdate, carreturn: carret, RoomType: room1, holidayparking: holparking, token :tok, location : loc, sortby : '-5', contentlocale : '4' }, function(data){
	    						$('#content4 #contentcolumnmover').html(data);
	    						fn_centerdivwidth()
	    						$.post('incfiles/content-center-2.php', { arrivedate : arrdate, DepartDate : depdate, carreturn: carret, RoomType: room1, holidayparking: holparking, token :tok, location : loc, sortby : '-5', contentlocale : '5' }, function(data){
		    						$('#content5 #contentcolumnmover').html(data);
		    						fn_centerdivwidth()
		    							$.post('incfiles/content-center-2.php', { arrivedate : arrdate, DepartDate : depdate, carreturn: carret, RoomType: room1, holidayparking: holparking, token :tok, location : loc, sortby : '-5', contentlocale : '6' }, function(data){
			    						$('#content6 #contentcolumnmover').html(data);
			    						fn_centerdivwidth()
				    						$.post('incfiles/content-center-2.php', { arrivedate : arrdate, DepartDate : depdate, carreturn: carret, RoomType: room1, holidayparking: holparking, token :tok, location : loc, sortby : '-5', contentlocale : '7' }, function(data){
				    						$('#content7 #contentcolumnmover').html(data);
				    						fn_centerdivwidth()
				    					})
			    					})
		    					})
	    					})
    					})
    				})
    				//$('#contentcolumninner').css({width : widtharray[3]});
    				
    			})
    		});
    		return false;
    	} else {
    		alert("Please enter Arrival Date");
    		return false;
    	}
		})*/
		// from index page it show all the of the hotels loaded
		
		
	

        // This is for index that makes the page look correct
		
		
        function fn_centerdivwidth(){
        	//GET VIEWPORT WIDTH
		
	//var viewportwidth;
	//var viewportheight;
 
	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
 
	if (typeof window.innerWidth != 'undefined')
	{
		viewportwidth = window.innerWidth,
		viewportheight = window.innerHeight
	}
 
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

	else if (typeof document.documentElement != 'undefined'
	&& typeof document.documentElement.clientWidth !=
	'undefined' && document.documentElement.clientWidth != 0)
	{
			   viewportwidth = document.documentElement.clientWidth,
			   viewportheight = document.documentElement.clientHeight
	}
 
	// older versions of IE
 
	else
	{
		viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
		viewportheight = document.getElementsByTagName('body')[0].clientHeight
	}
	//alert("Viewport Width: "+viewportwidth);	
        //alert($('#contentcolumn').width());
		
		if (viewportwidth <= '1280') {
         leftcol = Math.round($('#contentcolumn').width()/3);
		 rightcol = Math.round($('#contentcolumn').width()/3*2);
		 outercol = Math.round($('#contentcolumn').width());
		 contentcol = Math.round($('#contentcolumn').width());
		 widtharray = [leftcol, rightcol, outercol, contentcol];
		// alert("Viewport Width is less than or equal to 1280px");
		}
		else if (viewportwidth > '1600') {
		 leftcol = Math.round($('#contentcolumn').width()/5);
		 rightcol = Math.round($('#contentcolumn').width()/5*2);
		 outercol = Math.round($('#contentcolumn').width()/5*3);
		 contentcol = Math.round($('#contentcolumn').width());
		 widtharray = [leftcol, rightcol, outercol, contentcol];
		// alert("Viewport Width is more than 1280px");
		}
		else {
		 leftcol = $('#contentcolumn').width()/4;
		 rightcol = $('#contentcolumn').width()/4*2;
		 outercol = $('#contentcolumn').width()/4*3;
		 contentcol = $('#contentcolumn').width();
		 widtharray = [leftcol, rightcol, outercol, contentcol];	
		// alert("Viewport Width is less than or equal to 1280px");
		}
			
			
		Array.max = function( array ){
        return Math.max.apply( Math, array );
	    };
			
		//alert(advertheight);
		
	//SET WIDTH
		$('.inner-left').css({width : widtharray[0]});
		$('.inner-right').css({width : widtharray[1]});
		$('.outer').css({width : widtharray[2]});
		$('.wrapper').css({width : widtharray[0]});
		$('.sub-ad-inner-1').css({width : widtharray[0]-5});
		$('.sub-ad-inner-2').css({width : widtharray[1]/10*6});
		$('.sub-ad-inner-3').css({width : widtharray[1]/10*4});
		$('.inner-content-right').css({width : widtharray[1]});
		$('.wrapper-last').css({width : widtharray[0]});
		$('.inner-content-left-border').css({width : widtharray[0]-2});
		$('#hompepage-datepicker').css({width : widtharray[3]});
	//SET HEIGHT
		advertheight = $('.inner-left').height();
		contentcolheight = $('#contentcolumn').height();
		contentcolheighthome = $('#contentcolumninner-home').height();
		$('.catalogue').css({'min-height' : advertheight+1});
		$('.wrapper-last').css({'height' : advertheight});
		//$('.leftcolumn').css({'height' : contentcolheight});
		//$('.leftcolumn').css({'height' : contentcolheighthome});
		$('.getresultsbutton').css({'margin-top' : contentcolheight-67});
		}
		

		
		fn_centerdivwidth()
		
		/*CHANGE BORDER OF ARRIVAL AND RETURN FIELDS ON HOVER LISTING*/		
		$(".wrapper").hover(function() {
			$(".arrdate").css({'border-color' : 'red'});
			$(".carreturn").css({'border-color' : 'red'});
			$(this).css({'background-position' : 'right -49px'});
			//$(".highlight").css({'background-color' : 'red','color' : 'white'});
				}, function() {
			var backposition=(widtharray[0]-51);
			$(".arrdate").css({'border-color' : '#ddd'});
			$(".carreturn").css({'border-color' : '#ddd'});
			$(this).css({'background-position' : backposition+'px 0'});
			//$(".highlight").css({'background-color' : '#ddd','color' : '#333'});
		});
		
		// this is to show and hide the different content types
		$('.displaylines').click(function(){
			fn_checkclicked();
		})
		function fn_checkclicked(){
			$('.displaylines').each(function(index){
			var ischecked = $('#checkcat'+(index+1)+':checked').length;
			if(ischecked == 0){
				$('#content'+(index+1)).css({'display' : 'none'})
			} else {
				$('#content'+(index+1)).css({'display' : 'block'})
			}
			})	
		}
		// this checks what check boxes are ticked up on load of page
		fn_checkclicked();
		//
		$('.moreinfoclick').click(function(){
			//alert("in here");
			var hotelid = $(this).attr("href").substring(0, $(this).attr("href").indexOf('_'));
			var contentpage = $(this).attr("href").substring($(this).attr("href").indexOf('_')+1);
			var arrdate = $('#arrivedate').val();
			if ( (hotelid == 0) && ($('.costdisplay').text().indexOf('?') == -1)){
				var depdate = $('#departdate').val();
				var carret =$('#carreturndate').val();
				var holparking = $('#holidayparking').val();
				var tok = $('#token').val();
				var loc = $('#location').val();
	    		var hreflocal = 'results-page.php?uidhotel=0&token='+tok+'&arrivedate='+arrdate+'&DepartDate='+depdate+'&carreturn='+carret+'&collecttime=&holidayparking='+holparking+"&contentlocale="+contentpage
	    		//var hreflocal = 'incfiles/hxxmlfeed.php?arrivedate='+arrdate+'&DepartDate='+depdate+'&carreturn='+carret+'&RoomType='+room1+'&holidayparking='+holparking+'&token='+tok+'& location='+loc+'RoomType2='+room2+'&whereto=1&uidhotel=0';
	    		$('#moreclickprice1').attr("href" , hreflocal);
			} else {
				$.get("incfiles/datepickerpopup.php", {hotelid : hotelid, contentpage : contentpage}, function(data){
					$('#loadpop').html(data);
					fn_display();	
				})
				return false;
			}
			
		})
		$('.specialofferclick').click(function(){
			$.get("incfiles/datepickerpopup.php", {'hotelid' : '2', 'contentpage' : 1}, function(data){
				$('#loadpop').html(data);
				fn_display();	
			})
		})
		// display freedownloadpopup
		$('#freedownload').click(function(){
			$.get("http://www.gatwickhotelswithparking.com/incfiles/downloademail.php", function(data){
					$('#loadpop').html(data);
					fn_display();	
				})
				return false;
		})
		//this is to position and display the popup
		function fn_display(){
			
			var winheight = $(window).height();
			var popupheight = $('#popup').height();
			var positionx = (winheight - popupheight)/2
			var winwidth = $(window).width();
			var popupwidth = $('#popup').width();
			var positiony = (winwidth - popupwidth)/2;
			$('#backgroundimage').css({"display" : "block"});
			$('#popup').css({
				"display" : "block",
				"top" : positionx,
				"left" : positiony
			});
		}
		//$('.left-arrow').each(function(index){
		$('.left-arrow a').click(function(){
			//alert("text"+leftcol);
			var pos = $('#content1 .contentcolumninner').position();
			//alert(pos.left);
			$('#content1 .contentcolumninner').css({'position' : 'relative' , 'left' : (pos.left - leftcol - 200)+'px'})
		})
		$('.right-arrow a').click(function(){
			//alert("text"+leftcol);
			var pos = $('#content1 .contentcolumninner').position();
			//alert(pos.left);
			$('#content1 .contentcolumninner').css({'position' : 'relative' , 'left' : (pos.left + leftcol - 200)+'px'})
		})				
	//})	
	// This refines the search results
	$('.hotelrefine').change(function(){
			fn_hotelrefine();
		})	

		
			
		
 $('#selectclick').click(function(){
			$.get("incfiles/termspopup.php", function(data){
			//alert(data);
				$('#loadpop').html(data);
				fn_display();	
			})
			
		})
		/*function fn_display(){
			
			var winheight = $(window).height();
			var popupheight = $('#popup').height();
			var positionx = (winheight - popupheight)/2
			var winwidth = $(window).width();
			var popupwidth = $('#popup').width();
			var positiony = (winwidth - popupwidth)/2;
			$('#backgroundimage').css({"display" : "block"});
			$('#popup').css({
				"display" : "block",
				"top" : positionx,
				"left" : positiony
			});
		}
		$('#popup #close').click(function(){
			$('#backgroundimage').css({"display" : "none"});
			$('#popup').css({"display" : "none"});
		})*/
		$('.priceform').click(function(){
			dd1 = ($('#dd1').val() == undefined ? 0 : $('#dd1').val());
			dd2 = ($('#dd2').val() == undefined ? 0 : $('#dd2').val());
			dd4 = ($('#dd4').val() == undefined ? 0 : $('#dd4').val());
			dd8 = ($('#dd8').val() == undefined ? 0 : $('#dd8').val());
			dd16 = ($('#dd16').val() == undefined ? 0 : $('#dd16').val());
		    dd10 = ($('#dd10').val() == undefined ? 0 : $('#dd10').val());
		    dd11 = ($('#dd11').val() == undefined ? 0 : $('#dd11').val());
			dd32 = ($('#dd32').val() == undefined ? 0 : $('#dd32').val());
			dd64 = ($('#dd64').val() == undefined ? 0 : $('#dd64').val());
			total = Number(dd1)+Number(dd2)+Number(dd4)+Number(dd8)+Number(dd16)+Number(dd32)+Number(dd64)+Number(dd10)+Number(dd11);
			if (total == 0) {
				alert("Please select at least 1 room.");
				return false;
			}
		})
		$('.tabno').each(function(){
			$(this).click(function(){
				$('#tab1').css({'display' : 'none'})
				$('#tab2').css({'display' : 'none'})
				$('#tab3').css({'display' : 'none'})
				$('#'+$(this).attr("href")).css({'display' : 'block'})
				$('#tab1click').removeClass('tabselected');
				$('#tab2click').removeClass('tabselected');
				$('#tab3click').removeClass('tabselected');
				$('#'+$(this).attr("href")+'click').addClass('tabselected');
				return false;
			})
		})
})
 function fn_makecurrency(anumber){
    var changenumber = anumber.toString();
    var adddec = changenumber.indexOf(".");
    var numdecs =  changenumber.substring(adddec+1).length
    if (adddec == -1){
        return("£"+changenumber+".00");
    } else if (numdecs == 1){
        return("£"+changenumber+"0");
    } else {
        if (numdecs > 2){
            return("£"+changenumber.substring(0, (adddec+3)));
        } else {
            return("£"+changenumber);
        }
    }
}
function fn_hotelrefine(){
			unchecked = "";
			count = 0;
			$('.hotelrefine').each(function(){
				$('.'+$(this).val()).css({"display" : "block"})
				if($('#'+this.id +':checked').length == 0){
					unchecked = unchecked  + "," + $(this).val();
					count++;
				}
			})
			if(count != 0){
				unchecked = unchecked.substring(1);
				fn_showstuff(count, unchecked);
			}
		}
		
function fn_showstuff(var_number, var_list){
				var arrlist = var_list.split(',');
				for(x=0;x<=arrlist.length;x++){
					$('.'+arrlist[x]).css({'display' : 'none'})
				}
				// this is to add up the number of packages displaying
				fn_changenumberpackages();
				// this resizes the window.
				//fn_centerdivwidth();
			}
