// JScript for navigation, homepage boxes and client logos
$(document).ready(function (){

// APPLY JQUERY HINTS
    $('input:text').hint();
    $('textarea').hint();

// INITIALISE TIPSY
    $(function() {
		$('a[rel=tipsy]').tipsy({fade: false, gravity: 'w'});
		$('span[rel=tipsy]').tipsy({fade: false, gravity: 'w'});
	});

// INITIALIZE JQMODAL
    // Add the no template querystring parameter for the lightbox mode
    $('.jqModal').each(function() {
            var anchor = $(this);
            if (anchor.attr('href').indexOf("?") == -1)
            {
            	anchor.attr('href', anchor.attr('href') + '?nt=1');
            }
            else
            {
            	anchor.attr('href', anchor.attr('href') + '&nt=1');
            }
    });

    $('#modalWindow').jqm({
        ajax:'@href', 
        modal:false, 
        ajaxText: '<p style="width: 650px; display: block; background: url(../../images/portfolio/lightbox/loading.gif) 50% 50% no-repeat; height: 0px; padding-top: 80px; overflow: hidden; color: #fff; font-weight: bold;">LOADING...</p>' 
    });

// SHARE WIDGET JS
     $('#favourites a').jFav();

     $('#emailToFriend a.close, #emailToFriend a.close').click( function(event) {
        $('#emailToFriend .sendToAFriendForm').slideToggle();
        event.preventDefault();
     });
     
     
     
     $('#helpLink a ').hover( 
     
        function(event) {
            $('#helpLink span.meetFletch').fadeIn(200); },
        function(event) {
            $('#helpLink span.meetFletch').fadeOut(200); }
     );
     
     

// ADD CLASS TO ALL NAV ELEMENTS WHICH DON'T HAVE CHILDREN
    $("ul#main_navigation li").each( 
        function() {
            var li = $(this)
            // for each li in the navigation check whether it has a child ul
            if (li.children("ul").length <= 0)
            {
                // if it doesn't add a class to it of noChildren
                li.addClass("noChildren");
            }
        } 
    );
 
// DECLARE FUNCTION TO FADE AND TOGGLE
    jQuery.fn.fadeToggle = function(speed, easing, callback) {
        return this.animate({opacity: 'toggle'}, speed, easing, callback);
    };

// FADE HOMEPAGE BOXES OUT ON HOVER
    // on hover
    $("#servicePanels a").hover(
        function(){
            // fade out the child image
            $(this).children("img").fadeToggle("1000"); },
        function(){
            // off hover fade the image back in
            $(this).children("img").fadeToggle("1000"); }
    );
    
// FADE LOGO's TO COLOUR ON HOVER    
    // for any a within div.clientLogos
    $(".clientLogos a").hover(
        function(){
            // on hover fade in the coloured image
            $(this).children('img').fadeToggle("600"); },
        function(){
            // off hover fade out the coloured image
            $(this).children('img').fadeToggle("600"); }
    );

// CHECKBOX CONTROLS
    
        $(".checkboxControls").show();
        
        $(".checkboxControls a.selectAll").click( function() {
            $('.subscriptionsArea input').attr('checked', true);
        });
        
        $(".checkboxControls a.deselectAll").click( function() {
            $('.subscriptionsArea input').attr('checked', false);
        });
});

function resetSTAFForm(tbName, tbEmail, tbFriendName, tbFriendEmail, tbMessage)
{
    $('#emailToFriend #pnlMain').attr('style', 'display:block');
    $('#emailToFriend #pnlThanks').attr('style', 'display:none');
    
    $(".sendToAFriendForm input").val('');
    $('input:text').hint();
    $('textarea').hint();
}
