(function($) {

    $.fn.cn_tabs = function() {
		
        this.each(function(){
            
            var obj = $(this);
            
            var items = $('.tab-content', obj);
            $('h2', items).addClass('moveoff');
            items.hide();
            
            
            $(obj).prepend('<ul class="tabnav"></ul>');
            items.each(function(i) {
                var currItem    = this;
                var currID      = currItem.id;
                var currLabel   = currItem.getElementsByTagName('h2')[0].firstChild.nodeValue;
                
                $('.tabnav', obj).append('<li' + (i == 0 ? ' class=first-child' : '') + '><a href="#' +  currID + '">' + currLabel + '</a></li>');
            });   
            
            function switchItems(){
                targetID = this.hash;
                items.fadeOut('fast');
                $(targetID).fadeIn();
                
                var tabNavItems = $('.tabnav li', obj);
                    tabNavItems.removeClass('current');
                    var matchingUrl;
                    tabNavItems.each(function(){
                        matchingUrl = '#' + $(this).children('a').attr('href').split('#')[1];
                        if (matchingUrl == targetID) {
                            $(this).addClass('current');
                        } 
                    }); 
                return false;
            }
            
            $('.tabnav a', obj).click(switchItems);
            
            items.first().show();
            $($('.tabnav li', obj).get(0)).addClass('current');
        });
    };
    
})(jQuery);  


(function($) {
    $.fn.cn_malp = function() {
        this.each(function(){
            var obj = $(this);
            var txt = obj.html().replace(RegExp('-at-','i'), '@');
            obj.html('<a href="mailto:' + txt + '">' + txt + '</a>');
        });
    };    
})(jQuery);

function keyUpHandler(e) {
    alt = e.altKey;
    key = e.charCode || e.keyCode || 0;
    keyHuman = String.fromCharCode(key).toLowerCase();
    
    if (keyHuman == 'g' && alt == true) {
        toggleGrid();
    };                  
}

function toggleGrid(){
    if ($('.grid').hasClass('show-grid')) { 
        $('.grid').removeClass('show-grid');
        $.cookie('grid', null); 
    } else {
        $('.grid').addClass('show-grid');
        $.cookie('grid', 'on'); 
    }
}   

function productGallery(x) {
    $('.gallery-thumbnails a').removeClass('current');    
    $('#gallery-blowup img').attr('src', x.href);
    $(x).addClass('current');
}



