var Search =
{
	baseUrl: null,

	init: function()
	{
		Search.baseUrl = location.protocol + '//' + location.hostname + '/';
		var url = location.pathname;
		if (location.hostname == 'devsys2.gaslightmedia.com') {
			var urlParts = url.split('/');
			Search.baseUrl += urlParts[1] + '/';
		} else if (location.hostname == 'kanga.acrewoods.com') {
			var site = location.pathname.split('/');
			var urlParts = url.split('/');
			Search.baseUrl += urlParts[1] + '/' + site[2] + '/';
		}

		$('.search-result-item').bind('mouseover', Search.highlightMember);
		$('.search-result-item').bind('mouseout', Search.lowlightMember);
		$('.search-result-item').bind('click', Search.goToMember);
		$("select[name='category_id']").bind('change', Search.populateMemberSubType);
	},

	highlightMember: function(event)
	{
		$(this).addClass('search-result-item-on');
	},

	lowlightMember: function(event)
	{
		$(this).removeClass('search-result-item-on');
	},

	goToMember: function(event)
	{
		var link = $(this).find("a[title='More Info']");
		document.location.href = link.attr('href');
	},

    populateMemberSubType: function(event)
    {
        // need to get the sub cats from the one selected
        // show me what I selected
        var id;
        $("select[name='category_id'] option:selected").each(function(){
            id = $(this).val();
        });
        // if id is empty then reset the sub_category_id select
        // or just reset the sub_category_id to empty
        $("select[name='sub_category_id']").empty();
        // Let's create an array in the display of the page that will contain all the elements for the sub cat levels
        // called subCatArray
        $("select[name='sub_category_id']").append('<option value="">-- Select --</option>');
        jQuery.each(MY_AR[id], function(val, name){
            $("select[name='sub_category_id']").append('<option value="'+val+'">'+name+'</option>');
        });
    }
};

$(document).ready(Search.init);
