$(document).ready(function(){

$(".clickdesc").each(function(intIndex){
    //$(".description"+intIndex).css({'visibility' : 'hidden'});
    $(this).bind("click", function (){
        
        whichhotel = $(".hotelclick"+intIndex).attr("href");
        whichhotel = whichhotel.substring(whichhotel.indexOf("=")+1);
        //alert(whichhotel);
        $(".description"+intIndex).load("hotelinformationpanel.php?hotel="+whichhotel);
        //$(".description"+intIndex).css({'height' : '500px'});
        return false;
    })
})

/*$(".clickdesc1 a").click(function(){
    testme = $(".description1");
    alert(testme);
   testme.css({'visibility' : 'visible'});
    return false;
})
$(".description1").ready(function(){
     $(".description1").css({'visibility' : 'hidden'});
})*/
$(".checkavail .datemonth select").change(function(){
    whichmonth = $(this).val();

    whichmonth = whichmonth.substring(0,whichmonth.indexOf("-"));
    day = $(".datechange select").val();
    alert ($(this + ".datechange select").val());
  //alert((whichmonth));
    $(".datechange").load("includes/dates.php?month="+whichmonth+"&day="+day);
})
var request = $(".cal");
request.click(function(){
    info = $(this).val();
    //alert(info);
    $.post("bookout.php", { bookout: info }, 
        function(success){
            location.reload()
        }
    );
    
})
/*$(".cal checkbox").change(function (){
    alert("hello");
    info = $(this).attr("href");
    //$(".bookout")
    info = info.substring(info.indexOf("?")+1, info.indexOf("&"))
    testme = info.substring(info.indexOf("-")+1);
    testme = testme.substring(testme.indexOf("-")+1, testme.lastIndexOf("-"));
    alert(info)
     $.post("bookout.php", { bookout: info } );
     $(".col"+testme).css({'background-color' : '#f00'});
   // return false;
})*/

$("#calendar select").change( function() {
  // check input ($(this).val()) for validity here
  info = this.id;
  quantity = $(this).val();
  alert(info);
	 $.post("roomupdate.php", { room: info, changequanity: quantity } );
	 $(this).css({'background-color' : '#0f0'});
});

	$("#calendar input[type='text']").change( function() {
  // check input ($(this).val()) for validity here
  info = this.id;
  quantity = $(this).val();
  //alert(info);
	 $.post("priceupdate.php", { roomtype: info, changeprice: quantity } );
	 $(this).css({'background-color' : '#0f0'});
});

/*
$(".hotelarray").mouseout(function(){
	$(this).children('.hotelmain').css({
			'visibility': 'visible', 'position': 'relative'
		});
		$(this).children('.hotelrollover').css({
			'visibility': 'hidden', 'position': 'absolute'
		});
})	
$(".hotelarray").mouseover(function(){
	$(this).children('.hotelmain').css({
			'visibility': 'hidden', 'position': 'absolute'
		});
		$(this).children('.hotelrollover').css({
			'visibility': 'visible', 'position': 'relative'
		});
})


$("div.hotelrollover").mouseleave(function(){
	//$(this).css({'visibility' : 'hidden'});
	//$('.hotelmain').css({'visibility' : 'visible'});
})
*/
$(".showmore").click(function(){
	 if ($(".morehotelsdiv").is(":hidden")){
	 	$(".showmore span").replaceWith("<span>&raquo; less gatwick hotels...</span>");
		$(".morehotelsdiv").animate({"height":"150px", "opacity": "toggle"},{ duration: "slow" });
			
	 } else {
	 	//$(".morehotelsdiv").slideUp("slow");
		$(".showmore span").replaceWith("<span>&raquo; more gatwick hotels...</span>");
		$(".morehotelsdiv").animate({"height":"0px", "opacity": "toggle"},{ duration: "slow" });
	 }
	 return false;
	 	
})

 //var $div = ;
var $morerev1 = $('.morereview1')
var height1 = $morerev1.height(); 
$morerev1.hide().css({ height : 0 }); 
$("a.review1").click(function(){
	if ($morerev1.is(":visible")){
		$(".review1 span").replaceWith("<span>&raquo; Read More Reviews...</span>");
		$(".morereview1").animate({"height":0}, { duration: 400, complete:function (){
		$morerev1.hide();
		}});
	} else {
		$(".review1 span").replaceWith("<span><br>&raquo; Close Reviews</span>");
		$(".morereview1").animate({"height":height1}, 400);
		$morerev1.show();
	}
	return false;	 	
})
var $morerev2 = $('.morereview2')
var height2 = $morerev2.height(); 
$morerev2.hide().css({ height : 0 }); 
$("a.review2").click(function(){
	if ($morerev2.is(":visible")){
		$(".review2 span").replaceWith("<span>&raquo; Read More Reviews...</span>");
		$(".morereview2").animate({"height":0}, { duration: 400, complete:function (){
		$morerev2.hide();
		}});
	} else {
		$(".review2 span").replaceWith("<span><br>&raquo; Close Reviews</span>");
		$(".morereview2").animate({"height":height2}, 400);
		$morerev2.show();
	}
	return false;	 	
})
var $morerev3 = $('.morereview3')
var height3 = $morerev3.height(); 
$morerev3.hide().css({ height : 0 }); 
$("a.review3").click(function(){
	if ($morerev3.is(":visible")){
		$(".review3 span").replaceWith("<span>&raquo; Read More Reviews...</span>");
		$(".morereview3").animate({"height":0}, { duration: 400, complete:function (){
		$morerev3.hide();
		}});
	} else {
		$(".review3 span").replaceWith("<span><br>&raquo; Close Reviews</span>");
		$(".morereview3").animate({"height":height3}, 400);
		$morerev3.show();
	}
	return false;	 	
})
var $booknow = $('.booknowdiv')
//var theFrame = $("#bookingiframe", parent.document.body);
//theFrame.height($(document.body).height() + 40);
var bookheight = $booknow.height(); 
$booknow.hide().css({ height : 0 }); 
$("a.booknow").click(function(){
    var theFrame = $(".bookingiframe", parent.document.body);
	if ($booknow.is(":visible")){
		//$(".review2 span").replaceWith("<span>&raquo; Read More Reviews...</span>");
                //theFrame.height($(document.body).height() + 40 - bookheight);
                
		$(".booknowdiv").animate({"height":0}, { duration: 400, complete:function (){
		$booknow.hide();
                $(".bookingiframe", parent.document.body).animate({"height":theFrame.height($(document.body).height() + 40)}, 400);
		}});
                
	} else {
		//$(".review2 span").replaceWith("<span><br>&raquo; Close Reviews</span>");
                //theFrame.height($(document.body).height() + 40 + bookheight);
                
		$(".booknowdiv").animate({"height":bookheight}, 400);
                $(".bookingiframe", parent.document.body).animate({"height":theFrame.height($(document.body).height() + 40 + bookheight)}, 400);
		$booknow.show();
	}
	return false;	 	
})

$('.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;
	}
})

$('.check1').click(function(){
	var_val = $('.form1 .showdate').val();
	if (var_val == "Please enter a date"){
		alert("You must enter a date before you can proceed.");
		return false;

	}
})
$('.check2').click(function(){
	var_val = $('.form2 .showdate').val();
	if (var_val == "Please enter a date"){
		alert("You must enter a date before you can proceed.");
		return false;

	}
})
$('.check3').click(function(){
	var_val = $('.form3 .showdate').val();
	if (var_val == "Please enter a date"){
		alert("You must enter a date before you can proceed.");
		return false;

	}
})
$('.check4').click(function(){
	var_val = $('.form4 .showdate').val();
	if (var_val == "Please enter a date"){
		alert("You must enter a date before you can proceed.");
		return false;

	}
})
/*# $( "#girls a.hottie" ).each(
#  
# // For each hottie, run this code. The "indIndex" is the
# // loop iteration index on the current element.
# function( intIndex ){
#  
# // Bind the onclick event to simply alert the
# // iteration index value.
# $( this ).bind (
# "click",
# function(){
# alert( "Hottie index: " + intIndex );
# }
# );
#  
# }
#  
# );*/
//$(".infonav1  a.infonavli").each(function(intIndex){

function movedesc (var_load, var_move){
    //this gets the number out to change the correct div
    var_changediv = var_move.substring(4,5);
    //this loads the correct data into the correct div
    $("#changediv"+var_move.substring(4,5)).css({"display":"block"});
    $("#changediv"+var_changediv).load(var_load);
    //this scrolls through to
    $("#descnav"+var_changediv+"  li span").each(function(intIndex){
        idlist = this.id;
        $("#"+idlist + " a").css({"background-position":"0 0px"});
    })
    $(var_move + " a").css({"background-position":"0 -30px"});
}
$(".descnav  a").each(function(intIndex){
    $("#changediv"+this.id.substring(3,4)).css({"display":"none"});
    $(this).bind("click", function (){
            //alert("hello" + intIndex);
            //this gets the id that has been clicked on
            thisid = this.id;
            //get the href of the button clicked;
            var_sendinfo = $("#"+thisid+"s a").attr("href");
            //send all this info to the function to do its stuff
            movedesc(var_sendinfo, '#'+thisid+'s');
            return false;
        //})
    })
}
);
function movestuff (var_load, var_move){
    //this gets the number out to change the correct div
    var_changediv = var_move.substring(4,5);
    //this loads the correct data into the correct div
    $("#changediv"+var_changediv).load(var_load);
    //this scrolls through to
    $("#infonav"+var_changediv+"  li span").each(function(intIndex){
        idlist = this.id;
        $("#"+idlist + " a").css({"background-position":"0 0px"});
    })
    $(var_move + " a").css({"background-position":"0 -30px"});
}
$(".infonav  a").each(function(intIndex){
    $(this).bind("click", function (){
        //alert("hello" + intIndex);
            //this gets the id that has been clicked on
            thisid = this.id;
            //get the href of the button clicked;
            var_sendinfo = $("#"+thisid+"s a").attr("href");
            //send all this info to the function to do its stuff
            movestuff(var_sendinfo, '#'+thisid+'s');
            return false;
        //})
    })
}
);
$("#rev11s a").css({"background-position":"0 -30px"});
$("#rev21s a").css({"background-position":"0 -30px"});
$("#rev31s a").css({"background-position":"0 -30px"});
$("#rev41s a").css({"background-position":"0 -30px"});

var theFrame = $(".bookingiframe", parent.document.body);
theFrame.height($(document.body).height() + 40);
})


