function attach(o, evt, fnc) {
    var xMoz = (typeof document.implementation != 'undefined') && (typeof document.implementation.createDocument != 'undefined') && (typeof HTMLDocument != 'undefined');
    var xSaf = navigator.userAgent.toLowerCase().indexOf("safari") != -1;
    var fIE = !xMoz && !xSaf;
    if (!fIE) {
        if (evt.substr(0, 2).toLowerCase() == "on")
            evt = evt.substr(2);
        o.addEventListener(evt, fnc, false);
    }
    else o.attachEvent(evt, fnc);
}

// append 'search text' to the box
attach(window, "onload", attachToSearchRecipe);

// append just enough numerals to the main recipe slider
attach(window, "onload", appendNumerals);


attach(window, "onload", initiateRecipeFinder);

function appendNumerals() {
    try {
        if (document.getElementById("cat_hl_164732")) {
            var totalRecipes = $("#cat_hl_164732 span.slides").length;
            var divNumerals = document.getElementById("slider").appendChild(document.createElement("div"));
            divNumerals.id = "numerals";
            for (i = 0; i < totalRecipes; i++) {
                var numeralDiv = divNumerals.appendChild(document.createElement("div"));
                numeralDiv.className = "class_numeral_div";
                numeralAnchor = numeralDiv.appendChild(document.createElement("a"));
                var m = i + 1;
                numeralAnchor.innerHTML = m;
                numeralAnchor.href = "javascript:switchSlide(" + m + ",0);";
            }
        }
    }
    catch (ex) { }
};


function onEnter(form, e, strParam) {
    var keycode;
    if (window.event) keycode = window.event.keyCode;
    else if (e) keycode = e.which;
    else return true;
    if (keycode == 13) {
        submit_form(form, strParam);
        return false;
    } else return true;
}


function submit_form() {
    var arrArgs = submit_form.arguments;
    var oForm = arrArgs[0];
    var strParam = arrArgs[1];
    var strInput, strType;

    if (strParam == 'rs') {
        if ("[" + typeof (oForm.query.value) + "]" != "[undefined]") {
            strInput = oForm.query.value
        } else {
            strInput = '';
        }

        window.parent.location.href = "/recipesearch/searchresults.aspx?collection=AllNZRecipe&query=" + strInput;

    }
    return false;
}












var min = 9;
var max = 12;
function increaseFontSize() {
    var p = document.getElementsByTagName('p');
    for (i = 0; i < p.length; i++) {
        if (p[i].style.fontSize) {
            var s = parseInt(p[i].style.fontSize.replace("pt", ""));
        } else {
            var s = 10;
        }
        if (s != max) {
            s += 1;
        }
        p[i].style.fontSize = s + "pt"
    }
}
function decreaseFontSize() {
    var p = document.getElementsByTagName('p');
    for (i = 0; i < p.length; i++) {
        if (p[i].style.fontSize) {
            var s = parseInt(p[i].style.fontSize.replace("pt", ""));
        } else {
            var s = 10;
        }
        if (s != min) {
            s -= 1;
        }
        p[i].style.fontSize = s + "pt"
    }
}




function initiateRecipeFinder() {


    fnc_HL164220();

    // background image for last li item on footer
    fnc_HL164390();

    // attach onclick events on footer-tabbed module
    fncAttachEventsToLinks();
    fncFooterScroller("scroller_most_rated");


    // attach onclick events on footer-tabbed module
    fncAttachEventsToLinksOnHomePage();
    fncHomePageScroller("div_scroller_entree");

    fncMostRated();
    fncMostPopular();


    if (document.getElementById("cat_hl_164678"))
        fncHomeEntree();

    if (document.getElementById("cat_hl_164679"))
        fncHomeMains();

    if (document.getElementById("cat_hl_164680"))
        fncHomeDessert();

    // hack to fix the hack on the template, how good is that?
    if (document.getElementById("contentcol") != null) {
        document.getElementById("contentcol").style.height = "auto";
    }

};

function attachToSearchRecipe() {

    if (!document.getElementById("search_recipe"))
        return;

    var searchBox = document.getElementById("search_recipe");

    if (document.getElementById("search_recipe").value == "")
        document.getElementById("search_recipe").value = "Enter keyword eg: chicken, entree, easy";

    searchBox.onclick = function(evt) {
        if (document.getElementById("search_recipe").value == "Enter keyword eg: chicken, entree, easy")
            document.getElementById("search_recipe").value = "";
    };
    searchBox.onblur = function(evt) {
        if (document.getElementById("search_recipe").value == "")
            document.getElementById("search_recipe").value = "Enter keyword eg: chicken, entree, easy";
    };
};

function fncAttachEventsToLinksOnHomePage() {

    if (!document.getElementById("scroller_entree"))
        return;

    var HomeEntree = document.getElementById("scroller_entree");
    HomeEntree.onclick = function(evt) { fncHomePageScroller("div_scroller_entree"); return false; };

    var HomeEntree = document.getElementById("scroller_mains");
    HomeEntree.onclick = function(evt) { fncHomePageScroller("div_scroller_mains"); return false; };

    var HomeEntree = document.getElementById("scroller_dessert");
    HomeEntree.onclick = function(evt) { fncHomePageScroller("div_scroller_dessert"); return false; };

};


function fncHomePageScroller(selectedTab) {

    if (!document.getElementById("div_scroller_entree"))
        return;

    var allTabs = ["div_scroller_entree", "div_scroller_mains", "div_scroller_dessert"];

    for (i = 0; i < allTabs.length; i++) {

        var currentTab = allTabs[i];
        var getCurrentTab = document.getElementById(currentTab);

        if (!getCurrentTab)
            continue;

        if (currentTab == selectedTab) {
            getCurrentTab.style.display = "block";
        }
        else {
            getCurrentTab.style.display = "none";
        }
    }

    var selectedLinkTab = selectedTab.replace("div_", "");

    if (selectedLinkTab == "scroller_entree") {
        document.getElementById("scroller_entree").style.backgroundImage = "url(/img/backgrounds/bg_entree.gif)";
        document.getElementById("link_entree").style.color = "#000000";
        document.getElementById("scroller_mains").style.backgroundImage = "url(/img/backgrounds/bg_non_mains.gif)";
        document.getElementById("link_mains").style.color = "#FFFFFF";
        document.getElementById("scroller_dessert").style.backgroundImage = "url(/img/backgrounds/bg_non_dessert.gif)";
        document.getElementById("link_dessert").style.color = "#FFFFFF";
    }
    else if (selectedLinkTab == "scroller_mains") {
        document.getElementById("scroller_entree").style.backgroundImage = "url(/img/backgrounds/entree_not_selected.gif)";
        document.getElementById("link_entree").style.color = "#FFFFFF";
        document.getElementById("scroller_mains").style.backgroundImage = "url(/img/backgrounds/mains_selected.gif)";
        document.getElementById("link_mains").style.color = "#000000";
        document.getElementById("scroller_dessert").style.backgroundImage = "url(/img/backgrounds/bg_non_dessert.gif)";
        document.getElementById("link_dessert").style.color = "#FFFFFF";

    }
    else if (selectedLinkTab == "scroller_dessert") {
        document.getElementById("scroller_entree").style.backgroundImage = "url(/img/backgrounds/entree_not_selected.gif)";
        document.getElementById("link_entree").style.color = "#FFFFFF";
        document.getElementById("scroller_mains").style.backgroundImage = "url(/img/backgrounds/bg_non_mains.gif)";
        document.getElementById("link_mains").style.color = "#FFFFFF";
        document.getElementById("scroller_dessert").style.backgroundImage = "url(/img/backgrounds/dessert_selected.gif)";
        document.getElementById("link_dessert").style.color = "#000000";
    }

    $("#cat_hl_164678").animate({ marginLeft: "0px" }, 0, "swing");
    $("#cat_hl_164679").animate({ marginLeft: "0px" }, 0, "swing");
    $("#cat_hl_164680").animate({ marginLeft: "0px" }, 0, "swing");

    $("#recipefinder_home_second_photo_galleries_nav a#a_back").removeClass();
    $("#recipefinder_home_second_photo_galleries_nav a#a_back").addClass("no_more_back");
    $("#recipefinder_home_second_photo_galleries_nav a#a_forward").removeClass();
    $("#recipefinder_home_second_photo_galleries_nav a#a_forward").addClass("forward");





    return false;
};


function fncAttachEventsToLinks() {

    if (document.getElementById("link_most_rated") != null) {
        var FooterMostRated = document.getElementById("link_most_rated");
        FooterMostRated.onclick = function(evt) { fncFooterScroller("scroller_most_rated"); return false; };
        var FooterMostPopular = document.getElementById("link_most_popular");
        FooterMostPopular.onclick = function(evt) { fncFooterScroller("scroller_most_popular"); return false; };
    }

};

function fncFooterScroller(selectedTab) {

    var allTabs = ["scroller_most_rated", "scroller_most_popular"];
    for (i = 0; i < allTabs.length; i++) {
        var currentTab = allTabs[i];
        var getCurrentTab = document.getElementById(currentTab);
        if (!getCurrentTab)
            continue;
        if (currentTab == selectedTab) {
            getCurrentTab.style.display = "block";
        }
        else {
            getCurrentTab.style.display = "none";
        }
    }
    var selectedLinkTab = selectedTab.replace("scroller_", "footer_");
    if (selectedLinkTab == "footer_most_rated") {
        if (document.getElementById("footer_most_rated") != null) {
            document.getElementById("footer_most_rated").style.backgroundImage = "url(/img/backgrounds/footer_most_rated_selected.gif)";
            document.getElementById("footer_most_popular").style.backgroundImage = "url(/img/backgrounds/footer_tab_selected_most_popular.gif)";
            // temporarility disabled for most popular
            document.getElementById("photo_galleries_nav").style.display = "block";
        }
    }
    else if (selectedLinkTab == "footer_most_popular") {
        if (document.getElementById("footer_most_rated") != null) {
            document.getElementById("footer_most_rated").style.backgroundImage = "url(/img/backgrounds/footer_most_rated_not_selected.gif)";
            document.getElementById("footer_most_popular").style.backgroundImage = "url(/img/backgrounds/most_popular_selected.gif)";
            // temporarility disabled for most popular
            document.getElementById("photo_galleries_nav").style.display = "none";
        }
    }

    $("#cat_hl_164483").animate({ marginLeft: "0px" }, 0, "swing");
    $("#cat_hl_167420").animate({ marginLeft: "0px" }, 0, "swing");

    $("#photo_galleries_nav a#f_back").removeClass();
    $("#photo_galleries_nav a#f_back").addClass("no_more_back");

    $("#photo_galleries_nav a#f_forward").removeClass();
    $("#photo_galleries_nav a#f_forward").addClass("forward");

    return false;
};

// remove the background image of the last 'li' object on the horizontal navigation
function fnc_HL164220() {
    try { $("#cat_hl_164220 ul > li:last").addClass("noBackgroundImage"); }
    catch (ex) { alert("cat_hl_164220 = " + ex.description); }
};

function fnc_HL164390() {
    try { $("#cat_hl_164390 ul > li:last").addClass("noBackgroundImage"); }
    catch (ex) { alert("cat_hl_164390 = " + ex.description); }
};

function fncHomeEntree() {

    if ($("#cat_hl_164678 span.odd, #cat_hl_164678 span.even").length <= 5) {
        $("#recipefinder_home_second_photo_galleries_nav").hide();
        $("#recipefinder_home_second_content .headerimage .headertitle a").width("620px");
    }

    $("#recipefinder_home_second_photo_galleries_nav a#a_back").click(function() {
        try {
            var marginLeft = getPixelValue($("#cat_hl_164678").css("margin-left"));
            if (marginLeft < 0) {
                marginLeft = marginLeft + 615;
                $("#cat_hl_164678").animate({ marginLeft: marginLeft + "px" }, 250, "swing", swapButtonsDisplay);
            }

        }
        catch (ex) {
            alert("cat_hl_164678 = " + ex.description);
        }
        finally {
            return false;
        }
    });

    $("#recipefinder_home_second_photo_galleries_nav a.forward").click(function() {
        try {
            var marginLeft = getPixelValue($("#cat_hl_164678").css("margin-left"));
            var imageCount = $("#cat_hl_164678 span.odd, #cat_hl_164678 span.even").length;
            if (imageCount <= 5 || (marginLeft > (0 - ((imageCount * 123) - 5 * 123)))) {
                marginLeft = marginLeft - 615;
                $("#cat_hl_164678").animate({ marginLeft: marginLeft + "px" }, 250, "swing", swapButtonsDisplay);
            }
        }
        catch (ex) {
            alert("cat_hl_164678 = " + ex.description);
        }
        finally {
            return false;
        }
    });

    $("#recipefinder_home_second_content .headerimage .headertitle a").text($("#cat_hl_164678 .headerimage .headertitle a").text());

    function getPixelValue(value) {
        var val = value;
        if (val == "auto")
            val = "0";
        val = parseInt(val.replace("px", ""));
        return val;
    }

    // call back to animate()
    function swapButtonsDisplay() {

        var imageCount = $("#cat_hl_164678 span.odd, #cat_hl_164678 span.even").length;
        var totalPossibleScrolls = (Math.ceil(imageCount / 5) - 1);
        var maxPossibleLeftMargin = (-1) * (615 * totalPossibleScrolls);
        var currentlyItIs = getPixelValue($("#cat_hl_164678").css("margin-left"));

        // cannot go any more forward
        if (currentlyItIs == maxPossibleLeftMargin) {
            $("#recipefinder_home_second_photo_galleries_nav a#a_forward").removeClass();
            $("#recipefinder_home_second_photo_galleries_nav a#a_forward").addClass("no_more_forward");
            $("#recipefinder_home_second_photo_galleries_nav a#a_back").removeClass();
            $("#recipefinder_home_second_photo_galleries_nav a#a_back").addClass("back");
        }
        // can go forward, both buttons to appear here
        else if (currentlyItIs > maxPossibleLeftMargin && currentlyItIs != 0) {
            $("#recipefinder_home_second_photo_galleries_nav a#a_back").removeClass();
            $("#recipefinder_home_second_photo_galleries_nav a#a_back").addClass("back");
            $("#recipefinder_home_second_photo_galleries_nav a#a_forward").removeClass();
            $("#recipefinder_home_second_photo_galleries_nav a#a_forward").addClass("forward");
        }
        else if (currentlyItIs == 0) {
            $("#recipefinder_home_second_photo_galleries_nav a#a_back").removeClass();
            $("#recipefinder_home_second_photo_galleries_nav a#a_back").addClass("no_more_back");
            $("#recipefinder_home_second_photo_galleries_nav a#a_forward").removeClass();
            $("#recipefinder_home_second_photo_galleries_nav a#a_forward").addClass("forward");
        }
    };

}; // entree


function fncHomeMains() {
    if ($("#cat_hl_164679 span.odd, #cat_hl_164679 span.even").length <= 5) {
        $("#recipefinder_home_second_photo_galleries_nav").hide();
        $("#recipefinder_home_second_content .headerimage .headertitle a").width("615px");
    }
    $("#recipefinder_home_second_photo_galleries_nav a#a_back").click(function() {
        try {
            var marginLeft = getPixelValue($("#cat_hl_164679").css("margin-left"));
            if (marginLeft < 0) {
                marginLeft = marginLeft + 615;
                $("#cat_hl_164679").animate({ marginLeft: marginLeft + "px" }, 250, "swing", swapButtonsDisplayMains);
            }
        }
        catch (ex) { alert("cat_hl_164679 = " + ex.description); }
        finally {
            return false;
        }
    });
    $("#recipefinder_home_second_photo_galleries_nav a#a_forward").click(function() {
        try {
            var marginLeft = getPixelValue($("#cat_hl_164679").css("margin-left"));
            var imageCount = $("#cat_hl_164679 span.odd, #cat_hl_164679 span.even").length;
            var maxMargin = (0 - (imageCount * 123) + (5 * 123));
            if (imageCount <= 5 || ((marginLeft) > maxMargin)) {
                marginLeft = marginLeft - 615;
                $("#cat_hl_164679").animate({ marginLeft: marginLeft + "px" }, 250, "swing", swapButtonsDisplayMains);
            }
        }
        catch (ex) {
            alert("cat_hl_164679 = " + ex.description);
        }
        finally {
            return false;
        }
    });

    $("#recipefinder_home_second_content .headerimage .headertitle a").text($("#cat_hl_164679 .headerimage .headertitle a").text());

    function getPixelValue(value) {
        var val = value;
        if (val == "auto")
            val = "0";
        val = parseInt(val.replace("px", ""));
        return val;
    }

    // call back to animate()
    function swapButtonsDisplayMains() {

        var imageCount = $("#cat_hl_164679 span.odd, #cat_hl_164679 span.even").length;
        var totalPossibleScrolls = (Math.ceil(imageCount / 5) - 1);
        var maxPossibleLeftMargin = (-1) * (615 * totalPossibleScrolls);
        var currentlyItIs = getPixelValue($("#cat_hl_164679").css("margin-left"));

        // cannot go any more forward
        if (currentlyItIs == maxPossibleLeftMargin) {
            $("#recipefinder_home_second_photo_galleries_nav a#a_forward").removeClass();
            $("#recipefinder_home_second_photo_galleries_nav a#a_forward").addClass("no_more_forward");
            $("#recipefinder_home_second_photo_galleries_nav a#a_back").removeClass();
            $("#recipefinder_home_second_photo_galleries_nav a#a_back").addClass("back");
        }
        // can go forward, both buttons to appear here
        else if (currentlyItIs > maxPossibleLeftMargin && currentlyItIs != 0) {
            $("#recipefinder_home_second_photo_galleries_nav a#a_back").removeClass();
            $("#recipefinder_home_second_photo_galleries_nav a#a_back").addClass("back");
            $("#recipefinder_home_second_photo_galleries_nav a#a_forward").removeClass();
            $("#recipefinder_home_second_photo_galleries_nav a#a_forward").addClass("forward");
        }
        else if (currentlyItIs == 0) {
            $("#recipefinder_home_second_photo_galleries_nav a#a_back").removeClass();
            $("#recipefinder_home_second_photo_galleries_nav a#a_back").addClass("no_more_back");
            $("#recipefinder_home_second_photo_galleries_nav a#a_forward").removeClass();
            $("#recipefinder_home_second_photo_galleries_nav a#a_forward").addClass("forward");
        }
    };
}; // mains


function fncHomeDessert() {
    if ($("#cat_hl_164680 span.odd, #cat_hl_164680 span.even").length <= 5) {
        $("#recipefinder_home_second_photo_galleries_nav").hide();
        $("#recipefinder_home_second_content .headerimage .headertitle a").width("620px");
    }
    $("#recipefinder_home_second_photo_galleries_nav a#a_back").click(function() {
        try {
            var marginLeft = getPixelValue($("#cat_hl_164680").css("margin-left"));
            if (marginLeft < 0) {
                marginLeft = marginLeft + 615;
                $("#cat_hl_164680").animate({ marginLeft: marginLeft + "px" }, 250, "swing", swapButtonsDisplayDessert);
            }
        }
        catch (ex) {
            alert("cat_hl_164680 = " + ex.description);
        }
        finally {
            return false;
        }
    });
    $("#recipefinder_home_second_photo_galleries_nav a#a_forward").click(function() {
        try {
            var marginLeft = getPixelValue($("#cat_hl_164680").css("margin-left"));
            var imageCount = $("#cat_hl_164680 span.odd, #cat_hl_164680 span.even").length;
            if (imageCount <= 5 || (marginLeft > (0 - ((imageCount * 123) - 5 * 123)))) {
                marginLeft = marginLeft - 615;
                $("#cat_hl_164680").animate({ marginLeft: marginLeft + "px" }, 250, "swing", swapButtonsDisplayDessert);
            }
        }
        catch (ex) {
            alert("cat_hl_164680 = " + ex.description);
        }
        finally {
            return false;
        }
    });

    $("#recipefinder_home_second_content .headerimage .headertitle a").text($("#cat_hl_164680 .headerimage .headertitle a").text());

    function getPixelValue(value) {
        var val = value;
        if (val == "auto")
            val = "0";
        val = parseInt(val.replace("px", ""));
        return val;
    }

    // call back to animate()
    function swapButtonsDisplayDessert() {

        var imageCount = $("#cat_hl_164680 span.odd, #cat_hl_164680 span.even").length;
        var totalPossibleScrolls = (Math.ceil(imageCount / 5) - 1);
        var maxPossibleLeftMargin = (-1) * (615 * totalPossibleScrolls);
        var currentlyItIs = getPixelValue($("#cat_hl_164680").css("margin-left"));

        // cannot go any more forward
        if (currentlyItIs == maxPossibleLeftMargin) {
            $("#recipefinder_home_second_photo_galleries_nav a#a_forward").removeClass();
            $("#recipefinder_home_second_photo_galleries_nav a#a_forward").addClass("no_more_forward");
            $("#recipefinder_home_second_photo_galleries_nav a#a_back").removeClass();
            $("#recipefinder_home_second_photo_galleries_nav a#a_back").addClass("back");
        }
        // can go forward, both buttons to appear here
        else if (currentlyItIs > maxPossibleLeftMargin && currentlyItIs != 0) {
            $("#recipefinder_home_second_photo_galleries_nav a#a_back").removeClass();
            $("#recipefinder_home_second_photo_galleries_nav a#a_back").addClass("back");
            $("#recipefinder_home_second_photo_galleries_nav a#a_forward").removeClass();
            $("#recipefinder_home_second_photo_galleries_nav a#a_forward").addClass("forward");
        }
        else if (currentlyItIs == 0) {
            $("#recipefinder_home_second_photo_galleries_nav a#a_back").removeClass();
            $("#recipefinder_home_second_photo_galleries_nav a#a_back").addClass("no_more_back");
            $("#recipefinder_home_second_photo_galleries_nav a#a_forward").removeClass();
            $("#recipefinder_home_second_photo_galleries_nav a#a_forward").addClass("forward");
        }
    };

}; // mains


function fncMostRated() {

    if ($("#cat_hl_164483 span.odd, #cat_hl_164483 span.even").length <= 5) {
        $("#photo_galleries_nav").hide();
        $("#photo_galleries .headerimage .headertitle a").width("615px");
    }

    $("#f_back").click(function() {
        try {
            var marginLeft = getPixelValue($("#cat_hl_164483").css("margin-left"));
            if (marginLeft < 0) {
                marginLeft = marginLeft + 615;
                $("#cat_hl_164483").animate({ marginLeft: marginLeft + "px" }, 250, "swing", swapButtonsDisplayMostRated);
            }
        }
        catch (ex) { }
        finally {
            return false;
        }
    });

    $("#f_forward").click(function() {
        try {
            var marginLeft = getPixelValue($("#cat_hl_164483").css("margin-left"));
            var imageCount = $("#cat_hl_164483 span.odd, #cat_hl_164483 span.even").length;
            var maxMarginLeft = (-1) * ((imageCount * 123) - (5 * 123));
            if (imageCount <= 5 || (marginLeft > maxMarginLeft)) {
                marginLeft = marginLeft - 615;
                $("#cat_hl_164483").animate({ marginLeft: marginLeft + "px" }, 250, "swing", swapButtonsDisplayMostRated);
            }
        }
        catch (ex) { }
        finally {
            return false;
        }
    });

    $("#photo_galleries .headerimage .headertitle a").text($("#cat_hl_164483 .headerimage .headertitle a").text());
    function getPixelValue(value) {
        var val = value;
        if (val == "auto")
            val = "0";
        val = parseInt(val.replace("px", ""));
        return val;
    };

    // call back to animate()
    function swapButtonsDisplayMostRated() {

        var imageCount = $("#cat_hl_164483 span.odd, #cat_hl_164483 span.even").length;
        var totalPossibleScrolls = (Math.ceil(imageCount / 5) - 1);
        var maxPossibleLeftMargin = (-1) * (615 * totalPossibleScrolls);
        var currentlyItIs = getPixelValue($("#cat_hl_164483").css("margin-left"));


        // cannot go any more forward
        if (currentlyItIs == maxPossibleLeftMargin) {
            $("#f_forward").removeClass();
            $("#f_forward").addClass("no_more_forward");
            $("#f_back").removeClass();
            $("#f_back").addClass("back");
        }
        // can go forward, both buttons to appear here
        else if (currentlyItIs > maxPossibleLeftMargin && currentlyItIs != 0) {
            $("#f_back").removeClass();
            $("#f_back").addClass("back");
            $("#f_forward").removeClass();
            $("#f_forward").addClass("forward");
        }
        else if (currentlyItIs == 0) {
            $("#f_back").removeClass();
            $("#f_back").addClass("no_more_back");
            $("#f_forward").removeClass();
            $("#f_forward").addClass("forward");
        }
    };
};

function fncMostPopular() {

    if ($("#cat_hl_167420 span.odd, #cat_hl_167420 span.even").length <= 5) {
        $("#photo_galleries_nav").hide();
        $("#photo_galleries .headerimage .headertitle a").width("615px");
    }


    $("#f_back").click(function() {
        try {
            var marginLeft = getPixelValue($("#cat_hl_167420").css("margin-left"));
            if (marginLeft < 0) {
                marginLeft = marginLeft + 615;
                $("#cat_hl_167420").animate({ marginLeft: marginLeft + "px" }, 250, "swing", swapButtonsDisplayMostRated);
            }
        }
        catch (ex) {
        }
        finally {
            return false;
        }
    });

    $("#f_forward").click(function() {
        try {
            var marginLeft = getPixelValue($("#cat_hl_167420").css("margin-left"));
            var imageCount = $("#cat_hl_167420 span.odd, #cat_hl_167420 span.even").length;
            var maxMarginLeft = (-1) * ((imageCount * 123) - (5 * 123));
            if (imageCount <= 5 || (marginLeft > maxMarginLeft)) {
                marginLeft = marginLeft - 615;
                $("#cat_hl_167420").animate({ marginLeft: marginLeft + "px" }, 250, "swing", swapButtonsDisplayMostRated);
            }
        }
        catch (ex) {
        }
        finally {
            return false;
        }
    });

    $("#photo_galleries .headerimage .headertitle a").text($("#cat_hl_167420 .headerimage .headertitle a").text());
    function getPixelValue(value) {
        var val = value;
        if (val == "auto")
            val = "0";
        val = parseInt(val.replace("px", ""));
        return val;
    }

    // call back to animate()
    function swapButtonsDisplayMostRated() {

        var imageCount = $("#cat_hl_167420 span.odd, #cat_hl_167420 span.even").length;
        var totalPossibleScrolls = (Math.ceil(imageCount / 5) - 1);
        var maxPossibleLeftMargin = (-1) * (615 * totalPossibleScrolls);
        var currentlyItIs = getPixelValue($("#cat_hl_167420").css("margin-left"));

        // cannot go any more forward
        if (currentlyItIs == maxPossibleLeftMargin) {
            $("#f_forward").removeClass();
            $("#f_forward").addClass("no_more_forward");
            $("#f_back").removeClass();
            $("#f_back").addClass("back");
        }
        // can go forward, both buttons to appear here
        else if (currentlyItIs > maxPossibleLeftMargin && currentlyItIs != 0) {
            $("#f_back").removeClass();
            $("#f_back").addClass("back");
            $("#f_forward").removeClass();
            $("#f_forward").addClass("forward");
        }
        else if (currentlyItIs == 0) {
            $("#f_back").removeClass();
            $("#f_back").addClass("no_more_back");
            $("#f_forward").removeClass();
            $("#f_forward").addClass("forward");
        }
    };
};

function fnChangeCourse(cboId, btnId) {
    var cboCuisineType = document.getElementById(cboId);
    var btnObj = document.getElementById(btnId);
    var selIndex = cboCuisineType.selectedIndex;
    var sHref = cboCuisineType.options[selIndex].value;
    if (sHref.length > 0) {
        $(btnObj).attr('href', sHref);
    }
    else {
        $(btnObj).attr('href', 'javascript:alert("please select course type.");javascript:void(0);');
    }
}



