// JavaScript Document
// Author: Jay Darnell
// Date: December 10, 2008

function initRatings() {
	
	// determine park name for XML lookup to get ratings
	var theParkLabel = location.href.substr(location.href.indexOf("parks/")+6);
	parklabel = theParkLabel.substr(0, theParkLabel.indexOf(".htm")).toLowerCase();
	var newhtml = "";
	var netroomzid = null;
	var parkname = null;
	var bookings_phone = null;
	// Open XML file
	$.get("/xml/top10parks.xml", function(xml) {
		// Find the appropriate park node
		$(xml).find("park").each(function() {
			if ($(this).find("lookup").text() == parklabel) {
				if ($(this).find("rating").text().length) {
					newhtml += '<img src="../parks/qualmarks/' + $(this).find("rating").text() + '_big.jpg" /> ';
				}
				if ($(this).find('greenrating').text().length) {
					newhtml += '<img src="../parks/qualmarks/' + $(this).find("greenrating").text() + '.jpg" /> ';
				}
				if ($(this).find('rating2').text().length) {
					newhtml += '<img src="../parks/qualmarks/' + $(this).find("rating2").text() + '_big.jpg" /> ';
				}
				// get netroomz hotelid if present
				if ($(this).find('netroomzid').text().length && $(this).find('netroomzid').text() != "0") {
					netroomzid = $(this).find('netroomzid').text();
					parkname = $(this).find('name').text();
					// bookings_phone = $(this).find('reservations').text();
					if ($('form#bookingform').length > 0) {	// new booking control exists
						$('input#hid').val(netroomzid);
						$('input#parkname').val(parkname);
						// $('#booking-number').text(bookings_phone);
					}
				}
				else { // no netroomz id for the current park page - so hide the netroomz control
					$('form#bookingform').hide();
				}
				return false; // stop searching
			}
			return true;

		});
			
		$("#ratings").html(newhtml);
		
		if (!netroomzid) { // no netroomz id for the current park page - so hide the netroomz control
			$('form#bookingform').hide();
		}
	});										
	
	
}

$(document).ready(function() {
	initRatings();
});