jQuery(document).ready(function() {
    //If either of the popups are already active, set them to hide after 5 and a half seconds
    if (jQuery("#manufacturer_popup").css("display") == "block")
        setTimeout('jQuery("#manufacturer_popup").toggle();', 5500);
    if (jQuery("#type_popup").css("display") == "block")
        setTimeout('jQuery("#type_popup").toggle();', 5500);
    
    //When someone clicks on a disabled filter, display the popup message
    jQuery(".filterPopupLink").click(function(event) {
        //Pull the id of which popup was clicked
        box_name = jQuery(this).attr("id");
        box_name = box_name.substr(0, box_name.indexOf("_"));
        //Only toggle it and set the toggle timeout if it's not already showing
        if (jQuery("#" + box_name + "_popup").css("display") == "none")
        {
            jQuery("#" + box_name + "_popup").toggle();
            setTimeout('jQuery("#" + box_name + "_popup").toggle();', 5500);
        }
    });
    
    //Open the attribute pop-up window when a filter link is clicked on (external function)
    jQuery("[id^='attribute_filter_boxes_']").click(function(event) {
        box_id = jQuery(this).attr("id").split("_");
        if (select_tab)
        {
            jQuery('#attribute_search').show();
            select_tab(box_id[3]);
        }
        return false;
    });
    
    //Show hover-over popup for truncated names
    jQuery("[id^='manufacturer_link_hover_'], [id^='type_link_hover_']").mouseover(function(event) {
        link_id = jQuery(this).attr("id").split("_");
        jQuery("#hover_box_" + link_id[3]).css("visibility", "visible");
    });

    //Hide hover-over popup for truncated names
    jQuery("[id^='manufacturer_link_hover_'], [id^='type_link_hover_']").mouseout(function(event) {
        link_id = jQuery(this).attr("id").split("_");
        jQuery("#hover_box_" + link_id[3]).css("visibility", "hidden");
    });
    
    //Increment manufacturers and types when clicked on
    jQuery("[id^='manufacturer_link_main_'], [id^='manufacturer_link_hover_'], [id^='type_link_main_'], [id^='type_link_hover_']").click(function() {
        id_value = jQuery(this).attr("id").split("_");
        if (id_value[0] == 'manufacturer')
            url_data = "_t=m&_v=" + id_value[3];
        else if (id_value[0] == 'type')
            url_data = "_t=t&_v=" + id_value[3];
        //This is set to synchronous because it's triggered when clicking a link..
        //when asynchronous, sometimes the link's page loads too quickly and cancels this execution
        jQuery.ajax({
            type: "GET",
            url: "/ajax/increment.html",
            data: url_data,
            dataType: "text",
            async: false,
            success: function(data) { }
        });
    });   
});
    
    