/* ======================================================================== */
// IE/win background image flicker fix
// http://evil.che.lu/2006/9/25/no-more-ie6-background-flicker
try { document.execCommand('BackgroundImageCache', false, true); } catch(e) {}
/* ======================================================================== */

// simple return false function
Object.extend(Prototype, { False : function(){ return false; } });
/* ======================================================================== */

// from http://www.vivabit.com/code/domready/domready.js
Object.extend(Event, {
	_domReady : function() {
		if (arguments.callee.done) { return; }
		arguments.callee.done = true;
		if (this._timer) { clearInterval(this._timer); }
		this._readyCallbacks.each(	function(f) { f(); });
		this._readyCallbacks = null;
	},

	onDOMReady : function(f) {
		if (!this._readyCallbacks) {
			var domReady = this._domReady.bind(this);

			if (document.addEventListener) {
				document.addEventListener("DOMContentLoaded", domReady, false);
			}

			/*@cc_on @*/
			/*@if (@_win32)
				document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
				document.getElementById("__ie_onload").onreadystatechange = function() {if (this.readyState == "complete") domReady(); };
			/*@end @*/

			if (/WebKit/i.test(navigator.userAgent)) {
				this._timer = setInterval(function() {
					if (/loaded|complete/.test(document.readyState)) { domReady(); }
				}, 10);
			}

			Event.observe(window, 'load', domReady);
			Event._readyCallbacks =  [];
		}

		Event._readyCallbacks.push(f);
	}
});

/* ======================================================================== */

/* ======================================================================== */

var SFMusic = {

	// global "constants" for HBSP JS
	GLOBALS : {
		accordion_class : "AccordionControl",
        safari: (navigator.userAgent.toLowerCase().indexOf('safari') != -1) ? true : false
    },

	// to enable console debugging, set to true
	DEBUG : false,

	// tiny debug wrapper
	debug : function(msg) {
		// is debugging on?
		if (!this.DEBUG) { return; }

		if (msg instanceof Array) {
			msg = msg.join("\n");
		}
		try {
			console.log(msg);
		} catch(e) {
			alert(msg);
		}
	}, // END: debug()

	// each new "function" goes here
	Features : { },

	// this holds useful utility functions
	Utils : {

	} // END: Utils

}; // END: SFMusic namespace
/* ======================================================================== */


/* -- BEGIN: StyleFormElements ---------------------------------------------- */
Object.extend(SFMusic.Features, {
	StyleFormElements : function() {
        var CONFIG = {
			form_id : "searchForm",
            radio_group: "radio_group",
            check_group: "check_group",
            radio_class : "label_radio",
            radio_OnClass: "r_on",
            radio_OffCass : "r_off",
            price_slider: "track3",
            price_slider_control: "handle3"
        };

        // replace radio button
        var RadioCheckGraphic = Class.create();
        RadioCheckGraphic.prototype ={
			initialize : function(item) {
			
                this.container = $(item);
                // bail out if the form doesn't exist
				if (!this.container) { return false; }
                var radios = this.container.getElementsByClassName(CONFIG["radio_group"]);
                var checkbox = this.container.getElementsByClassName(CONFIG["check_group"]);
                for (var i = 0; i < radios.length; i++) {
                    $A(radios[i].getElementsByTagName("label")).each(function(f_label){
                        var f_input = $(f_label.htmlFor);
                        if(f_input){
                            if(f_input.checked) {
                               f_label.addClassName('r_on');
                            } else {
                               f_label.addClassName('r_off');
                            }
                            Event.observe(f_label, "click", this.turn_radio.bind(this), false);
						    f_label.onclick = Prototype.False;
                        }
					}.bind(this));
                };
                for (var i = 0; i < checkbox.length; i++) {
                    $A(checkbox[i].getElementsByTagName("label")).each(function(f_label){
                        var f_input = $(f_label.htmlFor);
                        if(f_input){
                            f_input.addClassName("check");
                            if(f_input.checked) {
                               f_label.addClassName('chk_on');
                            } else {
                               f_label.addClassName('chk_off');
                            }
                            Event.observe(f_label, "click", this.turn_check.bind(this), false);
						    f_label.onclick = Prototype.False;
                        }
					}.bind(this));
                };
            }, // END: initialize()

			// form element container
			container : null,
			
            turn_radio: function(e) {
                Event.stop(e);
                var f_label = Event.element(e);
                var f_input = $(f_label.htmlFor);
                if(!f_input) return;
                if (f_label.hasClassName("r_off") || f_input.checked) {
                    var labels = f_label.parentNode.parentNode.parentNode.getElementsByTagName("label");
                    for (var i = 0; i < labels.length; i++) {
                        var l = labels[i];
                        l.removeClassName("r_on");
                        l.addClassName("r_off");
                    }
                    f_label.removeClassName("r_off");
                    f_label.addClassName("r_on");
                    if (SFMusic.GLOBALS["safari"]) f_input.checked = true;
                } else {
                    f_label.removeClassName("r_on");
                    f_label.addClassName("r_off");
                    if (SFMusic.GLOBALS["safari"]) f_input.checked = false;
                };
            },

            turn_check: function(e) {
                Event.stop(e);
                var f_label = Event.element(e);
                var f_input = $(f_label.htmlFor);
                if(!f_input) return;
                if (f_label.hasClassName("chk_off") || f_input.checked) {
                    f_label.removeClassName("chk_off");
                    f_label.addClassName("chk_on");
                    if (SFMusic.GLOBALS["safari"]) f_input.checked = true;
                } else {
                    f_label.removeClassName("chk_on");
                    f_label.addClassName("chk_off");
                    if (SFMusic.GLOBALS["safari"]) f_input.checked = false;
                };
            }

        }; // END: Carousel

        return {
            // sets up the vertical carousel for all the ListWidgets in Tabs on the page
			initialize : function() {
                this.form_elements.push(new RadioCheckGraphic(CONFIG['form_id']));
            }, // END: initialize()

			// keeps track of the carousels we created
			form_elements : []

        };

	}()
});
/* ------------------------------------------------ END: StyleFormElements -- */

/* -- BEGIN: Accordion --------------------------------------------- */
Object.extend(SFMusic.Features, {
	AccordionNavigation : function() {
		var CONFIG = {
			accordion_class : "AccordionNavControl",
            accordion_content : "MainContent",
            exp_class: "EventDetailsSelected",
            exp_img: "img/icon.expand.gif",
            col_img : "img/icon.col.gif"
        };


		return {
			initialize : function() {

                // loop through all of the magnifying glass icons
                $$("IMG." + CONFIG["accordion_class"]).each(function(item){
                    if(!item.id) {return;}
                    // verify that the magnifying glass has an associated detail to show
                    var details = $(item.id + "_details");
					if (!details) { return; }
                    // hook up the event handlers
                    Event.observe(item, 'click', this.toggleDetail.bind(this, details), false);

                }.bind(this));
            }, // END: initialize()

			toggleDetail : function(el) {
                el.toggle();
                var navControl = el.id.split("_");
                var iconImg = $(navControl[0]);
                if(!iconImg) {return ;}
                var toggleImg = new Image();
                if (Element.visible(el)){
                    Element.addClassName(iconImg.parentNode.parentNode, CONFIG["exp_class"]);
                    toggleImg.src = CONFIG["col_img"];
                } else {
                    iconImg.parentNode.parentNode.removeClassName(CONFIG["exp_class"]);
                    toggleImg.src = CONFIG["exp_img"];
                }
                iconImg.src = toggleImg.src;
            }

		}; // END: return

	}()
});
/* ----------------------------------------------- END: Accordion -- */

/* BEGIN: CALENDAR */


Event.onDOMReady(function() {
    // the order in which the Features are enabled
	var order = [
	   "StyleFormElements",
       "AccordionNavigation"
    ];

	// this allows us to customize the order with the least amount of redundancy
	// and the most amount of customizabilty :)
	order.each(function(name){
		// check and see if the Feature is "installed"
		if ((typeof(SFMusic.Features[name]) != 'undefined') &&	SFMusic.Features[name].initialize) {
			SFMusic.Features[name].initialize();

		// alert the developer if debugging is on
		} else {
			SFMusic.debug("onDOMReady: " + name + " not found in SFMusic.Features");
		}
	});
}); // END: onDOMReady




/*
 =============================================== radio button function ===============================
*/
/*
var d = document;
var safari = (navigator.userAgent.toLowerCase().indexOf('safari') != -1) ? true : false;
var gebtn = function(parEl,child) { return parEl.getElementsByTagName(child); };

function InitRadio() {
    if(!d.getElementById || !d.createTextNode) return;
    var ls = gebtn(d,'label');
    for (var i = 0; i < ls.length; i++) {
        var l = ls[i];
        if (l.className.indexOf('label_') == -1) continue;
        var inp = d.getElementById(l.htmlFor);
        if (l.className == 'label_check') {
            l.className = (safari && inp.checked == true || inp.checked) ? 'label_check c_on' : 'label_check c_off';
            l.onclick = check_it;
        };
        if (l.className == 'label_radio') {
            l.className = (safari && inp.checked == true || inp.checked) ? 'label_radio r_on' : 'label_radio r_off';
            l.onclick = turn_radio;
        };
    };
};
var check_it = function() {
    var inp = d.getElementById(this.htmlFor);
    if (this.className == 'label_check c_off' || (!safari && inp.checked)) {
        this.className = 'label_check c_on';
        if (safari) inp.checked = true;
    } else {
        this.className = 'label_check c_off';
        if (safari) inp.checked = false;
    };
};
var turn_radio = function() {
    var inp = d.getElementById(this.htmlFor);
    if (this.className == 'label_radio r_off' || inp.checked) {
        var ls = gebtn(this.parentNode.parentNode.parentNode,'label');
        for (var i = 0; i < ls.length; i++) {
            var l = ls[i];
            if (l.className.indexOf('label_radio') == -1)  continue;
            l.className = 'label_radio r_off';
        };
        this.className = 'label_radio r_on';
        if (safari) inp.checked = true;
    } else {
        this.className = 'label_radio r_off';
        if (safari) inp.checked = false;
    };
};

*/