/**
 * Common jquery
 * 
 * This file is normally included in all pages
 */

/**
 * Show notification message
 */
function notify(message)
{
    $('#notifications .notifications-content').html(message);
    $('#notifications')
        .animate({opacity: 1.0}, 200).slideDown()
        .animate({opacity: 1.0}, 4000).slideUp();
}

/**
 * Plugins
 */
(function($) {
  
    /**
     * Stripe rows
     */
    $.fn.stripeRows = function(options) {
        var defaults = {
            row  : '',
            find : 'tbody tr'
        };
        var options = $.extend(defaults, options) ;
        
        return this.each(function() {
            // Reset
            $(this).find(options.find).removeClass('odd') ;
            
            // Start striping
            $(this).find(options.find + options.row + ':odd').addClass('odd') ;
        });
    }

})(jQuery);

/**
 * Init
 */
jQuery(function($){
    
    /**
     * Sub items
     */
    $('.sub_items ul li a').wrapInner('<span></span>');
    $('.sub_items ul li').hover(
        function(){ $(this).addClass('hover'); },
        function(){ $(this).removeClass('hover'); }
    );

    /**
     * Stripe rows
     */
    $('.data-table').stripeRows() ;
    $('.side-menu').stripeRows({find:'li'}) ;
    
    /**
     * Data table hover
     */
    $('.data-table tr').hover(function(){
        
        $(this).addClass('hover');
        
    }, function(){
        
    //    $(this).removeClass('hover');
        
    });
    
    /**
     * Info toggle
     */
    $('.info-toggle').hover(function(){
        $(this)
            .find('.first').hide().end()
            .find('.last').show();
    }, function(){
        $(this)
            .find('.first').show().end()
            .find('.last').hide();
    });

    /**
     * Notifications
     */
    $('body').append('<div id="notifications"><div class="notifications-container"><div class="notifications-content"></div></div></div>');
    $('#notifications').click(function(){
        $(this).stop().slideUp() ;
    });

    /**
     * Currency ajax overlay
     */
    if (jQuery().overlay) {
        $('#changeCurrency').overlay();
    }

    /**
     * My Account bar
     */
    $('.my_account').click(function(e){
        // Opened already?
        if ( $(this).hasClass('open') ) {
            // Yes, close it then...
            $(this).removeClass('open');
            $('.accountbar').slideUp();
        } else {
            // No, open it then...
            $(this).addClass('open');
            $('.accountbar').slideDown('fast');
        }
        e.preventDefault();
    });
    $('.my_account_close').click(function(e){
        $('.my_account').removeClass('open');
        $('.accountbar').slideUp();
        e.preventDefault();
    });
    
});
