window.addEvent('domready', function() {
    var tables = $$("table.product-table");
    for (var i=0; i<tables.length; i++)
        setup_table_slide(tables[i]);
				
	// Show Contact Box
	$('join-our-network').addEvent('click', function(e){
		e.stop();
		if ($('contact-box').match('.hide')){$('contact-box').removeClass('hide');}
		else{$('contact-box').addClass('hide');}
	});

});

// This function allows us to pass row variables into event callback's scope
var setup_table_slide_setup_cell = function(cell, parentRow, nextRowDiv) {
    cell.setStyle("cursor", "pointer");
    
    // Add mousedown effect
    cell.addEvent("mousedown", function(evt) {
        evt.stopPropagation();
        
        // If a slide effect hasn't already been set up due to
        // a previous mouse click, create it now.  Setting this up as
        // needed saves time at domready when lots of rows are being
        // displayed.
        var fx = parentRow.retrieve("effect");
        if (fx == null) {
            fx = new Fx.Slide(nextRowDiv);
            if (nextRowDiv.getStyle("display") == "block")
            	fx.show();
           	else
            	fx.hide();
            nextRowDiv.setStyle("display", "block");
            parentRow.store("effect", fx);
        }
        
        // Toggle the neighboring row's visibility
        fx.toggle();
        return false;
    });
};

function setup_table_slide(root_element) {
    if (root_element == null)
        return;
    
    // Get an array of all rows within the body section of "product-table" elements
    var rows = root_element.getElements("tbody tr");
    
    for (var i=0; i<rows.length-1; i++) {
        var thisRow = rows[i];
        var nextRow = rows[i + 1];
        var nextRowDiv = nextRow.getElements("div")[0];
        
        // If this isn't a collapsed row, but the following one is, set this one up to control the next one's slide effect
        if (!thisRow.hasClass("collapsed") && nextRow.hasClass("collapsed")) {
            // Attach event to all of this row's cells
            var cells = thisRow.getElements("td");
            for (var j=0; j<cells.length; j++) {
                if (!cells[j].hasClass("no_click"))
                    setup_table_slide_setup_cell(cells[j], thisRow, nextRowDiv);
            }
            
            // Skip the collapsed row
            i++;
        }
    }
};
