jQuery.fn.alternateStripes = function () {
    var $elems = this.add(this.siblings());
    
    $elems.filter(':odd').removeClass('even').addClass('odd');
    $elems.filter(':even').removeClass('odd').addClass('even');
    return this;
};

var MRUtils = {
    init: function () {
        $j('body').addClass('js');
        this.searchLabel($j('#CAT_Search','#catsearchform72352')); 
        this.formatSpecs();
        this.setErrorStyle();
        $j('#survey_form:visible') ? $j('#survey_form').data('state','inactive') : $j('#survey_form').data('state','active');
        $j('#survey_tab').click(function (e) {
            if ($j('#survey_form').data('state') === 'inactive') {
                $j(this).hide();
                $j('#survey_form')
                    .data('state','active')
                    .animate({
                        opacity:'show',
                        width:'450px'
                        },600);
                return false;
            }
        });
        $j('a.close','#survey_form').click(function (e) {
            if ($j('#survey_form').data('state') === 'active') {
                $j('#survey_form')
                    .data('state','inactive')
                    .animate({
                        opacity:'hide',
                        width:0
                        },600,function() {
                            $j('#survey_tab').fadeIn();
                        });
            }
        });
    },
    
    searchLabel: function (e) {
        if (e.length) {
            if (e.val() === '') {
                e.val('Search');
            }
            e.blur(function () {
                if (e.val() === '') {
                    e.val('Search');
                }
            });
            e.focus(function () {
                if (e.val() === 'Search') {
                    e.val('');
                }
            });
        }
    },
    
    formatSpecs : function () {
        $j('tbody tr td:first-child,tbody tr th:first-child','table.specifications').addClass('first');
    },
    
    setErrorStyle : function (e) {
        if ($j('.f_error').length > 0 && $j('.f_error').html() !== '') $j('.f_error').addClass('error');
    }
};

jQuery(function () {
    if ($j('#accreditation_list').length > 0) {
        $j('#iso,#carbon_neutral,#community,#yrs_exp').dialog({
			bgiframe: true,
			width: 400,
			modal: true,
			autoOpen: false
		});
		$j('#accreditation_list').click(function (e) {
		    var target = $j(e.target).parent().attr('class');

		    switch (target) {
		        case 'iso':
		            $j('#iso').dialog('open');
		            break;
		        case 'carbon':
		            $j('#carbon_neutral').dialog('open');
		            break;
		        case 'community':
		            $j('#community').dialog('open');
		            break;
		        case 'yrs_exp':
		            $j('#yrs_exp').dialog('open');
		            break;
		        default:
		            break;
		    }
		});
    }
    MRUtils.init();
});