
$(document).ready(function () {
$("#fares-summary").hide();
$("th.destination, th.fare").toggle(function () {
$(this).removeClass("down").addClass("up");
},
function () {
$(this).removeClass("up").addClass("down");
});

var retVar = "<td colspan='4'><div style='text-align:center; padding:10px;'><h3>" + txtPleaseWait + "</h3></div></td>";
$("<tr></tr>").html(retVar).appendTo("#fares-summary table tbody").slideDown(500);
getData();
resetSession();
tableStyle();


var code = $("#dCode").val();
$("#bannerImage").error(function() {
$("#bannerImage").attr("src","/cms/global/assets/images/local/lpbm/page_banners/lpbm_view_destinations_LON.jpg");
$("#imageHRef").attr("href","/main/holidays-in-london");
});
$("#bannerImage").attr("src","/cms/global/assets/images/local/lpbm/page_banners/lpbm_view_destinations_" + code + ".jpg");

});
function imageDidNotLoad()
{
alert("!!");
}
function tableStyle() {
$("#fares-summary table thead th:first").css("border-left-width", "0px");
$("#fares-summary table tbody tr td:first-child").css("border-left", "0px");
$("#fares-summary table tbody tr td:last-child").css("border-right", "0px");
$("#fares-summary table tbody tr td:has(div.button)").css("border-left", "0px");

$("#fares").tablesorter();
}
function displayErrMsg() {
$("#fares-summary").slideUp(500, function () {

var retVar = "<div style='text-align:center; padding:10px;'><h3 style='color:#DD0000;'>" + txtSystemsNotResponding + "</h3></div>";
$(this).html(retVar).slideDown(500);
});
}
function getData() {
var returnValue = "";

var urlData = "";

var lpfURL = "/main/low-price-finder/itemid-zzall/?eId=113021";
var fxURL = "/main/fx?eId=111009";
$.ajax({
type: "GET",
cache: true,
dataType: "json",
url: serviceUrl,
data: urlData,
async: false,
complete: function () {
$("#fares-summary").slideDown(500);
},
error: function (XMLHttpRequest, textStatus) {
displayErrMsg();
},

success: function (data, status) {
if (status == "success") {

$("#fares-summary table tbody").empty();

$.each(data.Cache, function (j, item) {
var currency = item.Response.CurrencySymbol;
var from = item.Response.From;
var fromDisplay = item.Response.FromDisplay;
var to = item.Response.To;
var cabin = item.Response.CabinDisplay;
var destDisplay = item.Response.ToDisplay;

$("#imageHRef").attr("href","/main/holidays-in-"+destDisplay.replace(" " ,"-").toLowerCase());
var minPrice = 999999;
var travelClass = item.Response.CabinCode;
var price, dateDisplay, lpfData, fxData, itemLpfURL, itemFxURL, depDate, retDate, arrivalAirport, arrivalAirportDisplay;
returnValue = "";
$.each(item.Response.FareData.Fare, function (i, item) {
if (parseFloat(item.Amount) < minPrice) {
minPrice = parseFloat(item.Amount);
price = parseFloat(item.Amount);
dateDisplay = item.DateDisplay;
if (country == "us") {
depDate = item.FXUSDepartureDate;
retDate = item.FXUSReturnDate;
} else {
depDate = item.FXDepartureDate;
retDate = item.FXReturnDate;
}
arrivalAirportDisplay = item.ArrivalAirportDisplay;
arrivalAirport = item.ArrivalAirport;
}
});
lpfData = "&amp;origin=" + from + "&amp;destination=" + to + "&amp;cabin=" + travelClass + "&amp;source=LowPriceFinderList" + onewayClause;

fxData = "&amp;from=" + from + "&amp;to=" + arrivalAirport + "&amp;depDate=" + depDate + "&amp;cabin=" + travelClass + "&amp;ad=1&amp;restrictionType=LOWEST&amp;source=LowPriceFinderList";
if (onewayClause == "") {
fxData += "&amp;retDate=" + retDate;
}
itemLpfURL = lpfURL + lpfData;
itemFxURL = lpfURL + lpfData;
if (price != undefined) {
returnValue = "<td style='border-left: 0px none;' class='destination' id='destination-1'><a href='" + itemLpfURL + "' class='city'>" + fromDisplay + "</a><br>" + txtToDestination + " " + arrivalAirportDisplay + "</td>";
returnValue += "<td class='fare' id='fare-1'><a href='" + itemFxURL + "'>" + currency + price + "<span class='type'>&nbsp;" + waynessTxt + "</span></a>";

returnValue += "<td style='border-left: 0px none;' id='button-1'><div class='button primary'><a href='" + itemFxURL + "' class='arrow'>" + txtFindThisPrice + "</a></div></td>";
returnValue += "<td style='border-right: 0px none;' class='graph' id='graph-1'><a href='" + itemLpfURL + "' class='tertiaryLink'>" + txtShowAllMonths + "</a></td>";



if ($("#" + from).length > 0) {
$("#" + from).html(returnValue);
} else {
$("<tr id=" + from + "></tr>").html(returnValue).appendTo("#fares-summary table tbody");
}
} else {

}
});
} else {
displayErrMsg();
}
}
});
return false;
}
function resetSession() {
var resetUrl = "/main/low-price-finder/itemid-zzall/?eId=113001";

$.ajax({
type: "GET",
cache: true,
async: false,
url: resetUrl,
success: function (xml, status) {}
});
}
