  var panelwidth = 183;
    var currentpanel = 0;
    var caroselBar;
    var caroselBarInner;
    var demonstration;
    var ieversion = 10;

    function show_carosel() {
        caroselHTML = "<table class=\"carosel\"><tr><td class=\"carosel_left\" onclick=\"panel(-5)\" id=\"carosel_left\" onmouseover=\"hcc('left','over')\" onmouseout=\"hcc('left','out')\"></td><td><div id=\"caroselBar\"><div id=\"caroselBarInner\"><table style=\"border-collapse:collapse\"><tr>";
        for (i = 0; i < carosel.length; i++) {
            caroselHTML += "<td><table style=\"background:url('/graphics/carosel/" + carosel[i][0] + ".jpg')\" class=blankcarosel onmouseover=\"this.className='activecarosel'\" onmouseout=\"this.className='blankcarosel'\" onclick=\"location.href='/tourism/products/?id=" + carosel[i][0] + "'\" title=\"" + carosel[i][1] + "\"><tr><Td class=carosel_description valign=top><div>" + carosel[i][3] + "</div></td></tr><tr><td class=carosel_title><div>" + carosel[i][2] + "</div></td></tr></table></td>";
        }
        caroselHTML += "</tr></table></div></div></td><td class=\"carosel_right\" onclick=\"panel(+5)\" id=\"carosel_right\" onmouseover=\"hcc('right','over')\" onmouseout=\"hcc('right','out')\"></td></table><br />";
        document.write(caroselHTML);
        caroselBarInner = document.getElementById("caroselBarInner");
        stagewidth = document.getElementById("caroselBar").offsetWidth;
        panel_offset = 0;
        panel_display = Math.ceil(stagewidth / panelwidth);
        panel_max_offset = carosel.length - panel_display;
    }

    if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
        var ieversion = new Number(RegExp.$1);
    }

    function s(what) {
        what.className = "menu_show";
        if (ieversion < 7) {
            document.getElementById("quick_finder").style.visibility = "hidden";
        }
    }


    function c(what) {
        what.className = "menu_hide";
        if (ieversion < 7) {
            document.getElementById("quick_finder").style.visibility = "visible";
        }
    }


    function h(what, x, y) {
        what.style.backgroundPosition = "" + x + "px " + y + "px";
    }


    function ajax_fetch_type() {
        value_send = escape(document.getElementById("quick_location").options[document.getElementById("quick_location").selectedIndex].text);
        if (value_send != escape("Select Your Region") &&
            value_send != "---------------------------") {
            aJAXit("tour_location=" + value_send);
            history_region = value_send;
        } else {
            alert("Invalid Selection");
        }
    }


    function show_quickfinder() {
        document.write(" <select onchange=\"ajax_fetch_type()\" id=\"quick_location\">");
        document.write("<option>Select Your Region</option>");
        document.write("<option>---------------------------</option>");
        document.write("<option>North &amp; The Atacama</option>");
        document.write("<option>Santiago &amp; Central Valley</option>");
        document.write("<option>Easter Island</option>");
        document.write("<option>Lake District &amp; Volcanoes</option>");
        document.write("<option>Patagonia</option>");
        document.write("<option>Chile</option>");
        document.write("<option>International</option>");
        document.write("</select> <select disabled=\"disabled\">");
        document.write("<option>Select Type of Activity</option>");
        document.write("</select> <select disabled=\"disabled\">");
        document.write("<option>Select Product</option>");
        document.write("</select>");
        document.write("<div>");
        document.write("<input type=\"submit\" value=\"View Tour\" disabled=\"disabled\" />");
        document.write("</div>");
    }


    function ajax_fetch_product() {
        value_send = escape(document.getElementById("quick_type").options[document.getElementById("quick_type").selectedIndex].text);
        if (value_send != escape("Select Type of Activity") &&
            value_send != "---------------------------") {
            aJAXit("tour_location=" + history_region + "&tour_type=" + value_send);
        } else {
            alert("Invalid Selection");
        }
    }


    function fetch_tour() {
        value_send = escape(document.getElementById("quick_product").options[document.getElementById("quick_product").selectedIndex].value);
        if (value_send != escape("Select Product") &&
            value_send != "---------------------------") {
            document.location.href = "/tourism/products/?id=" + value_send;
        } else {
            alert("Invalid Selection");
        }
    }


    function aJAXit(string) {
        var ajaxRequest;
        var getstr = string;
        try {
            ajaxRequest = new XMLHttpRequest;
        } catch (e) {
            try {
                ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {
                    alert("Incompatible Browser.");
                    return false;
                }
            }
        }
        ajaxRequest.open("POST", "/tourism/products/quick_finder.php?rnd=" + Math.random(), true);
        ajaxRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset:ISO-8859-1");
        ajaxRequest.onreadystatechange = function () {if (ajaxRequest.readyState == 4) {document.getElementById("quick_finder").innerHTML = ajaxRequest.responseText;}};
        document.getElementById("quick_finder").innerHTML = "Please Wait";
        ajaxRequest.send(getstr);
    }


    function SmoothMovement(position, target, velocity) {
        position = Math.round(position);
        target = Math.round(target);
        velocity = velocity ? Math.round(velocity) : 0;
        this.updatePosition = function () {position += velocity;if (velocity < 0) {if (position - velocity * (velocity - 1) / 2 < target) {velocity++;} else if (position - (velocity - 1) * (velocity - 2) / 2 >= target) {velocity--;}} else {if (position + velocity * (velocity + 1) / 2 > target) {velocity--;} else if (position + (velocity + 1) * (velocity + 2) / 2 <= target) {velocity++;}}return position;};
        this.changeTarget = function (newTarget) {target = Math.round(newTarget);};
        this.getPosition = function () {return position;};
        this.getVelocity = function () {return velocity;};
        this.hasStopped = function () {return position == target && velocity == 0;};
    }


    function updateDemonstration() {
        caroselBarInner.style.left = demonstration.updatePosition() + "px";
    }


    function panel(action) {
        panel_offset_new = panel_offset + action;
        h(document.getElementById("carosel_left"), "-27", "0");
        document.getElementById("carosel_left").style.cursor = "pointer";
        h(document.getElementById("carosel_right"), "-27", "0");
        document.getElementById("carosel_right").style.cursor = "pointer";
        if (panel_offset_new <= 0) {
            panel_offset_new = 0;
            document.getElementById("carosel_left").style.cursor = "default";
            h(document.getElementById("carosel_left"), "27", "0");
            h(document.getElementById("carosel_right"), "54", "0");
        }
        if (panel_offset_new >= panel_max_offset) {
            panel_offset_new = panel_max_offset;
            document.getElementById("carosel_right").style.cursor = "default";
            h(document.getElementById("carosel_left"), "54", "0");
            h(document.getElementById("carosel_right"), "0", "0");
        }
        panel_offset = panel_offset_new;
        demonstration.changeTarget(-1 * panel_offset_new * panelwidth);
    }


    function hcc(arrow, action) {
        if (arrow == "left") {
            if (action == "over") {
                if (panel_offset != 0) {
                    h(document.getElementById("carosel_left"), "0", "0");
                }
            }
            if (action = "out") {
                if (panel_offset != 0) {
                    h(document.getElementById("carosel_left"), "-27", "0");
                }
            }
        }
        if (arrow == "right") {
            if (action == "over") {
                if (panel_offset != panel_max_offset) {
                    h(document.getElementById("carosel_right"), "-54", "0");
                }
            }
            if (action = "out") {
                if (panel_offset != panel_max_offset) {
                    h(document.getElementById("carosel_right"), "-27", "0");
                }
            }
        }
    }


    function setActiveStyleSheet(title) {
        var i, a, main;
        for (i = 0; (a = document.getElementsByTagName("link")[i]); i++) {
            if (a.getAttribute("rel").indexOf("style") != -1 &&
                a.getAttribute("title")) {
                a.disabled = true;
                if (a.getAttribute("title") == title) {
                    a.disabled = false;
                }
            }
        }
    }


    function getActiveStyleSheet() {
        var i, a;
        for (i = 0; (a = document.getElementsByTagName("link")[i]); i++) {
            if (a.getAttribute("rel").indexOf("style") != -1 &&
                a.getAttribute("title") && !a.disabled) {
                return a.getAttribute("title");
            }
        }
        return null;
    }


    function getPreferredStyleSheet() {
        var i, a;
        for (i = 0; (a = document.getElementsByTagName("link")[i]); i++) {
            if (a.getAttribute("rel").indexOf("style") != -1 &&
                a.getAttribute("rel").indexOf("alt") == -1 &&
                a.getAttribute("title")) {
                return a.getAttribute("title");
            }
        }
        return null;
    }


    function createCookie(name, value, days) {
        if (days) {
            var date = new Date;
            date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
            var expires = "; expires=" + date.toGMTString();
        } else {
            expires = "";
        }
        document.cookie = name + "=" + value + expires + "; path=/";
    }


    function readCookie(name) {
        var nameEQ = name + "=";
        var ca = document.cookie.split(";");
        for (var i = 0; i < ca.length; i++) {
            var c = ca[i];
            while (c.charAt(0) == " ") {
                c = c.substring(1, c.length);
            }
            if (c.indexOf(nameEQ) == 0) {
                return c.substring(nameEQ.length, c.length);
            }
        }
        return null;
    }

    window.onunload = function (e) {var title = getActiveStyleSheet();createCookie("style", title, 365);};
    var cookie = readCookie("style");
    var title = cookie ? cookie : getPreferredStyleSheet();
    setActiveStyleSheet(title);
    onload = function () {demonstration = new SmoothMovement(0, 0);window.setInterval(updateDemonstration, 20);var cookie = readCookie("style");var title = cookie ? cookie : getPreferredStyleSheet();setActiveStyleSheet(title);};