$(document).ready(function() {
    var page = $('body').attr('id');

    
    if (page == 'videos' || page == 'diagrams' || page == 'sounds') {
        $('select.large_section_filter').change(function (eve) {
            selection = $(this).val();
            window.location = "/" + page + "/browse/" + selection;
        });
        $('select.tag_filter, select.section_filter').change(function (eve) {
            var classes = new Array();
            var selection = '';
            $('select.tag_filter, select.section_filter').each(function () {
                selection = $(this).val();
                if (selection != 'all') {
                    classes.push( selection );
                }
                //alert( $(this).val() );
            });
            
            // Hide all the items
            $("#inner_main .media_list div").removeClass('odd').removeClass('even').hide();
            //console.log( classes);
            if (classes.length > 0) {
                selection = '';
                for (var i = classes.length - 1; i >= 0; i--){
                    selection += "[class*='" + classes[i] + "']";
                };
                //alert(selection);
                $("#inner_main .media_list div" + selection).show();
                $('#result_count').html( $("#inner_main .media_list div." + selection).length );
                var odd = true;
                var class_name = 'even';
                $("#inner_main .media_list div" + selection).each(function () {
                    if (odd) {
                        class_name = 'odd';
                    } else {
                        class_name = 'even';
                    }
                    $(this).addClass( class_name );
                    odd = !odd;
                });
                
            } else {
               $("#inner_main .media_list div").show();
               $('#result_count').html( $("#inner_main .media_list div:visible").length );
                var odd = true;
                var class_name = 'even';
                $("#inner_main .media_list div:visible").each(function () {
                    if (odd) {
                        class_name = 'odd';
                    } else {
                        class_name = 'even';
                    }
                    $(this).addClass( class_name );
                    odd = !odd;
                });
            }
            if ( $("#inner_main .media_list div:visible").length >= 1) {
                $('#none_found').hide();
            } else {
                $('#none_found').show();
            }

                
        });
    
    }
    
    $('#search .search_text').focus(function (eve) {
        var search_text = $(this).val();
        var default_search_text = 'Search Site';
        if (search_text == default_search_text) {
            $(this).val('');
            $(this).removeClass('default');
        } else {
        }
    });
    
});
