var RatingSystem = new Class({
    options: {
        RateElement: ".rate"
    },
    initialize: function(){
        var b = $$(this.options.RateElement);
        var a = new Array();
        b.each(function(d, c){
            d.addEvent("click", function(){
                a = ["no_star", "one_star", "two_star", "three_star", "four_star", "five_star"];
                a.each(function(e){
                    if (d.getParent().hasClass(e)) {
                        d.getParent().removeClass(e)
                    }
                });
                a.each(function(f, e){
                    if (e == d.id) {
                        d.getParent().toggleClass(f)
                    }
                })
            })
        })
    }
});
var moopop = {
    width: 0,
    height: 0,
    captureByRel: function(a, b){
        this.capture((b || document).getElements("a[rel*=" + (a || "popup") + "]"))
    },
    capture: function(c, b, a){
        if ($defined(b) && $defined(a)) {
            this.width = b;
            this.height = a
        }
        switch ($type(c)) {
            case "string":
                c = $$(c);
            case "element":
            case "array":
                $splat(c).each(this.add_pop_to, this)
        }
        this.width = null;
        this.height = null
    },
    add_pop_to: function(c){
        c.addEvent("click", function(d){
            d.stop();
            this.popup(c)
        }
.bind(this));
        var b = c.get("rel").match(/\[(\d+),\s*(\d+)/) || ["", this.width, this.height];
        var a = c.get("rel").match(/,(r)/) || [];
        if (b[1]) {
            c.store("popupprops", "top=0, left=0, scrollbars=yes, width=" + b[1] + ", height=" + b[2] + (a[1] ? ", scrollbars=yes, resizable=yes" : ""))
        }
    },
    popup: function(a){
        window.open(a.get("href"), a.get("name") || "", a.retrieve("popupprops") || "")
    }
};
window.addEvent("domready", function(){
    moopop.captureByRel("popup")
});
var InputClearAndReplace = new Class({
    options: {
        InputElement: ".clear_replace"
    },
    initialize: function(){
        var b = $$(this.options.InputElement);
        var a = new Array();
        b.each(function(d, c){
            a.push(b[c].value);
            d.onfocus = function(){
                if (this.value == a[c]) {
                    this.value = ""
                }
            }, d.onblur = function(){
                if (this.value == "") {
                    this.value = a[c]
                }
            }
        })
    }
});
var CharCount = new Class({
    initialize: function(){
        var d = $$(".char_limit");
        var c = $$(".char_count");
        for (i = 0; i < d.length; i++) {
            var a = Number(d[i].get("label"));
            var b = c[i];
            d[i].addEvent("keydown", this.onKeyPress.bindWithEvent(this, [d[i], a, b]));
            d[i].addEvent("keyup", this.onKeyPress.bindWithEvent(this, [d[i], a, b]));
            this.updateCount(d[i], a, b)
        }
    },
    onKeyPress: function(c, d, a, b){
        c = new Event(c);
        if (!c.shift && !c.control && !c.alt && !c.meta) {
            this.updateCount(d, a, b)
        }
    },
    updateCount: function(e, a, c){
        if (e.value.length > a) {
            e.value = e.value.substring(0, a)
        }
        var d = a - e.value.length;
        if (d == 1) {
            var b = "1 character left"
        }
        else {
            var b = d + " characters left"
        }
        c.set("html", b)
    }
});
var CalendarSlider = new Class({
    options: {
        Items: "#slide_cal li",
        ItemMargin: 3,
        Group: "slide_cal",
        PerPage: 7
    },
    initialize: function(){
        var h = $$(this.options.Items);
        var b = this.options.ItemMargin;
        var m = $(this.options.Group);
        var e = h.length * (h[1].getSize().x + b);
        m.setStyle("width", e);
        var k = this.options.PerPage;
        var c = Math.ceil(h.length / k);
        var g = 1;
        var l = (h[1].getSize().x + b) * k;
        var j = "forward";
        var a = new Fx.Scroll("dates_wrap", {
            duration: 500,
            transition: Fx.Transitions.Expo.easeInOut,
            onStart: function(){
                if (j == "forward") {
                    g < c ? g++ : g = 1
                }
                if (j == "backward") {
                    g > 1 ? g-- : g = 1
                }
            },
            onComplete: function(){
            }
        });
        a.toLeft();
        g = 1;
        var d = $("dates_prev");
        var f = $("dates_next");
        if (g == 1) {
            d.fade(0.3)
        }
        else {
            d.fade(1)
        }
        if (g == c) {
            f.fade(0.3)
        }
        else {
            f.fade(1)
        }
        d.addEvent("click", function(n){
            n = new Event(n).stop();
            j = "backward";
            if (g > 1) {
                a.start((g - 2) * l, 0)
            }
            if (g == 1) {
                d.fade(0.3)
            }
            else {
                d.fade(1)
            }
            if (g == c) {
                f.fade(0.3)
            }
            else {
                f.fade(1)
            }
        });
        f.addEvent("click", function(n){
            n = new Event(n).stop();
            j = "forward";
            if (g < c) {
                a.start(g * l, 0)
            }
            if (g == 1) {
                d.fade(0.3)
            }
            else {
                d.fade(1)
            }
            if (g == c) {
                f.fade(0.3)
            }
            else {
                f.fade(1)
            }
        })
    }
});
window.addEvent("load", function(){
    if ($("slide_cal")) {
        var a = new CalendarSlider()
    }
});
function initEventCalTips(){
    $$("a.cal_tip").each(function(c, b){
        var d = c.get("title").replace(/::/g, "<br / >");
        c.store("tip:title", d)
    });
    var a = new Tips(".cal_tip", {
        className: "cal_tip_wrap",
        hideDelay: 50,
        showDelay: 50
    })
}

function showVenues(){
    $("show_venues").addEvent("click", function(){
        $("venue_list").setStyle("display", "block")
    })
}

function initMultimedia(){
    $("expand").addEvent("click", function(){
        this.setStyle("display", "none");
        $("close").setStyle("display", "inline");
        expandMediaComments()
    });
    $("close").addEvent("click", function(){
        this.setStyle("display", "none");
        $("expand").setStyle("display", "inline");
        collapseMediaComments()
    });
    $("add_comment").addEvent("click", function(){
        $("media_info").setStyle("display", "none");
        $("media_add_comment").setStyle("display", "inline")
    });
    $("close_comment").addEvent("click", function(){
        $("media_add_comment").setStyle("display", "none");
        $("media_info").setStyle("display", "inline")
    })
}

function expandMediaComments(){
    $("media_details").setStyle("display", "none");
    $("comments_rating_wrap").setStyle("height", "294px");
    $("comments_outter_wrap").setStyle("height", "235px");
    $("comments_wrap").setStyle("height", "235px")
}

function collapseMediaComments(){
    $("media_details").setStyle("display", "block");
    $("comments_rating_wrap").setStyle("height", "148px");
    $("comments_outter_wrap").setStyle("height", "114px");
    $("comments_wrap").setStyle("height", "114px")
}

function initMediaForm(){
    $("media_type").addEvent("change", function(){
        var b = $$("#media_swap .form_data");
        for (var c = 0; c < b.length; c++) {
            b[c].setStyle("display", "none")
        }
        if (this.value != "empty") {
            var a = "upload_" + this.value;
            var d = $(a).setStyle("display", "block")
        }
    })
}

function initBandForm(){
    $("input_show_contact").addEvent("change", function(){
        if (this.value == "yes") {
            $("band_contact_info").setStyle("display", "block")
        }
        else {
            $("band_contact_info").setStyle("display", "none")
        }
    })
}

function initMediaTabs(){
    var a = $("media_nav").getElements("a");
    for (var b = 0; b < a.length; b++) {
        if (a[b].getAttribute("href") && a[b].getAttribute("rel") == "swap") {
            a[b].addEvent("click", function(){
                for (var c = 0; c < a.length; c++) {
                    a[c].removeClass("active")
                }
                swapMediaContent(this.id)
            })
        }
    }
}

function swapMediaContent(d){
    $(d).addClass("active");
    var c = $$(".media_types");
    for (var b = 0; b < c.length; b++) {
        c[b].setStyle("display", "none")
    }
    var a = "content_" + d;
    var e = $(a).setStyle("display", "block")
}

function initScreenTabs(){
    var a = $("showtimes_listings_nav").getElements("a");
    for (var b = 0; b < a.length; b++) {
        if (a[b].getAttribute("href") && a[b].getAttribute("rel") == "swap") {
            a[b].addEvent("click", function(){
                for (var c = 0; c < a.length; c++) {
                    a[c].removeClass("active")
                }
                swapScreenContent(this.id)
            })
        }
    }
}

function swapScreenContent(d){
    $(d).addClass("active");
    var c = $$(".showtimes_listings");
    for (var b = 0; b < c.length; b++) {
        c[b].setStyle("display", "none")
    }
    var a = "content_" + d;
    var e = $(a).setStyle("display", "block")
}

function initDrinkTabs(){
    var a = $("drink_filter").getElements("a");
    for (var b = 0; b < a.length; b++) {
        if (a[b].getAttribute("href") && a[b].getAttribute("rel") == "swap") {
            a[b].addEvent("click", function(){
                for (var c = 0; c < a.length; c++) {
                    a[c].removeClass("active")
                }
                swapDrinkContent(this.id)
            })
        }
    }
}

function swapDrinkContent(d){
    $(d).addClass("active");
    var c = $$("#filter_stories .additional_story");
    for (var b = 0; b < c.length; b++) {
        c[b].setStyle("display", "none")
    }
    var a = "content_" + d;
    var e = $(a).setStyle("display", "block")
}

function initBizForm(){
    $("input_biz_status").addEvent("change", function(){
        if (this.value == "Opening") {
            $("biz_opening_date").setStyle("display", "block")
        }
        else {
            $("biz_opening_date").setStyle("display", "none")
        }
    });
    $("input_multiple").addEvent("change", function(){
        if (this.value == "yes") {
            addBizLocation();
            $("btn_add_location").setStyle("display", "block")
        }
    });
    $("btn_add_location").addEvent("click", function(){
        addBizLocation()
    })
}

function addBizLocation(){
    var lastLocation = $("add_location_wrap").getLast().getProperty("id");
    var i = parseInt(lastLocation.split("_")[1]) + 1;
    var newLocation = $("location_0").clone();
    newLocation.setProperty("id", "location_" + eval(i));
    var temp = newLocation.innerHTML.replace(/input_location_phone_0/g, "input_location_phone_" + eval(i));
    newLocation.innerHTML = temp;
    var temp = newLocation.innerHTML.replace(/input_location_address_0/g, "input_location_address_" + eval(i));
    newLocation.innerHTML = temp;
    var temp = newLocation.innerHTML.replace(/input_location_city_0/g, "input_location_city_" + eval(i));
    newLocation.innerHTML = temp;
    var temp = newLocation.innerHTML.replace(/input_location_state_0/g, "input_location_state_" + eval(i));
    newLocation.innerHTML = temp;
    var temp = newLocation.innerHTML.replace(/input_location_zip_0/g, "input_location_zip_" + eval(i));
    newLocation.innerHTML = temp;
    var temp = newLocation.innerHTML.replace(/input_location_nieghborhood_0/g, "input_location_nieghborhood_" + eval(i));
    newLocation.innerHTML = temp;
    newLocation.injectAfter($(lastLocation));
    newLocation.setStyle("display", "block")
}

function initRealEstateTabs(){
    var a = $("real_estate_search_nav").getElements("a");
    for (var b = 0; b < a.length; b++) {
        if (a[b].getAttribute("href") && a[b].getAttribute("rel") == "swap") {
            a[b].addEvent("click", function(){
                for (var c = 0; c < a.length; c++) {
                    a[c].removeClass("active")
                }
                swapRealEstateContent(this.id)
            })
        }
    }
}

function initRealEstateSearch(){
    var b = $("advanced_top").getElements("input");
    for (var a = 0; a < b.length; a++) {
        b[a].addEvent("click", function(){
            if (this.value == "Commercial") {
                $("input_bedrooms").setProperty("disabled", "disabled");
                $("input_bathrooms").setProperty("disabled", "disabled")
            }
            else {
                $("input_bedrooms").removeProperty("disabled", "disabled");
                $("input_bathrooms").removeProperty("disabled", "disabled")
            }
        })
    }
}

function swapRealEstateContent(d){
    $(d).addClass("active");
    var c = $$(".real_estate_search");
    for (var b = 0; b < c.length; b++) {
        c[b].setStyle("display", "none")
    }
    var a = "content_" + d;
    var e = $(a).setStyle("display", "block")
}

function addRealEstateArea(e, c, a){
    var d = $("advanced_search").getElement("select.input_selected_neighborhoods");
    if (d) {
        var b = "Loc_" + e;
        if (!($(b))) {
            var f = new Element("option", {
                id: b,
                value: c,
                html: a
            });
            d.grab(f, "bottom")
        }
    }
}

function removeRealEstateArea(c){
    var b = $("advanced_search").getElement("select.input_selected_neighborhoods");
    if (b) {
        var a = $("Loc_" + c);
        if (a) {
            a.dispose()
        }
    }
}

function getMovieName(a){
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[a]
    }
    else {
        return document[a]
    }
}

function initSelectAll(){
    $("select_all").addEvent("click", function(a){
        window.InteractiveMap = document.forms[0].InteractiveMap;
        $("InteractiveMap").selectAll();
        a.stop()
    })
}

function initRemoveAll(){
    $("remove_all").addEvent("click", function(a){
        window.InteractiveMap = document.forms[0].InteractiveMap;
        $("InteractiveMap").clearAll();
        a.stop()
    })
}

function initRemoveSelected(){
    $("removeNeighborhood").addEvent("click", function(c){
        var b = $("advanced_search").getElement("select.input_selected_neighborhoods");
        window.InteractiveMap = document.forms[0].InteractiveMap;
        for (var a = 0; a < b.options.length; a++) {
            if (b.options[a].selected) {
                $("InteractiveMap").removeArea(b.options[a].value)
            }
        }
        c.stop()
    })
}

function realEstateMapSubmit(a){
    var b = a.getElement("select.input_selected_neighborhoods");
    if (b.length > 0) {
        for (i = 0; i < b.length; i++) {
            b.options[i].selected = "selected"
        }
    }
    return true
}

function launchEvent(a){
    $("EventDay").loadDay(a)
}

function initEventAdvancedSearch(){
    $("event_advanced_toggle").addEvent("click", function(){
        $("advanced_search").toggleClass("hide")
    });
    $("input_neighborhood").addEvent("change", function(){
        if (this.value != "empty") {
            $("input_zip").setProperty("disabled", "disabled");
            $("input_zip").value = "disabled"
        }
        else {
            $("input_zip").removeProperty("disabled");
            $("input_zip").value = ""
        }
    });
    $("input_zip").addEvent("click", function(){
        $("input_neighborhood").setProperty("disabled", "disabled")
    });
    $("input_zip").addEvent("blur", function(){
        if (this.value == "") {
            $("input_neighborhood").removeProperty("disabled")
        }
    })
}

function initPopularContent(){
    var a = $("popular_head").getElements("a");
    for (var b = 0; b < a.length; b++) {
        if (a[b].getAttribute("href") && a[b].getAttribute("rel") == "swap") {
            a[b].addEvent("click", function(){
                for (var c = 0; c < a.length; c++) {
                    a[c].removeClass("active")
                }
                swapPopularContent(this.id)
            })
        }
    }
}

function swapPopularContent(d){
    $(d).addClass("active");
    var c = $$(".article_list");
    for (var b = 0; b < c.length; b++) {
        c[b].setStyle("display", "none")
    }
    var a = "content_" + d;
    var e = $(a).setStyle("display", "block");
    var f = $("popular_head").getElement("h4");
    if (d == "most_popular") {
        f.set("html", "MOST POPULAR ARTICLES >")
    }
    else {
        if (d == "most_commented") {
            f.set("html", "MOST COMMENTED ARTICLES >")
        }
        else {
            f.set("html", "MOST EMAILED ARTICLES >")
        }
    }
}

function ie6NavFix(){
    var a = $("nav").getElements("li");
    for (i = 0; i < a.length; i++) {
        if (a[i].getAttribute("rel") == "menu") {
            var d = a[i].getLast("div");
            a[i].addClass("over");
            var c = $(d).getCoordinates(a[i]);
            a[i].removeClass("over");
            var b = new Element("iframe");
            b.set("frameBorder", "0");
            b.set("scrolling", "no");
            b.set("src", "");
            b.set("styles", {
                display: "none",
                position: "absolute",
                "z-index": "100",
                width: c.width,
                height: c.height,
                top: c.top,
                left: c.left
            });
            b.inject(d, "after");
            a[i].setStyle("z-index", "1000");
            a[i].addEvent("mouseover", function(){
                this.addClass("over");
                this.getLast("iframe").setStyle("display", "block")
            });
            a[i].addEvent("mouseout", function(){
                this.removeClass("over");
                this.getLast("iframe").setStyle("display", "none")
            })
        }
    }
}

function navMenuHover(){
    var a = $("nav").getElements("li");
    for (i = 0; i < a.length; i++) {
        if (a[i].getAttribute("rel") == "menu") {
            a[i].getLast().addEvent("mouseover", function(){
                this.getPrevious().addClass("menu_active")
            });
            a[i].getLast().addEvent("mouseout", function(){
                this.getPrevious().removeClass("menu_active")
            })
        }
    }
}

function getTimeStamp(){
    var d = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
    var b = new Date();
    var c = b.getYear();
    var a = b.getHours();
    var h = b.getMinutes();
    var g = "am";
    var f = "";
    if (c < 1000) {
        c += 1900
    }
    if (a >= 12) {
        a -= 12;
        g = "pm"
    }
    if (a == 0) {
        a = 12
    }
    var e = d[b.getMonth()] + " " + b.getDate() + ", " + c;
    e += " at " + a + ":" + ((h < 10) ? "0" : "") + h + g;
    return e
}

function showEditorialComment(){
    var e = "Brandon Gray";
    var k = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam vel metus. Curabitur pulvinar augue eget mauris. Phasellus vel risus. Nunc pulvinar ligula at dolor. Praesent hendrerit tempor magna. Phasellus purus. Sed mauris. Mauris sodales tincidunt diam. Quisque rutrum.";
    var b = false;
    var j;
    var n;
    var h = getTimeStamp();
    var o = document.getElementById("add_comment");
    var l = o.getElementsByTagName("div");
    for (i = 0; i < l.length; i++) {
        l[i].setStyle("display", "none")
    }
    var g = document.createElement("p");
    g.innerHTML = "Thank you, your comment has been added.";
    o.setAttribute("style", "height: 250px;");
    o.appendChild(g);
    if (k != "") {
        if (!b) {
            if (e == "") {
                e = "Anonymous"
            }
            var d = document.getElementById("comments");
            var m = document.createElement("div");
            m.setAttribute("class", "comment clear");
            var a = document.createElement("p");
            a.setAttribute("class", "author");
            a.innerHTML = "<strong>" + e + " said...</strong> on " + h;
            var f = document.createElement("p");
            f.innerHTML = "&#8220;" + k + "&#8221;";
            var c = document.createElement("div");
            c.setAttribute("class", "rule");
            m.appendChild(a);
            m.appendChild(f);
            d.appendChild(m);
            d.appendChild(c)
        }
        else {
            g.innerHTML = "Comment has been sent for approval"
        }
    }
}

function showMMComment(){
    var c = "Brandon Gray";
    var k = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam vel metus. Curabitur pulvinar augue eget mauris. Phasellus vel risus. Nunc pulvinar ligula at dolor. Praesent hendrerit tempor magna. Phasellus purus. Sed mauris. Mauris sodales tincidunt diam. Quisque rutrum.";
    var a = true;
    var j;
    var l;
    var m = document.getElementById("media_add_comment");
    var d = m.getElementsByTagName("form")[0];
    d.setStyle("display", "none");
    var h = document.createElement("p");
    h.innerHTML = "Thank you, your comment has been added.";
    m.appendChild(h);
    if (k != "") {
        if (!a) {
            if (c == "") {
                c = "Anonymous"
            }
            var b = document.getElementById("comments_wrap");
            var n = b.getElementsByTagName("ul")[0];
            var g = document.createElement("li");
            g.setAttribute("class", "clear");
            var f = document.createElement("div");
            f.setAttribute("class", "num");
            f.innerHTML = "&nbsp;";
            var e = document.createElement("p");
            e.innerHTML = "<span>" + c + " said...</span><br />";
            e.innerHTML += k;
            g.appendChild(f);
            g.appendChild(e);
            n.appendChild(g)
        }
        else {
            h.innerHTML = "Comment has been sent for approval"
        }
    }
}

window.addEvent("load", function(){
    if (document.all && !window.opera && !window.XMLHttpRequest) {
        ie6NavFix()
    }
    navMenuHover();
    BlasterBox.assign($$("a.boxed"), {
        parse: "rel"
    });
    if ($("popular_articles")) {
        initPopularContent()
    }
    if ($("event_cal")) {
        initEventCalTips()
    }
    if ($("drink_filter")) {
        initDrinkTabs()
    }
    if ($("media_player_wrap")) {
        initMultimedia()
    }
    if ($("media_nav")) {
        initMediaTabs()
    }
    if ($("media_swap")) {
        initMediaForm()
    }
    if ($("band_contact_info")) {
        initBandForm()
    }
    if ($("business_swap")) {
        initBizForm()
    }
    if ($("real_estate_search_nav")) {
        initRealEstateTabs();
        initRealEstateSearch()
    }
    if ($("event_advanced_toggle")) {
        initEventAdvancedSearch()
    }
    if ($("input_date")) {
        myCal = new Calendar({
            input_date: "m/d/Y"
        }, {
            direction: 1
        })
    }
    if ($("input_date_to")) {
        myCal = new Calendar({
            input_date_to: "m/d/Y"
        }, {
            direction: 1
        })
    }
    if ($("input_date_from")) {
        myCal = new Calendar({
            input_date_from: "m/d/Y"
        }, {
            direction: 1
        })
    }
    if ($("input_sale_start_date")) {
        myCal = new Calendar({
            input_sale_start_date: "m/d/Y"
        }, {
            direction: 1
        })
    }
    if ($("input_sale_end_date")) {
        myCal = new Calendar({
            input_sale_end_date: "m/d/Y"
        }, {
            direction: 1
        })
    }
    if ($("show_venues")) {
        showVenues()
    }
    if ($("select_all")) {
        initSelectAll()
    }
    if ($("remove_all")) {
        initRemoveAll()
    }
    if ($("removeNeighborhood")) {
        initRemoveSelected()
    }
    var c = new RatingSystem();
    var a = new InputClearAndReplace();
    if ($$(".char_limit").length != 0) {
        var b = new CharCount()
    }
});
