//These are the JQuery scripts used globally throughout the module

$(document).ready(function(){
    //these scripts handle the rotating tip box    
    var total = $('div.slideshow-item').length;
    
    $('div.caption').html('1 of ' + total );
    
    $('a.slideshow-prev').click(function(){
        var curr  = $('div#slideshow-slide').attr('_number');
        var prev  = parseInt(curr) - 1;
        if (prev < 0) prev = total - 1;
        var img   = $('div.slideshow div.slideshow-item:eq(' + prev + ')').html();
        $('div#slideshow-slide').fadeOut('fast', function(){
           $(this).html( img ).attr('_number', prev).fadeIn('fast');
           $('div.caption').html( (parseInt(prev) + 1) + ' of ' + total )
          //$('div#slideshow-caption').html( img.attr('alt') );
        });
        return false;  
    });    
    
    $('a.slideshow-next').click(function(){
        var curr  = $('div#slideshow-slide').attr('_number');
        var next  = parseInt(curr) + 1;
        if (next > (total - 1)) next = 0;
        var img   = $('div.slideshow div.slideshow-item:eq(' + next + ')').html();
        //var cap   = $('div.slideshow div.slideshow-item-caption:eq(' + next + ')').html();
        $('div#slideshow-slide').fadeOut('fast', function(){
           $(this).html( img ).attr('_number', next).fadeIn('fast');
           $('div.caption').html( (parseInt(next) + 1) + ' of ' + total )
           //$('div#slideshow-caption').html( img.attr('alt') )
        });
        return false;  
    });
    
    //this script handles the tabs switching
    $('ul#tab li').each(function(){
        
        $(this).click(function(){
            
	        $('ul#tab li').removeClass('buttonActive');
        	$(this).addClass('buttonActive');
            
            var tabname = $(this).attr('rel');
            
            //hide all tabs first
            $('div#tab1').hide();
            $('div#tab2').hide();
            $('div#tab3').hide();
        
            $('div#' + tabname).show();
            //img_lg_container.empty();
    
        });
        
    });
    
    $('a.letme-click').click(function(){
    
        $('div.letme-box').show();  
        
    }); 
    
    $('a.letme-close').click(function(){
    
        $('div.letme-box').hide();  
        
    }); 
    
    $('a.license-key-click').click(function(){
    
        $('div#license-key-popup').show();  
        
    }); 
    
    $('a.license-key-close').click(function(){
    
        $('div#license-key-popup').hide();  
        
    }); 
    
    $('.cc-toggle').click( function() {
        $('div#tab1').toggle();
   });
    
});
