function get_url() {
	selected_room = jQuery('.selected_room').attr('pagenum');
	size_code = jQuery('.selected_room').attr('room_code');
	room_title = jQuery('.selected_room').attr('room_title');
	weeks_free = jQuery('.stage_1_discounts .discount_selected').attr('weeks_free');
	weeks_pay = jQuery('.stage_1_discounts .discount_selected').attr('weeks_pay');
	start_date  = jQuery('#start_date').val();

	end_date = new Date.fromString(start_date);
	start_date_long = end_date.asString('d mmmm yyyy').toUpperCase();
	end_date_ongoing = new Date.fromString(start_date);
	end_date.addDays((weeks_free * 7) + (weeks_pay * 7) - 1);
	end_date_ongoing.addDays((weeks_free * 7) + (weeks_pay * 7));

	goprice = jQuery('#go_price').val();

	var limited = (jQuery('.items .price_current .limited_value').val() == "limited") ? "true" : "false";

	end_date_long = end_date.asString('d mmmm yyyy').toUpperCase();
	end_date_ongoing_long  = end_date_ongoing.asString('d mmmm yyyy').toUpperCase();

	end_date = end_date.asString('dd/mm/yyyy');
	end_date_ongoing = end_date_ongoing.asString('dd/mm/yyyy');

	first_discounts = jQuery('.stage_1_discounts .discount_selected').html();
	second_discounts = jQuery('.stage_2_discounts .discount_selected').html();
	discount = jQuery('.stage_2_discounts .discount_selected').attr('discount');
	
	room_code = jQuery('.selected_room').attr('room_code');

	return "selected_room=" + selected_room + "&weeks_free=" + weeks_free + "&limited=" + limited + "&weeks_pay=" + weeks_pay + "&discount=" + discount + "&start=" + start_date_long + "&ongoing=" + end_date_ongoing_long + "&end=" + end_date_long + "&location_string=" + jQuery("#location_string").val() + "&location=" + jQuery("#location_id").val() + "&go_price=" + goprice + "&room_code=" + room_code;
}

jQuery(function()
{
	jQuery("#progressbar").progressbar({ value: 0 });
	jQuery("#progressbar2").progressbar({ value: 0 }).hide();
 	jQuery(".print_quote_link").colorbox({width:"250px", inline:true, href:"#inline_popup_download", onLoad:function(){ 
	
	jQuery(document).everyTime(130, function(i) {
		jQuery("#progressbar").progressbar({ value: ((i + 1) * 1) });
	}, 200);

	jQuery(this).oneTime(16500, "hide", function() {
		jQuery.fn.colorbox.close();
	});
	
	window.location = "/print_pdf.php?" + get_url(); }});
		
	jQuery('.cbox_target').each(function(index) {
		//alert(index + ': ' + jQuery(this).text());
		jQuery("a[rel='" + jQuery(this).attr('attr-group') +  "']").colorbox();
	});
	
	jQuery('.cbox_target').click(function() {
		jQuery(this).parent().parent().find('div.active_image').prev().click();
		return false;
	})
	
	// initialise the "Select date" link
	jQuery('#dp-choose-date')
		.datePicker(
			// associate the link with a date picker
			{
				createButton:false,
				endDate:'31/12/2012'
			}
		).bind(
			// when the link is clicked display the date picker
			'click',
			function()
			{
				updateSelects(jQuery(this).dpGetSelected()[0]);
				jQuery(this).dpDisplay();
				change_dates();
				return false;
			}
		).bind(
			// when a date is selected update the SELECTs
			'dateSelected',
			function(e, selectedDate, jQuerytd, state)
			{
				updateSelects(selectedDate);
				jQuery('#start_date').val(jQuery('#d').val() + "/" + jQuery('#m').val() + "/" + jQuery('#y').val());
				change_dates();
			}
		).bind(
			'dpClosed',
			function(e, selected)
			{
				updateSelects(selected[0]);
				jQuery('#start_date').val(jQuery('#d').val() + "/" + jQuery('#m').val() + "/" + jQuery('#y').val())
				change_dates();
			}
		);
	jQuery('#d, #m, #y').change(function(){
		jQuery('#start_date').val(jQuery('#d').val() + "/" + jQuery('#m').val() + "/" + jQuery('#y').val())
		change_dates();
	})
	var updateSelects = function (selectedDate)
	{
		var selectedDate = new Date(selectedDate);
		var today = new Date();
		jQuery('#d option[value=' + selectedDate.getDate() + ']').attr('selected', 'selected');
		jQuery('#m option[value=' + (selectedDate.getMonth()+1) + ']').attr('selected', 'selected');
		jQuery('#y option[value=' + (selectedDate.getFullYear()) + ']').attr('selected', 'selected');
	}
	// listen for when the selects are changed and update the picker
	jQuery('#d, #m, #y')
		.bind(
			'change',
			function() {
				var d = new Date(
							jQuery('#y').val(),
							jQuery('#m').val()-1,
							jQuery('#d').val()
						);
				var today = new Date();
				if (today.getTime() > d.getTime() ) {
					d = today;
				}
				//change_prices();
				//jQuery('#dp-choose-date').dpSetSelected(d.asString());
			}
		);
	 init_questions('');
	if (jQuery('.session_date').length > 0) {
		session_date = Date.fromString(jQuery('.session_date').attr('attr-date'));
		jQuery('#start_date').val(session_date.asString('dd/mm/yyyy'));
		updateSelects(session_date);
		jQuery('#d').trigger('change');
		if (jQuery('.stage_1_discounts .discount_selected').length == 1) {
			jQuery('.moveindates, .ongoingdates').show()
			jQuery('.moveinalert').hide();
		}
	} else {
		var today = new Date();
		updateSelects(today.getTime());
		// and update the datePicker to reflect it...
		jQuery('#d').trigger('change');
	}
	jQuery(".email_quote_link").colorbox({width:"250px", inline:true, href:"#inline_popup", onCleanup:function(){ jQuery("#inline_popup").removeClass("sent"); }});
	jQuery("#send_quote").click(function() {
		jQuery(this).parent().append("<span class='sendingnow'>Sending, please wait</span>");
		jQuery('#email_quote_email').hide();
		jQuery(this).hide();
		jQuery("#progressbarogressbar2").progressbar({ value: 0 });
		jQuery("#progressbar2").show();
			jQuery(document).everyTime(130, function(i) {
				jQuery("#progressbar2").progressbar({ value: ((i + 1) * 1) });
			}, 200);
			jQuery.get("/email_quote.php?"+get_url()+"&email="+jQuery("#email_quote_email").val(), {}, function(data){
				jQuery("#send_quote").show();
				jQuery('#email_quote_email').show();
			    jQuery("#inline_popup").addClass("sent");
				jQuery("#progressbar2").hide();
				jQuery(".sendingnow").remove();
	   		});
		});
	});

/*This room is normally £37.99/wk.
5 weeks free saves you £189.95 making your rate £23.38/wk for 13 weeks   
 
Bottom section:
This room is normally £37.99/wk.
15% off makes your rate £32.29/wk
*/

//change the prices for the scrollable areas
function change_prices() {
	weeks_free = parseInt(jQuery('.stage_1_discounts .discount_selected').attr('weeks_free'));
	weeks_pay = parseInt(jQuery('.stage_1_discounts .discount_selected').attr('weeks_pay'));
	discount = jQuery('.stage_2_discounts .discount_selected').attr('discount');
	price = jQuery('.selected_room').attr('room_price');
	perc = ((1 - discount ) * 100).toFixed(0)
	weeks_total = weeks_free + weeks_pay;
	if (weeks_total == 0) {
		price_per_week = (Number(price)).toFixed(2);
	} else {
		price_per_week = ((price * weeks_pay ) / weeks_total).toFixed(2);
	}
	price_per_week_ongoing = (price * discount).toFixed(2);
	start_date  = jQuery('#start_date').val();
	end_date = new Date.fromString(start_date);
	start_date_long = end_date.asString('d mmmm yyyy');
	end_date_ongoing = new Date.fromString(start_date);
	end_date.addDays((weeks_free * 7) + (weeks_pay * 7) - 1);
	end_date_ongoing.addDays((weeks_free * 7) + (weeks_pay * 7));
	end_date_long = end_date.asString('d mmmm yyyy')
	end_date_ongoing_long  = end_date_ongoing.asString('d mmmm yyyy');
	end_date = end_date.asString('dd/mm/yyyy');
	end_date_ongoing = end_date_ongoing.asString('dd/mm/yyyy');
	saving = (price *  parseInt(weeks_free)).toFixed(2);
	jQuery(".price_save").html("Save &pound;" + saving);
	jQuery("#regular_rate").html("&pound;" + price);
	jQuery(".first_summary .price_start").html("&pound;" + price_per_week);
	jQuery(".second_summary .price_start").html("&pound;" + price_per_week_ongoing);
	question_info = "This room is normally &pound;" + price +"/wk<br />" + weeks_free + " weeks free saves you &pound;" + saving + "<br />making your rate &pound;" + price_per_week + "/wk for " + weeks_total +" weeks<br />from " + start_date_long + " to " + end_date_long; 
	jQuery('#info_first').attr('attr-info', question_info);
	info = "This room is normally &pound;" + price  +"/wk<br />" + perc + "% off makes your rate &pound;" + price_per_week_ongoing + "/wk<br />from " + end_date_ongoing + " onwards.";
	jQuery('#info_second').attr('attr-info', info);
	init_questions('.scrollable ');
	update_session();
	if (window.location.host == 'storagebase.com.dev:8888') {
		test_print_quote();
	}
}

function update_move_in_discounts() {
	site = jQuery('.selected_room').attr('site');
	room_code = jQuery('.selected_room').attr('room_code');
	if (room_code) {
		jQuery.ajax(
			{
				url: '/move_in_discounts.php?room_code=' + room_code + '&site=' + site,
				async: false,
				dataType: 'text',
				complete: function(jqXHR, textStatus) {
					jQuery('#move_in_discounts').html(jqXHR.responseText);
				}
			}
		);
		jQuery('.discount_box').click(function() {
			var box = jQuery(this);
			box.addClass('discount_selected').siblings('div').removeClass('discount_selected');
			box.find('input').attr('checked', true);
			if (jQuery('.discount_selected').length == 2) {
				jQuery('.off').removeClass('off');
			}
			if (jQuery('.stage_1_discounts .discount_selected').length == 1) {
				jQuery('.moveindates, .ongoingdates').show()
				jQuery('.moveinalert').hide();
			}
			init_questions('');
			change_prices();
			change_dates();
			update_session();
		});
	}
	
}

function test_print_quote() {
	jQuery('#test_print').html('test');
	jQuery('#test_print').attr('href', location.host + '/test_print_quote.php?' + get_url());
}

function update_session(room_id) {
	booking_date = jQuery('#start_date').val();
	booking_discount_1 = jQuery('.stage_1_discounts .discount_selected').attr('weeks_free');
	move_in_discount = jQuery('.stage_1_discounts .discount_selected').attr('move_in_discount');
	booking_discount_2 = jQuery('.stage_2_discounts .discount_selected').attr('weeks_pay');
	booking_room_index = jQuery('.selected_room').attr('pagenum');
	data = { booking_date: booking_date, booking_discount_1: booking_discount_1, booking_discount_2: booking_discount_2, booking_room_index: booking_room_index, move_in_discount: move_in_discount };
	if (room_id) {
		data['room_id'] = room_id;
	}
	jQuery.post("/booking/booking_vars.php", data);
}


function check_weeks() {
	start_date  = jQuery('#start_date').val();
	end_date = jQuery('#end-date').val();
	weeks_pay_stage_1 = jQuery('.stage_1_discounts .discount_selected').attr('weeks_pay');
	weeks_pay_stage_2 = jQuery('.stage_2_discounts .discount_selected').attr('weeks_pay');
	days = days_between(start_date, end_date);
	weeks = ((days + 1) / 7);
	if (weeks < weeks_pay_stage_1 || weeks < weeks_pay_stage_2) {
		return false;
	} else {
		return true;
	}
}

//update the pricing area for the booking
function change_dates() {
	//get the relevant data
	room_id = jQuery('.selected_room').parent().attr('room_id');
	size_code = jQuery('.selected_room').attr('room_code');
	room_title = jQuery('.selected_room').attr('room_title');
	weeks_free = jQuery('.stage_1_discounts .discount_selected').attr('weeks_free');
	weeks_pay = jQuery('.stage_1_discounts .discount_selected').attr('weeks_pay');
	if (typeof(weeks) == 'undefined') {
		weeks = 0;
		weeks = (parseInt(weeks_pay) + parseInt(weeks_free));
	}
	start_date  = jQuery('#start_date').val();
	end_date = new Date.fromString(start_date);
	start_date_long = end_date.asString('d mmmm yyyy').toUpperCase();
	end_date_ongoing = new Date.fromString(start_date);
	end_date.addDays((weeks_free * 7) + (weeks_pay * 7) - 1);
	end_date_ongoing.addDays((weeks_free * 7) + (weeks_pay * 7));
	end_date_long = end_date.asString('d mmmm yyyy').toUpperCase();
	end_date_ongoing_long  = end_date_ongoing.asString('d mmmm yyyy').toUpperCase();
	end_date = end_date.asString('dd/mm/yy');
	end_date_ongoing = end_date_ongoing.asString('dd/mm/yy');
	first_discounts = jQuery('.stage_1_discounts .discount_selected').html();
	second_discounts = jQuery('.stage_2_discounts .discount_selected').html();
	discount = jQuery('.stage_2_discounts .discount_selected').attr('discount');
	price = jQuery('.selected_room').attr('room_price');
	if (discount == "1") {
		jQuery('.perc_from').html('');
	} else {
		discount_string = Math.round((1 - discount) * 100)
	 	jQuery('.perc_from').html(discount_string + "% off ")
	}
	price_weekly = (price * weeks_pay / (parseInt(weeks_pay) + parseInt(weeks_free))).toFixed(2);
	weeks_weekly = (parseInt(weeks_pay) + parseInt(weeks_free));
	saving = ((price_weekly) *  parseInt(weeks_free)).toFixed(2);
	if (price_weekly == 0) {
		text = '<span class="save offer_details">Save &pound;' + (weeks_free * price).toFixed(2)+ "</span>";
	} else {
		text = "<span class='offer_details'>" + (parseInt(weeks_pay) + parseInt(weeks_free))+ ' wks for the price of ' + (parseInt(weeks_pay)) + '</span> <br /><span class="save">Save &pound;' + (weeks_free * price).toFixed(2) + "</span>";
	}
	if ('' == start_date) {
		return false;
	}
	initial_discount = (price * weeks_free).toFixed(2);
	jQuery('#var_discount_1').val(weeks_free + " weeks free");
	jQuery('#var_discount_2').val(second_discounts);
	jQuery('#var_room_size').val(room_title);
	jQuery('#var_room_code').val(size_code);
	jQuery('#var_room_type').val(size_code);
	output = "";
	output = output + "<div class='info_segment'><h3>Storage Room</h3>";
	output = output + "<p class='price_dates'>From: "+ start_date + "</p>";
	output = output + "<p><div class='room_title'>" + room_title + "</div><br /><p class='price_dates'>Normal rate: &pound;" + price + " / week</p></p>";
	zone_1 = room_title + "\nNormal rate: &pound;" +  price;
	output = output + "</div><div class='info_segment'><h3>Move In Discount</h3>";
	jQuery('.moveindates').html("FROM " + start_date_long + " TO "+ end_date_long );
	jQuery('.ongoingdates').html("FROM " + end_date_ongoing_long + " ONWARDS" );
	var total_weeks = (parseInt(weeks_pay) + parseInt(weeks_free));
	var price_dates = (total_weeks) ? start_date + " - " + end_date : '&nbsp;';
	output = output + "<p class='price_dates'>" + price_dates + "</p>";
	var move_in_discounts_available = find_move_in_discounts_available();
	if (total_weeks) {
		output = output + "<p class='discounts_zone'>" + first_discounts + "<br />" + text + "</p>";
	} else {
		var discounts_zone = (move_in_discounts_available == 1) ? 'No move in discount available' : 'No move in discount chosen';
		output = output + "<p class='discounts_zone'>" + discounts_zone + "</p>";
	}
	if (total_weeks) {
		zone_2 = "Move in discount: " + start_date + " - " + end_date + "\n" + first_discounts + "\n" + text;
	} else {
		zone_2 = "Move in discount: " + start_date + " - "+ end_date + "\n" + first_discounts;
	}
	jQuery('#top_date').html(" per week until " + end_date);
	jQuery('#bottom_date').html(" per week from " + end_date_ongoing);
	output = output + "</div><div class='info_segment'><h3>Ongoing Storage</h3>";
	output = output + "<p class='price_dates'>From: " + end_date_ongoing + "</p>";
	output = output + "<p class='discounts_zone'>" + second_discounts + "<br /><span class='offer_details'>" + "&pound;" + (price * discount).toFixed(2) + " per week</span></p>";
	zone_3 = "From: " + end_date_ongoing + "\n" + second_discounts + "\nDiscounted Rate: " + "&pound;" + (price * discount).toFixed(2) + " per week";
	output = output + "</div>";
	if (initial_discount == 0) {
		var discount_html = (move_in_discounts_available == 1) ? 'No move in discount available' : 'No move in discount chosen';
		jQuery('.first_summary span.price_start').addClass('no_discount');
		jQuery('.first_summary span.price_start').html(discount_html);
		jQuery('.first_summary span#top_date').html('&nbsp;');
		jQuery('.first_summary img').hide();
	} else {
		jQuery('.first_summary span.price_start').removeClass('no_discount');
		jQuery('.first_summary img').show();
	}
	jQuery('#var_zone_1').val(zone_1);
	jQuery('#var_zone_2').val(zone_2);
	jQuery('#var_zone_3').val(zone_3);
	jQuery('.booking_summary').html(output);
	update_session();
}

function find_move_in_discounts_available() {
	return parseInt(jQuery('#move_in_discounts_available').attr('move_in_discounts_available'));
}

function check_valid() {
	jQuery('.highlight').removeClass('highlight');
	jQuery('.error_message').hide();
	if (!jQuery('#tandc').is(':checked') && jQuery('#tandc').hasClass('required')) {
		jQuery('.tandctext').addClass('highlight');
		jQuery('.tandc_required').show();
	}
	jQuery('.panes div:visible').find('.required').each(function(index) {
		if (jQuery(this).val() == "") {
			jQuery(this).addClass('highlight');
			jQuery("." + jQuery(this).attr('name') + "_required").show();
		}
	});
	if (jQuery('.highlight:visible').length > 0) {
		return false;
	}
	return true;
}

jQuery(function() {
	//lets auto submit to google checkout form
	default_date = new Date();
	jQuery('.booking_summary').hide();
	jQuery('.booking_summary_list').hide();
	jQuery(".panes").children().hide();
	jQuery("#fragment-1").show();
	jQuery('.booking_submit').click(function () {
		order_type = jQuery(this).attr('id');
		jQuery('#var_order_type').val(order_type);
		if (check_valid() && jQuery('#var_waiting').val() != "1")  {
			jQuery.post("/booking/book.php", jQuery("#form_booking").serialize(), function(data){
				jQuery('.form_area').html(data);
				jQuery('#BB_BuyButtonForm').submit();
			});
			return false;
		}
		return check_valid();
	});
	jQuery(".pane_click").click(function () {
		if (jQuery(this).attr('trg') == "fragment-3") {
			if (!check_weeks()) {
				alert("You have not chosen enough weeks to cover the discounts selected, please change the discount or recheck the dates.");
				return false;
			}
			if (jQuery('.insurance_amount').val() != parseInt(jQuery('.insurance_amount').val()) || jQuery('.insurance_amount').val() < 0) {
				alert("Please enter a valid insurance amount, if your property has no value, please enter 0.");
				return false;
			}
		}
		if (jQuery(this).attr('trg') == "fragment-2") {
			var d = new Date(
				jQuery('#y').val(),
				jQuery('#m').val() - 1,
				jQuery('#d').val()
			);
			var today = new Date();
			if (today.getTime() > d.addDays(1).getTime() ) {
				alert('Please choose a date in the future');
				return false;
			}
			var available_from = jQuery("li.room_selected div.availability");
			var parts = available_from.html().split("/");
			if (typeof parts[1] != 'undefined') {
				var parts2 = parts[0].split(" ");
				var dcheck = new Date(parseInt(("20" + parts[2]),10), (parseInt(parts[1],10) - 1), parseInt(parts2[1],10));
				if (dcheck.getTime() > d.getTime() ) {
					alert('Please choose a date past the available from date. (' + parts2[1] + "/" + parts[1] + "/" + parts[2] +")");
					return false;
				}
			}
		}
		jQuery(".panes").children().hide();
		jQuery('#' + jQuery(this).attr('trg')).show();
		if (jQuery(this).attr('trg') == "fragment-1") {
			jQuery('.room_listt').show();
			jQuery('.booking_summary').hide();
			jQuery('.booking_summary_list').hide();
		} else {
			jQuery('.room_listt').hide();
			jQuery('.booking_summary').show();
			jQuery('.booking_summary_list').show();
		}
	});
	jQuery('.room_box_reserve').click(function () {
		available = jQuery('.selected_room').attr('available_rooms');
		if (available == "0") {
			jQuery('#tandc').removeClass('required');
			jQuery('.no_waiting').hide();
			jQuery('.waiting_list').show();
			jQuery('#var_waiting').val("1");
		} else {
			jQuery('#tandc').addClass('required');
			jQuery('.no_waiting').show();
			jQuery('.waiting_list').hide();
			jQuery('#var_room_code').val(size_code);
			jQuery('#var_waiting').val("0");
		}
		change_dates();
	});
	jQuery('.insurance_amount').keyup(function () {
		change_dates();
	})
	jQuery('.required').keyup(function () {
		if (jQuery(this).val() != "") {
			jQuery(this).removeClass('highlight');
		}
	});
	
	api = jQuery("div.scrollable").scrollable( {api:true, onSeek: function() { 
	//make the current column highlighted
			jQuery('div.scrollable div.price_column').removeClass("price_current");
			//extract the current room id
			room_id = jQuery('div.scrollable div.price_column:nth-child('+(this.getPageIndex() + 1)+')').attr('room_id');
			//get the url for finding data for this room
			room_url = jQuery('div.scrollable div.price_column:nth-child('+(this.getPageIndex() + 1)+')').attr('room_url');
			jQuery('div.scrollable div.price_column:nth-child('+(this.getPageIndex() + 1)+')').toggleClass("price_current");
		
			if (jQuery('.price_current').prevAll().size() == 1)
				jQuery('.prevPage').fadeOut();
			else
				jQuery('.prevPage').fadeIn();
				
			if (jQuery('.price_current').nextAll().size() == 0)
				jQuery('.nextPage').fadeOut();
			else
				jQuery('.nextPage').fadeIn();
			
			//jQuery('div.scrollable div.price_column:nth-child('+(this.getPageIndex() + 2)+')').fadeTo('fast', 1);
		    
			//change the classes after the current to have the modifier title css (so it aligns central correctly)
			jQuery('div.scrollable div.price_column').removeClass("after_current");
			jQuery('.price_current').nextAll().addClass('after_current');
			jQuery('.selected_room').removeClass('selected_room')
			jQuery('.price_current .room_box').addClass('selected_room');
			
			jQuery('div.scrollable div.price_column').removeClass("after_current_one");
			jQuery('.price_current').next().addClass('after_current_one');
			jQuery('div.scrollable div.price_column').removeClass("prev_current_one");
			jQuery('.price_current').prev().addClass('prev_current_one');
			//remove the previously selected room class
			jQuery('.rooms').removeClass('room_selected');
			//make the sidebar link selected
			jQuery('#room_link_'+room_id).addClass('room_selected');
			
		 	update_session();
			//.split(','); 
			
			//change_prices();
			update_move_in_discounts();
			jQuery('.discount_selected input').attr('checked',true);
			jQuery('.discount_selected input').click();
			change_dates();
			
			//get the data for the current room, h1 and content area
			jQuery.get('/data_pull.php?'+room_url, function(data) {
			  jQuery('.location_h1').html(data);
			title = document.title;//jQuery('title').html();
			title_parts = title.split("|");
			title_parts.pop();
			title = title_parts.join("|") + "| "  + data;
			document.title = title ;
			
			});
			jQuery.get('/data_pull.php?all=true&'+room_url, function(data) {
			  jQuery('.room_info_area').html(data);
			});
			
			
			
	    },	onBeforeSeek: function() { 
			//remove the class before seeking
					jQuery('div.scrollable div.price_column').removeClass("price_current");
			    }, size:1, steps:1, 

	    // another configuration variable as an example 
	    clickable: false 

	}); 
	
	//show/hide room info
	jQuery('.room_info_toggle').click(function () {
		jQuery('.room_info_area').toggle('fast');
	});
	//seek to the chosen page
	jQuery('.room_box, .price_header').click(function() {
	if (!jQuery(this).parent().hasClass('price_current'))
		api.setPage(jQuery(this).attr('pagenum'));
		
	});
	if (!jQuery('.room_selected').length)
		api.setPage(1);
	else {
		api.setPage(1);
		roomidclick =  jQuery('.room_selected').attr('offset');
		api.setPage(parseInt(roomidclick) + 1);
	}
	
	jQuery('.room_click').click(function() {
		update_session(jQuery(this).attr('room_id'));
		if (jQuery('.off').length > 0 ) {
			return false;
		}
		if (jQuery('div.scrollable').length > 0) {
			if ((jQuery('.items').children().size() - 1) <= jQuery(this).attr('offset')) {
				return false;
			}
			api.setPage(parseInt(jQuery(this).attr('offset')) + 1);	
			return false;
		} else {
			return true;
		}
	});
	
	if (jQuery('.discount_selected').length == 2)
	{
		jQuery('.off').removeClass('off');
	}
	
	//change_prices();
	
	jQuery('.nav_left, .nav_right').click(function() {
		target = jQuery(this).parent().parent().find('.image_' + jQuery(this).attr('attr-target'));
		update_image(target);		
		
	});
	
	jQuery('.small_image img').click(function() {
		update_image(jQuery(this));
	});
	

	
	
});

function update_image(image) {
	image.parent().parent().find('.primary_image img').attr('src',image.attr('src'));
	image.parent().parent().find('.primary_image a').attr('href',image.attr('src'));
	image.parent().parent().find('div').removeClass('active_image')
	image.parent().addClass('active_image');
	
	
	prev_nav =  get_prev_nav(image);
	next_nav = get_next_nav(image);
	
	next = get_next_image(image);
	prev = get_prev_image(image);
	if (next != "undefined" && next.hasClass('thumb_image')) {		
		next_nav.attr('attr-target', next.attr('attr-id'));
		next_nav.show();				
	} else {next_nav.hide();}
	
	if (prev != "undefined" && prev.hasClass('thumb_image')) {
		prev_nav.attr('attr-target', prev.attr('attr-id'));
		prev_nav.show();				
	} else {prev_nav.hide();}
}

function get_next_image(image) {
	return image.parent().next().find('img');
}

function get_prev_image(image) {
	return image.parent().prev().find('img');
}

function get_prev_nav(image) {
	return image.parent().parent().find('.nav_left');
}

function get_next_nav(image) {
	return image.parent().parent().find('.nav_right');
}

