$(document).ready(function(){
    
    $('body').addClass('js-enabled');
    
    $('div#techtour_tabs').tabs({ fx: { opacity: 'toggle' }}).tabs("rotate", 5000, false);
    
    $(".lightbox").colorbox({ width:"80%", height:"80%", iframe:true });
    $(".video_lightbox").click(function() {
        var item = $(this);
        var entry = $(item).attr('id').split('_');

        $(this).colorbox( { 
                innerWidth:490, 
                innerHeight:520, 
                href: "/features/_features_web_lightbox/"+entry[1]+"/"+entry[0],
                onLoad:function(){ $('#cboxClose').hide(); },
                onComplete:function(){ $('#cboxClose').fadeIn(400); },
                onCleanup:function(){ $('#cboxClose').hide(); }
        });
    });
    
    $(".interactive_lightbox").colorbox({width:"80%", height:"80%", iframe:true});

    $('ul#page_nav li ul li:last').addClass('end');
    
    $('div#theme_select h5').append('<img src="/assets/images/site/theme_select_arrow.gif" alt="" width="10" height="5" />');
    
    related_content();
    theme_listing();
    chapter_tooltips();
    
    
    // DEALS WITH THE SHOW/HIDE OF THE FULL CHAPTERS NAVIGATION ON THE CONTENT PAGES
    $('ul#page_nav').hide();
    var link_p = $('<p class="page_nav_toggle"><a href="#">View full navigation</a></p>');
    $('a',link_p).show_hide( 'ul#page_nav', 'Hide full navigation', $('a',link_p).html(), 'slow');
    $('div#pagination').after(link_p);
     
});



// EXPAND/COLLAPSE OF LIST FOLLOWING H5 
function related_content(){
    
    $('.slidetoggle').click(function() {
       $(this).next('ul').slideToggle('medium');
       $(this).toggleClass('down');
       return false; 
    });
    
}



// EXPAND/COLLAPSE OF THEME LISTING 
function theme_listing(){
    
    $('div#theme_select h5').click(
        function() {
            $(this).next('ul').slideToggle('medium');
            $(this).toggleClass('down');
            return false; 
        }
    );
}



// ADDS A IMAGE AND HEADING TOOLTIP WHEN HOVERING OVER CHAPTER LINKS
function chapter_tooltips(){
    $('div.chapter_select ul li').hover(function() {
       $(this).children('div:eq(0)').addClass('on'); 
       return false;
    },
    function() {
        $(this).children('div:eq(0)').removeClass('on');
    });
}



/**
*
* Show/Hide
* -----------------
* Toggle slides and item, and chnages the html() of
* the clicked item to the specified value
*
* @return $(this) obj
*/
$.fn.show_hide = function( the_item, althtml, orightml, speed )
{
 $(this).click(function(){
   $(the_item).slideToggle( speed);
   $(this).toggleClass('open').toggleClass('closed');
   if( $(this).html() != althtml) {
     $(this).html(althtml);
   } else {
     $(this).html(orightml);
   }
   return false;
 });
 return $(this);
}
