typeof jQuery == "undefined" ? CF_load("//ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js", function () {
    CF_init()
}) : CF_init();

jQuery(document).ready(function () {
	jQuery("#CF_items .CF_add").click(function () {
		if (jQuery('#CF_param_qty').val() == 0 && jQuery('#CF_param_children').val() == 0 && jQuery('#CF_param_seniors').val() == 0) {
			jQuery('#CF_param_qty').css('border', '2px solid red');
			jQuery('#CF_param_children').css('border', '2px solid red');
			jQuery('#CF_param_seniors').css('border', '2px solid red');
			alert('Please enter the number of tickets you need');
			return false;
		}
	});
});

function CF_load(c, i) {
    var k = arguments.callee;
    if (!("queue" in k)) k.queue = {};
    var d = k.queue;
    if (c in d) i && (d[c] ? d[c].push(i) : i());
    else {
        d[c] = i ? [i] : [];
        var a = document.createElement("script");
        a.type = "text/javascript";
        a.onload = a.onreadystatechange = function () {
            if (!a.readyState || !(a.readyState != "loaded" && a.readyState != "complete")) {
                for (a.onreadystatechange = a.onload = null; d[c].length;) d[c].shift()();
                d[c] = null
            }
        };
        a.src = c;
        document.getElementsByTagName("head")[0].appendChild(a)
    }
}
var CF_version;

function CF_init() {
    jQuery(document).ready(function () {
        if (!CF_version) {
            CF_version = "1.7.7";
            var c = jQuery("#CF_id").attr("class");
            c || (c = jQuery("#CF").attr("class"));
            c || (c = jQuery("#CF_cal").attr("class"));
            if (c) {
                var i = /^1.6|^1.7/.test(jQuery.fn.jquery) ? 0 : 1,
                    c = "//" + c,
                    k = document.getElementsByTagName("head")[0],
                    d = document.createElement("link");
                d.type = "text/css";
                d.rel = "stylesheet";
                d.href = c + "/www/client.css?" + CF_version;
                d.media = "screen";
                k.appendChild(d);
                (function (a) {
                    jQuery.cookie = function (a, c, e) {
                        if (typeof c != "undefined") {
                            e = e || {};
                            if (c === null) c = "", e.expires = -1;
                            var g = "";
                            if (e.expires && (typeof e.expires == "number" || e.expires.toUTCString)) typeof e.expires == "number" ? (g = new Date, g.setTime(g.getTime() + e.expires * 864E5)) : g = e.expires, g = "; expires=" + g.toUTCString();
                            var d = e.path ? "; path=" + e.path : "",
                                i = e.domain ? "; domain=" + e.domain : "",
                                e = e.secure ? "; secure" : "";
                            document.cookie = [a, "=", encodeURIComponent(c), g, d, i, e].join("")
                        } else {
                            c = null;
                            if (document.cookie && document.cookie != "") {
                                e = document.cookie.split(";");
                                for (g = 0; g < e.length; g++) if (d = jQuery.trim(e[g]), d.substring(0, a.length + 1) == a + "=") {
                                    c = decodeURIComponent(d.substring(a.length + 1));
                                    break
                                }
                            }
                            return c
                        }
                    };
                    a.fn.checkfront = function (c) {
                        function d(b) {
                            if (!a("#CF").length) b.elm = "cal";
                            var c = window.location.protocol + b.url + "/api/" + b.version + "/ui/?CF_elm=" + b.elm;
                            if (!b.day_id) {
                                var h = window.location.hash.replace("#D", "");
                                b.day_id = h > 0 ? h : 0
                            }
                            b.day_id && (c += "&CF_D=" + b.day_id);
                            h = parseInt(window.location.hash.replace("#item_id:", ""));
                            h > 0 && (c += "&CF_item_id=" + h);
                            if (f) {
                                if (f.elm) b.elm = f.elm;
                                if (f.callback) b.callback = f.callback;
                                f.category_id && (c += "&CF_category_id=" + f.category_id);
                                f.item_id && (c += "&CF_item_id=" + f.item_id);
                                f.mode && (c += "&CF_mode=" + f.mode);
                                f.date && (c += "&CF_D=" + f.date);
                                f.len && (c += "&CF_len=" + f.len);
                                f.time && (c += "&CF_time=" + f.time);
                                f.discount && (c += "&CF_discount=" + f.discount)
                            }
                            var j;
                            a.cookie("CF_voucher") ? j = a.cookie("CF_voucher") : e("CF_voucher") ? (j = e("CF_voucher"), a.cookie("CF_voucher", j)) : a("#CF_voucher").length && (j = a("#CF_voucher").val());
                            j && (c += "&CF_discount=" + j);
                            (j = e("CF_invoice")) ? (a("#CF").html('<a name="CF"></a><iframe id="CF_invoice" border="0" frameborder="0" style="height: 800px" src="https:' + b.url + "/www/invoice/" + j + '"></iframe>'), a("#CF_invoice").load(function () {}), a.getScript("https:" + b.url + "/www/lib/invoice/?id=" + j)) : (a("#CF form").length || a("#CF").prepend('<a name="CF"></a><form id="CF_box" action="' + window.location.protocol + b.url + "/api/" + b.version + '" method="get"></form>'), a.ajax({
                                type: "GET",
                                url: c,
                                data: a("#CF #CF_head input").serialize() + "&" + a("#CF #CF_B .CF_slip").serialize() + a("#CF #CF_head select").serialize(),
                                dataType: "jsonp",
                                cache: "true",
                                success: function (c) {
                                    if (c.error) a("#CF").html('<p id="CF_msg" class="error">' + c.error + "</p>"), a("#CF_msg").fadeIn();
                                    else if (a("#CF_load").hide(), typeof c.version != "undefined" && b.version != c.version && a.cookie("CF_reload") != c.version) a.cookie("CF_reload", c.version), window.document.location.reload(!0);
                                    else return a("#CF_items").length || a("#CF_box").html("<\!-- Checkfront --\>&nbsp;"), a("#CF a.CF_add").removeClass("CF_load"), a("#CF_items").removeClass("CF_dim"), a("#CF_tabs").length || a("#CF_box").append('<ul id="CF_tabs"></ul><div style="clear: both; border:0; height:0;margin:0;padding:0;"></div>'), a("#CF_items").length || a("#CF_box").append('<ul id="CF_items"></ul>'), typeof c.search != "undefined" && (a("#CF_head").length ? a("#CF_head").html("<fieldset>" + c.search.html + '</fieldset><div id="CF_status"><strong>' + c.date_desc + "</strong></div>") : a("#CF_items").html('<li id="CF_head"><fieldset>' + c.search.html + '</fieldset><div id="CF_status"><strong>' + c.date_desc + "</strong></div></li>")), typeof c.inv != "undefined" && (a.each(c.inv, function (b, d) {
                                        if (d.items) {
                                            cat = "CF_" + b;
                                            var e = d.name;
                                            d.available > 0 && (e += "<em>" + d.available + "</em>");
                                            a("#" + cat).length ? (a("#" + cat).replaceWith(d.items.html), a("#CF_tabs #" + cat + "T").html('<a href="#' + cat + '">' + e + "</a>")) : (a("#CF_tabs").append('<li id="' + cat + 'T"><a href="#' + cat + '">' + e + "</a></li>"), a("#CF_items").append(d.items.html))
                                        }!a.cookie("CF_session") && c.session_id && !a.cookie("CF_session") && c.session_id && a.cookie("CF_session", c.session_id);
                                        a.cookie("CF_session") && (a("#CF_session").length || a("#CF_head").prepend('<input type="hidden" name="CF_session" id="CF_session" value="' + a.cookie("CF_session") + '" />'))
                                    }), a("#CF_items .CF_add").click(function () {
										 if (jQuery('#CF_param_qty').val() == 0 && jQuery('#CF_param_children').val() == 0 && jQuery('#CF_param_seniors').val() == 0) {
										  jQuery('#CF_param_qty').css('border', '2px solid red');
										  jQuery('#CF_param_children').css('border', '2px solid red');
										  jQuery('#CF_param_seniors').css('border', '2px solid red');
										  alert('Please enter the number of tickets you need');
										  return false;
										}
										jQuery('#CF_param_qty').css('border', 'none');
										jQuery('#CF_param_children').css('border', 'none');
										jQuery('#CF_param_seniors').css('border', 'none');
                                        a(this).addClass("CF_load");
                                        slip = this.hash.replace("#", "");
                                        b.elm = "inv.search.cal";
                                        b.target = "#CF_B";
                                        a("#CF_head").append('<input type="hidden" class="CF_slip" name="CF_slip[N]" value="' + slip + '" />');
                                        d(b);
                                        return !1
                                    }),a('#CF_q').click(function() {
										 if (jQuery('#CF_param_qty').val() == 0 && jQuery('#CF_param_children').val() == 0 && jQuery('#CF_param_seniors').val() == 0) {
										  jQuery('#CF_param_qty').css('border', '2px solid red');
										  jQuery('#CF_param_children').css('border', '2px solid red');
										  jQuery('#CF_param_seniors').css('border', '2px solid red');
										  alert('Please enter the number of tickets you need');
										  return false;
										}
									})
									), typeof c.booking != "undefined" ? m(c) : a("#B").html(), a("#CF_tabs li a").click(function () {
                                        l(this.hash);
                                        return !1
                                    }), a("#CF_adc a").click(function () {
                                        a("#CF_adc a").hide();
                                        a("#CF_adc  span").fadeIn();
                                        return !1
                                    }), a("#CF_dc").change(function () {
                                        a("#CF_head").append('<input type="hidden" class="CF_discount" name="CF_discount" value="' + a(this).val() + '" />');
                                        d(b)
                                    }), a("#customer_country").change(function () {
                                        var c = window.location.protocol + b.url + "/api/" + b.version + "/get/regions/?country_id=" + a(this).val();
                                        a.ajax({
                                            type: "GET",
                                            url: c,
                                            dataType: "jsonp",
                                            cache: "true",
                                            success: function (b) {
                                                b.regions ? (a("#customer_region").parent("li").html('<label for="customer_region">' + b.region_type + '</label><select id="customer_region">' + b.regions + "</select>"), a("#customer_region").parent("li").show()) : b.region_type ? (a("#customer_region").parent("li").html('<label for="customer_region">' + b.region_type + '</label><input type="text"  name="customer_region" id="customer_region" />'), a("#customer_region").parent("li").show()) : a("#customer_region").parent("li").hide();
                                                b.postal_zip ? (a("label[for=customer_postal_zip]").html(b.postal_zip), a("#customer_postal_zip").parent("li").show()) : a("#customer_postal_zip").parent("li").hide()
                                            }
                                        })
                                    }), typeof c.cal != "undefined" && (a("#CF_cal").length ? (a("#CF_cal").html(c.cal.html), a("#CF_head .CF_cal").length && a("#CF_head .CF_cal").show()) : (a("#CF_head").append('<div id="CF_cal">' + c.cal.html + "</div>"), a("#CF_head input").focus(function () {
                                        a(this).attr("id") == "CF_date" ? a("#CF_head .CF_cal").show() : a("#CF_head .CF_cal").fadeOut(200)
                                    })), b.cal == "stick" && a("#CF_head .CF_cal").show(), a(".CF_times input").focus(function () {
                                        a(this).closest("div").find("ol").fadeIn();
                                        return !1
                                    }), a(".CF_times a").click(function () {
                                        if (this.hash) {
                                            a(this).closest(".CF_times").find(".CF_t").val(a(this).text());
                                            var b = a(this).closest(".CF_foot").find(".CF_add");
                                            hh = g(b);
                                            ht = hh.replace(/@.*X/, "@" + a(this).text() + "x");
                                            i ? b.attr("hash", ht) : b.prop("hash", ht);
                                            a(this).closest(".CF_time").fadeOut();
                                            return !1
                                        } else alert("Not available.")
                                    }), a("#CF_D").change(function () {
                                        a("#CF_items").addClass("CF_dim");
                                        var c = a(this).val();
                                        b.cal = null;
                                        b.day_id = c;
                                        b.elm = "inv.search.cal";
                                        a("#CF_head #CF_cal").fadeOut(200);
                                        b.target = g(a("#CF_tabs .CF_a a"));
                                        d(b);
                                        a(this).blur();
                                        return !1
                                    }), a("#CF_cal  a").click(function () {
										  if (jQuery(this).attr('id') !== 'CF_prev' && jQuery(this).attr('id') !== 'CF_next' && jQuery('#CF_param_qty').val() == 0 && jQuery('#CF_param_children').val() == 0 && jQuery('#CF_param_seniors').val() == 0) {
											jQuery.fancybox({
												'width': 300,
												'height': 300,
												'type': 'inline',
												'href': '#ticket-popup'
											});
										  }
                                        if (!a("#CF").length && a("#CF_src").val()) window.location = a("#CF_src").val() + this.hash;
                                        else {
                                            a("#CF_items").addClass("CF_dim");
                                            var c = this.hash.replace("#D", "");
                                            if (a("#CF_day").val(c)) b.day_id = c;
                                            nid = a(this).attr("id");
                                            nid == "CF_next" || nid == "CF_prev" ? (b.cal = "stick", b.elm = a("#CF_head").length ? "inv.search.cal" : "cal.search") : (b.cal = null, b.elm = "inv.search.cal", a("#CF_head #CF_cal").fadeOut(200));
                                            b.target = g(a("#CF_tabs .CF_a a"));
                                            d(b);
                                            return !1
                                        }
                                    }), a("#CF_I a").click(function () {
                                        a("#CF_items").addClass("CF_dim");
                                        var c = this.hash.replace("#D", "");
                                        if (a("#CF_day").val(c)) b.day_id = c;
                                        d(b);
                                        return !1
                                    })), l(b.target), b.callback && eval(b.callback + "()"), !1
                                }
                            }))
                        }
                        function e(a) {
                            a = a.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
                            a = RegExp("[\\?&]" + a + "=([^&#]*)").exec(window.location.href);
                            return a == null ? "" : a[1]
                        }
                        function g(a) {
                            return i ? a.attr("hash") : a.prop("hash")
                        }
                        function k(b) {
                            a(".CF_unit").hide();
                            a("#CF_len").hide();
                            b || (b = a("#CF_tabs .CF_a").attr("class"));
                            a("#CF_u" + b).hasClass("CF_h") || a("#CF_len").show();
                            a("#CF_u" + b).length ? a("#CF_u" + b).show() : a("#CF_u0").show()
                        }
                        function l(b) {
                            a("#CF_tabs li").removeClass("CF_a");
                            a("#CF_items .CF_item").hide();
                            b == "#CF_B" ? a("#CF_head fieldset").hide() : a("#CF_head fieldset").show();
                            b ? (a("#CF_tabs " + b + "T").addClass("CF_a"), a(b).show()) : (a("#CF_tabs li:first").addClass("CF_a"), a("#CF .CF_item:first").show());
                            b != void 0 ? k(b.replace("#CF_", "")) : (b = a("#CF_tabs .CF_a a").attr("href")) && k(b.replace("#CF_", ""))
                        }
                        function m(b) {
                            a("#CF_B").length ? a("#CF_B").replaceWith(b.booking.html) : (a("#CF_items").append(b.booking.html), a("#CF_tabs").prepend('<li id="CF_BT"><a  href="#CF_B">Booking</a></li>'), window.location.hash = "#CF");
                            typeof b.policy != "undefined" && b.policy.html && a("#CF_B fieldset").append(b.policy.html);
                            a("#CF_clr").click(function () {
                                if (confirm("Remove all items?")) a("#CF_B table .CF_slip").remove(), a("#CF #CF_B").remove(), a("#CF #CF_BT").remove(), h.elm = "inv", d(h);
                                else return !1
                            });
                            a("#CF_B table .CF_slip").click(function () {
                                if (a(this).is(":checked")) if (confirm("Add this item?")) a(this).val(a(this).val() + "R"), a(".CF_optout").remove();
                                else return !0;
                                else if (confirm("Remove this item?")) a("#CF_B").append('<input type="hidden" class="CF_slip CF_optout" name="' + a(this).attr("name") + '" value="' + a(this).val() + '!" />');
                                else return !0;
                                h.target = "#CF_B";
                                h.elm = "inv";
                                d(h);
                                return !1
                            });
                            a("#CF #CF_B").fadeIn();
                            return !0
                        }
                        var f = a("#CF_set").length ? eval("(" + a("#CF_set").val() + ")") : null,
                            h = {
                                url: null,
                                elm: null,
                                version: null,
                                target: null,
                                slip: null,
                                cf_set: f,
                                schema: "http:",
                                cal: null,
                                day_id: null,
                                callback: null,
                                category_id: null,
                                item_id: null
                            };
                        c && a.extend(h, c);
                        d(c);
                        a("#CF form").submit(function () {
							_gaq.push(['_trackPageview', '/paypal-checkout-page/']);
                            var b = g(a("#CF_tabs .CF_a a"));
                            if (b != "#CF_B") return a("#CF_items").addClass("CF_dim"), h.elm = "search.inv.cal", h.target = b, d(h), !1;
                            f && a("#CF_box").append('<input type="hidden" name="CF_mode" name="CF_mode" value="' + f.mode + '" />');
                            a.cookie("CF_ref") && a("#CF_box").append('<input type="hidden" name="CF_ref" id="CF_ref" value="' + a.cookie("CF_ref") + '" />');
                            a.cookie("CF_tid") && a("#CF_box").append('<input type="text" name="CF_tid" id="CF_tid" value="' + a.cookie("CF_tid") + '" />');
                            a("#CF_box").append('<input type="hidden" name="CF_return" name="CF_return" value="' + window.location + '" />');
                            a("#CF_B fieldset").addClass("CF_dim");
                            a("#CF_msg").html('<p class="CF_load">Please wait..</p>');
                            a("#CF_msg").fadeIn();
                            a.ajax({
                                type: "GET",
                                data: a("#CF_box").serialize(),
                                url: a("#CF form").attr("action") + "/book",
                                dataType: "jsonp",
                                success: function (b) {
                                    b.msg ? (a("#CF_msg").html('<p class="' + b.msg.type + '">' + b.msg.str + "</p>"), a("#CF_msg").fadeIn(), a("#CF_B fieldset").removeClass("CF_dim")) : b.book.url ? top.location.href = b.book.url : b.book.html ? (a("#CF").append(b.book.html), a("#CF_ppws").submit()) : a("#CF_items").removeClass("CF_dim")
                                }
                            });
                            return !1
                        });
                        !a.cookie.CF_ref & document.referrer && a.cookie("CF_ref", document.referrer);
                        (c = e("CF_tid")) && a.cookie("CF_tid", c)
                    }
                })(jQuery);
                jQuery("#CF").checkfront({
                    version: CF_version,
                    url: c,
                    set: null,
                    elm: "inv.search.cal"
                })
            }
        }
    })
};
