/*
	---------------------
	** REQUIRES jQuery **
	---------------------
	
	includes scripts to:
		+ add functionality to allow text boxes a default value that will be cleared on focus (ie. 'Search...')
		+ equalize the heights of elements matching the given selector rules

*/


var iomer = {
    searchDefault: 'Search...', // default value for search boxes if initialized

    equalizePanels: function(selector) {
        if (selector === '') return;

        var maxHeight = 0;
        $(selector).each(function() {
            var panelHeight = $(this).height();
            maxHeight = panelHeight > maxHeight ? panelHeight : maxHeight;
        });
        $(selector).height(maxHeight);
    },

    initSearchText: function(selector, defValue) {
        // example selectors to pass in: .searchText, .sf_searchText
        if (selector === '') return;
        defValue = defValue || iomer.searchDefault;

        $(selector).focus(function() {
            $(this).attr({ value: '' });
        })
		.blur(function() {
		    if ($(this).attr('value') == '') {
		        $(this).attr({ value: defValue });
		    }
		})
		.attr({ value: defValue });
    },

    featureControl: {
        controlSelector:    '.IFP_link',
        controlIDPrefix:    '#IFP_link',
        featureSelector:    '.IFP_feature',
        featureIDPrefix:    '#IFP_feature',
        fShowing:           'IFP_showingFeature',
        cSelected:          'IFP_selected',

        init: function() {

            /* attach onclick events to all controls */
            $(iomer.featureControl.controlSelector).click(function(e) {
                e.preventDefault();
                var index = this.id.match(/[\d]+$/)[0];
                if (index !== null) {
                    // remove selected control class and add it to the new item.
                    $('.'+iomer.featureControl.cSelected).removeClass(iomer.featureControl.cSelected);
                    $(this).addClass(iomer.featureControl.cSelected);

                    $('.'+iomer.featureControl.fShowing).removeClass(iomer.featureControl.fShowing).fadeOut('slow');
                    $(iomer.featureControl.featureIDPrefix + index).addClass(iomer.featureControl.fShowing).fadeIn('slow');
                }
            });
            /* assign first as selected */
            $(iomer.featureControl.controlIDPrefix + '0').addClass(iomer.featureControl.cSelected);
            $(iomer.featureControl.featureIDPrefix + '0').addClass(iomer.featureControl.fShowing).fadeIn('slow');
        }
    }
};