﻿jQuery(function ($) {
	$.fn.quicksearch = function (opt) {
		
		function fix_widths(el)
		{
			$(el).find('td').each(function () {
				$(this).attr('width', parseInt($(this).css('width')));
			});
		}
	}; 
	
});

// set up the variables we will need later ...
var compNumber = 0;
var hiddenFilters = true;

$(document).ready(function() {


    var locationValue = $('input.hfDefaultLocation').val();

    //append class idleField to seperate log in form to allow value swap to work
    $('.input-wrap input, .delegates-wrap input').addClass('idleField');
    
    //swap values of inputs dependant on focus and blur
    $.each($('input.idleField'), function() {
        $(this).data('initial',$(this).val());
    });
    
    $('input.idleField').focus(function() {
        if($(this).val() == locationValue){
            $(this).val('');
        }else{
            $(this).removeClass('idleField');
            if($(this).val() == $(this).data('initial')) {
                return false;
            }
        }
    })
    
    .blur(function() {
        //Bug 487 - If the user clears the box in order to search for all hotels, do not 
        //readd the old search criteria
        //if($(this).val() == '') {
        //   $(this).val($(this).data('initial'));
        //}
    }); 

    


			$(function() {
				var zIndexNumber = 1000;
				$('tr').each(function() {
					$(this).css('zIndex', zIndexNumber);
					zIndexNumber -= 10;
				});
			});
			
            //init iphone switches
			$('.on_off :checkbox').iphoneStyle(); 
            //init compare slider
			$('#slider').easySlider();
			

			$('.hotelHolder .on_off input:checkbox').change(function(){
				if ($(this).is(':checked')){
					hotelID = $(this).attr('id');
					hotelname = $(this).parents('.hotelTop').children('h3').html();
					compHot = '<div class="name" id="hotel_' + hotelID + '" >' + hotelname + '</div>';		

					$.get("../../services/hotels.ashx", {hotelId: $(this).attr('id'), facilities : 1},
					  function(data){
					    var xml;
						if ($.browser.msie && typeof data == "string") {
							xml = new ActiveXObject("Microsoft.XMLDOM");
							xml.async = false;
							xml.loadXML(data);          
						} else {
							xml = data;
						}				
						
						hotelprice = '<div class="ticks" id="price_' + hotelID + '" >' + $(xml).find('pricexml').text() + '</div>';
						
						if($(xml).find('internetxml').text() == 'True'){
							internet = '<div class="ticks" id="internet_' + hotelID + '" ><img src="../../images/tick.gif"></div>';
						}else{
							internet = '<div class="ticks" id="internet_' + hotelID + '" ></div>';
						}	
						if($(xml).find('parkingxml').text() == 'True') {
							parking = '<div class="ticks" id="parking_' + hotelID + '" ><img src="../../images/tick.gif"></div>';
						}else{
							parking = '<div class="ticks" id="parking_' + hotelID + '" ></div>';
						}
						if ($(xml).find('accessablexml').text() == 'True'){
							accessable = '<div class="ticks" id="accessable_' + hotelID + '" ><img src="../../images/tick.gif"></div>';
						}else{
							accessable = '<div class="ticks" id="accessable_' + hotelID + '" ></div>';
						}
						if ($(xml).find('railwayxml').text() == 'True'){
							railway = '<div class="ticks" id="railway_'+ hotelID +'" ><img src="../../images/tick.gif"></div>';
						}else{
							railway = '<div class="ticks" id="railway_' + hotelID + '" ></div>';
						}
						if ($(xml).find('airportxml').text() == 'True'){
							airport = '<div class="ticks" id="airport_' + hotelID + '" ><img src="../../images/tick.gif"></div>';
						}else{
							airport = '<div class="ticks" id="airport_' + hotelID + '" ></div>';
						}
						if ($(xml).find('motorwayxml').text() == 'True'){
							motorway = '<div class="ticks" id="motorway_' + hotelID + '" ><img src="../../images/tick.gif"></div>';
						}else{
							motorway = '<div class="ticks" id="motorway_' + hotelID + '" ></div>';
						}
						if ($(xml).find('daylightxml').text() == 'True'){
							daylight = '<div class="ticks" id="daylight_' + hotelID + '" ><img src="../../images/tick.gif"></div>';
						}else{
							daylight = '<div class="ticks" id="daylight_' + hotelID + '" ></div>';
						}
						if ($(xml).find('urbanxml').text() == 'True'){
							urban = '<div class="ticks" id="urban_' + hotelID + '" ><img src="../../images/tick.gif"></div>';
						}else{
							urban = '<div class="ticks" id="urban_' + hotelID + '" ></div>';
						}
						if ($(xml).find('ruralxml').text() == 'True'){
							rural = '<div class="ticks" id="rural_' + hotelID + '" ><img src="../../images/tick.gif"></div>';
						}else{
							rural = '<div class="ticks" id="rural_' + hotelID + '" ></div>';
						}
						if ($(xml).find('poolxml').text() == 'True'){
							pool = '<div class="ticks" id="pool_' + hotelID + '" ><img src="../../images/tick.gif"></div>';
						}else{
							pool = '<div class="ticks" id="pool_' + hotelID + '" ></div>';
						}
						if ($(xml).find('golfxml').text() == 'True'){
							golf = '<div class="ticks" id="golf_' + hotelID + '" ><img src="../../images/tick.gif"></div>';
						}else{
							golf = '<div class="ticks" id="golf_' + hotelID + '" ></div>';
						}
						if ($(xml).find('gymxml').text() == 'True'){
							gym = '<div class="ticks" id="gym_' + hotelID + '" ><img src="../../images/tick.gif"></div>';
						}else{
							gym = '<div class="ticks" id="gym_' + hotelID + '" ></div>';
						}
						if ($(xml).find('spaxml').text() == 'True'){
							spa = '<div class="ticks" id="spa_' + hotelID + '" ><img src="../../images/tick.gif"></div>';
						}else{
							spa = '<div class="ticks" id="spa_' + hotelID + '" ></div>';
						}
						if ($(xml).find('restaurantxml').text() == 'True'){
							restaurant = '<div class="ticks" id="restaurant_' + hotelID + '" ><img src="../../images/tick.gif"></div>';
						}else{
							restaurant = '<div class="ticks" id="restaurant_' + hotelID + '" ></div>';
						}
						if ($(xml).find('barxml').text() == 'True'){
							bar = '<div class="ticks" id="bar_' + hotelID + '" ><img src="../../images/tick.gif"></div>';
						}else{
							bar = '<div class="ticks" id="bar_' + hotelID + '" ></div>';
						}
						if ($(xml).find('businessxml').text() == 'True'){
							business = '<div class="ticks" id="business_' + hotelID + '" ><img src="../../images/tick.gif"></div>';
						}else{
							business = '<div class="ticks" id="business_' + hotelID + '" ></div>';
						}
						$('#hotName').append(compHot);
						$('#price').append(hotelprice);
						$('#internetC').append(internet);
						$('#parkingC').append(parking);
						$('#accessableC').append(accessable);
						$('#railwayC').append(railway);
						$('#airportC').append(airport);
						$('#motorwayC').append(motorway);
						$('#daylightC').append(daylight);
						$('#urbanC').append(urban);
						$('#ruralC').append(rural);
						$('#poolC').append(pool);
						$('#golfC').append(golf);
						$('#gymC').append(gym);
						$('#spaC').append(spa);
						$('#restaurantC').append(restaurant);
						$('#barC').append(bar);
						$('#businessC').append(business);
					}); 
	
					compNumber++ ;
					$('.compNo').html('(' + compNumber + ')');
				
				}else{
				
					compNumber-- ;
					$('.compNo').html('(' + compNumber + ')');
					var remID = '#hotel_' + $(this).attr('id');
					var remPrice = '#price_' + $(this).attr('id');
					var remInternet = '#internet_' + $(this).attr('id');
					var remParking = '#parking_' + $(this).attr('id');
					var remAccessable = '#accessable_' + $(this).attr('id');
					var remRailway = '#railway_' + $(this).attr('id');
					var remAirport = '#airport_' + $(this).attr('id');
					var remMotorway = '#motorway_' + $(this).attr('id');
					var remDaylight = '#daylight_' + $(this).attr('id');
					var remUrban = '#urban_' + $(this).attr('id');
					var remRural = '#rural_' + $(this).attr('id');
					var remPool = '#pool_' + $(this).attr('id');
					var remGolf = '#golf_' + $(this).attr('id');
					var remGym = '#gym_' + $(this).attr('id');
					var remSpa = '#spa_' + $(this).attr('id');
					var remRestaurant = '#restaurant_' + $(this).attr('id');
					var remBar = '#bar_' + $(this).attr('id');
					var remBusiness = '#business_' + $(this).attr('id');
					
					
					$(remID).remove();
					$(remPrice).remove();
					$(remInternet).remove();
					$(remParking).remove();
					$(remAccessable).remove();
					$(remRailway).remove();
					$(remAirport).remove();
					$(remMotorway).remove();
					$(remDaylight).remove();
					$(remUrban).remove();
					$(remRural).remove();
					$(remPool).remove();
					$(remGolf).remove();
					$(remGym).remove();
					$(remSpa).remove();
					$(remRestaurant).remove();
					$(remBar).remove();
					$(remBusiness).remove();
				}
				
				$(this).blur();
			});				
			
        //filter code
		
		$('.openFilters').click(function (){
				$(this).hide();
				$(this).next().show('fast');
				$('#hiddenFilters').slideToggle('fast');
				hiddenFilters = false;
		}); 
		$('.closeFilters').click(function (){
				$(this).hide();
				$(this).prev().show('fast');
				$('#hiddenFilters').slideToggle('fast');
				hiddenFilters = true;
		});
			
		$('#hiddenFilters').slideToggle('fast');	
		

		}
			
			
			
);

			
