var Australia = {};
Australia._currentSection = '';
Australia.CurrentSection = function() {
    if (Australia._currentSection != '')
        return Australia._currentSection;

    //look in url for current section
    var urltest = document.location.toString().toLowerCase();
    if (urltest.indexOf('cities') > -1)
        Australia._currentSection = 'cities';
    else if (urltest.indexOf('coastal') > -1)
        Australia._currentSection = 'coastal';
    else if (urltest.indexOf('food_wine') > -1)
        Australia._currentSection = 'food_wine';
    else if (urltest.indexOf('aboriginal') > -1)
        Australia._currentSection = 'aboriginal';
    else if (urltest.indexOf('honeymoons') > -1 || urltest.indexOf('journeys')>-1)
        Australia._currentSection = 'honeymoons';
    else if (urltest.indexOf('nature') > -1)
        Australia._currentSection = 'nature';
    else Australia._currentSection = 'cities'; //default section for new visitors

    //return cached value
    return Australia._currentSection;
};
Australia.setGenericLinks = function() {
    //append query param to generic links
$("a[href='competition.htm']").attr("href", "competition.htm?" + Australia.CurrentSection());
$("a[href='offers.htm']").attr("href", "offers.htm?" + Australia.CurrentSection());
$("a[href='fast_facts.htm']").attr("href", "fast_facts.htm?" + Australia.CurrentSection());
}

//this function sets non-generic links from a generic page to the current context's section
Australia.SetUpContextForGenericPage = function() {
    //collect section properties
    var sectionlinkId = Australia.CurrentSection();
    var mastheadImageUrl;
    var galleryName;
    var video;
    switch (sectionlinkId) {
        case "food_wine":
            mastheadImageUrl = 'top_6a';
            sectionlinkId = "food";
            galleryName = "FoodWine";
            video = "3";
            break;
        case "aboriginal":
            mastheadImageUrl = 'top_4a';
            sectionlinkId = "outback";
            galleryName = "AboriginalOutback";
            video = "6";
            break;
        case "honeymoons":
            mastheadImageUrl = 'top_7a';
            sectionlinkId = "honey";
            galleryName = "Journeysgallery";
            video = "4";
            break;
        case "coastal":
            mastheadImageUrl = 'top_1a';
            galleryName = "Coastalgallery";
            video = "2";
            break;
        case "cities":
            mastheadImageUrl = 'top_2a';
            galleryName = "Cities";
            video = "";
            break;
        case "nature":
            galleryName = "Nature";
            mastheadImageUrl = 'top_5a';
            video = "5";
            break;
    }

    //highlight current section
    var imageEl = $("#" + sectionlinkId + "_link img"); imageEl.attr("src", imageEl.attr("src").replace(".png", "_h.png")); $("#" + sectionlinkId + "_link div a").css("color", "#37c1c2");
    var mainEl = document.getElementById(sectionlinkId + "_link"); mainEl.onmouseover = ''; mainEl.onmouseout = '';

    //set mast-head image
    //$("#banner img").attr("src", "australia_images/" + mastheadImageUrl + ".png");

    //set non generic links
    $("a[href='coastal_where_to_stay.htm']").attr("href", Australia.CurrentSection() + "_where_to_stay.htm");
    $("a[href='coastal_what_to_do.htm']").attr("href", Australia.CurrentSection() + "_what_to_do.htm");
    $("a[title='Gallery']").attr("href", "cngallery/galleryframe.htm?gallery=" + galleryName + "generic&TB_iframe=true&height=498&width=874&modal=true").attr("class", "thickbox");
    $("a[title='Video']").attr("href", Australia.CurrentSection() + ".htm?showvideo");
};

Australia.IsGenericPage = function() {
    var urltest = document.location.toString().toLowerCase();
    if (urltest.indexOf('competition.htm') > -1 || urltest.indexOf('offers.htm') > -1 || urltest.indexOf('fast_facts.htm') > -1 || urltest.indexOf('thankyou.htm') > -1)
        return true;
    else
        return false;
};


//set generic links on all pages
$(document).ready(function() {
    Australia.setGenericLinks();
});

//set non-generic page links on generic pages
if (Australia.IsGenericPage() == true) {
    $(document).ready(function() {
        Australia.SetUpContextForGenericPage();
    });

}
