/**
* Regal Content UI transformations
* 
* @package js
* @author Tim Carr
* @version 1
* @copyright n7 Studios 2009
*/

$(document).ready(function() {    
    // Fade out a success or error message, if it exists
    if ($('div.success').length > 0) {
        setTimeout(function(){ $('div.success').fadeOut(1000); }, 2000);        
    }
    if ($('div.error').length > 0) {
        setTimeout(function(){ $('div.error').fadeOut(1000); }, 2000);        
    }
    if ($('#login form p.error').length > 0) {
        setTimeout(function(){ $('#login form p.error').fadeOut(1000); }, 2000);        
    }
    
    // Hide product forms and show add product buttons, as JS is enabled
    $('div.details').addClass('hidden');
    $('a[rel=add]').removeClass('hidden');
    $('a[rel=update]').removeClass('hidden');
    
    // When a user clicks the Order Now button on a Product, display the form they need to fill out
    // with details for the item.  Also hide the right hand side button, as a submit button
    // is included in the form
    $('a[rel=add]').bind('click', function(e) {
        e.preventDefault(); // Stop link from working
        $('div.details', $(this).parent().parent()).removeClass('hidden');
        $(this).addClass('hidden');
    });
    $('a[rel=update]').bind('click', function(e) {
        e.preventDefault(); // Stop link from working
        $('div.details', $(this).parent().parent()).removeClass('hidden');
        $(this).addClass('hidden');
    });
});