/* Author: John Knowles - Nzime */
$(document).ready(function(){
    
    $("ul.sf-menu").superfish(); 
    
    //external link
    $('a[rel="external"]').click( function() {
        window.open( $(this).attr('href') );
        return false;
    });
    
    /* Prevent browser outline on click */
    $('a').click(function() {
       $(this).blur(); 
    });
    
    $('.toggle').toggle(function(){
       $(this).next('.hidden').show();
       return false;
    }, function(){
       $(this).next('.hidden').hide();
       return false;
    });
    
    $('.casestudy-toggle').toggle(function(){
       $(this).next('.hidden').show();
       $(this).addClass('underline');
       return false;
    }, function(){
       $(this).next('.hidden').hide();
       $(this).removeClass('underline');
       return false;
    });
    
    $('.cycleSlide').cycle({
        fx:      'scrollLeft',
        speed:    600,
        timeout:  6000,
        pause:    1,
        sync:     1        
    });
    
    $('.toggleHide').hover(function(){
        $('.hidden', this).show();
    },
    function(){
        $('.hidden', this).fadeOut(800);
    });
    
    
    // starting the script on page load
    nzimeTooltip('.tooltip');
    
    if ($.cookie("language")!=null)
    {
        var language = $.cookie("language");
        $('body').translate( 'en', language, {
            not: '#languageSelectCont', 
            async: true,
            toggle: true
        });
        var currentLanguage = $('#'+language).html();
        $('#languageSelect li').show();
        $('#'+language).parent().hide();
        $('#currentLanguage').html(currentLanguage);
    }
    
    $('#languageSelect a').click(function(){
        var language = $(this).attr('id');
        $('body').translate( 'en', language, {
            not: '#languageSelectCont', 
            async: true,
            toggle: true
        });
        $.cookie("language", language, {expires: 7, path: '/'});
        var currentLanguage = $('#'+language).html();
        $('#languageSelect li').show();
        $('#'+language).parent().hide()
        $('#currentLanguage').html(currentLanguage);
        $('#languageSelect').hide();
        return false;
    });

    //gallery navigation by thumbnail
    $('.detail-thumbnails a').click(function(){
           //create an object of the parent/closest div container
           var container = $(this).closest('div');
           //set the required variables
           var img = $(this).attr('href');
           var rel = $(this).attr('rel');
           var detail = $(this).attr('rev');

           //add active class to clicked thumb
           $(this).addClass('active');
           //set the detail zoom image href
           $('#detail-image a', container).attr('href', detail);
           //set the src alt and rel attributes
           $('#detail-image img', container).attr('src', img).attr('rel', rel);

           return false;
       });
    
});
