﻿/* GLOBAL VARIABLES
 **/
var CONFIG_BASE = "/Content/Assets/Config/";
var SFW_BASE = "/Content/Assets/Swfs/";

/* Updates the price of the package.
 **/
function UpdatePrice(sender, price) {

    var current = parseFloat($("#price").text());

    if ($(sender).is(":checked")) {
        var n = current + price;
        $("#price").text(n.toFixed(2));
    } else {
        var n = current - price;
        $("#price").text(n.toFixed(2));
    }
}

/* Gets the selected paraters and refreshes the page with the new results.
 **/
function MakeTFRequest() {
    var SelectedCountry = $("#SelectedCountry :selected").val() != null && $("#SelectedCountry :selected").val() != "" ? $("#SelectedCountry :selected").val() : -1;
    var SelectedBudget = $("#SelectedBudget :selected").val() != null && $("#SelectedBudget :selected").val() != "" ? $("#SelectedBudget :selected").val() : -1;
    var SelectedCategory = $("#SelectedCategory :selected").val() != null && $("#SelectedCategory :selected").val() != "" ? $("#SelectedCategory :selected").val() : -1;

    window.location = "/Home.mvc/TripFinder/?idx=1&ctr=" + SelectedCountry + "&bdg=" + SelectedBudget + "&ct=" + SelectedCategory;
}

/* Renders the Carousel in the Home page.
 **/
function RenderHomeCarousel() {
    var flashvars = {};
    flashvars.configPath = CONFIG_BASE + "slideshow/config.xml";
    var params = {};
    var attributes = {};
    attributes.id = "slideShow";
    swfobject.embedSWF(SFW_BASE + "FTSlideShow.swf", "carouselContainer", "644", "348", "9.0.0", false, flashvars, params, attributes);
}

/* Renders the Menu in every page.
 * TODO: Add the selected menu item.
 **/
function RenderMenu() {
    var flashvars = {};
    flashvars.configPath = CONFIG_BASE + "menu/config.xml";
    var params = {};
    var attributes = {};
    attributes.id = "mainMenu";
    swfobject.embedSWF(SFW_BASE + "FTMainMenu.swf", "menuContainer", "520", "49", "9.0.0", false, flashvars, params, attributes);
}

function RenderFooter() {
    var flashvars = {};
    flashvars.configPath = CONFIG_BASE + "footer/config.xml";
    var params = {};
    var attributes = {};
    attributes.id = "mainMenu";
    swfobject.embedSWF(SFW_BASE + "FTMainMenu.swf", "footer", "120", "49", "9.0.0", false, flashvars, params, attributes);
}

/* Renders the Destination Gallery
 **/
function RenderDestinationGallery(config) {
    var flashvars = {};
    flashvars.configPath = config;
    var params = {};
    var attributes = {};
    attributes.id = "findThePerfectTrip";
    swfobject.embedSWF(SFW_BASE + "FTFindThePerfectTrip.swf", "galleryContainer", "644", "348", "9.0.0", false, flashvars, params, attributes);
}

/* Generates a config path for a country code
 **/
function GetDestinationConfig(country) {
    return CONFIG_BASE + "destinations/" + country + ".xml";
}

/* Shows pop up with service description
 **/
function ShowDestinationPop(el, imgID, title, desc) {
    var content = "<table class=\"dialog\"><tr><td style=\"vertical-align:top;width:133px;\"><img height=\"128\" width=\"128\" alt=\"" + title + "\" src=\"" + imgID + "\" /></td><td><h3>" + title + "</h3><p>" + desc + "</p></td></tr></table>";
    
    $("#destinationPop").find(".popContent").html(content);

    var os = $(el).offset();
    var lt = os.left + ($(el).width());
    var tp = os.top - ($("#destinationPop").height() / 2);
    
    $("#destinationPop").css("left", lt).css("top", tp);
    $("#destinationPop").show();
}

/* Hides pop up.
 **/
function HideDestinationPop() {
    $("#destinationPop").hide();
}
