
/*-------------------------------------------------------
---- BEHAVIOUR (Primary Javascript file) ----------------
--------------------------------------------------------*/
var $rr = jQuery.noConflict();

$rr(document).ready(function() {//When the document is ready


    //alert("behaviour.js");	


    //Open external links in new windows

    var external = $rr('a[rel="external"],a[href*=.pdf],a[href*=.rtf],a[href*=.doc],a[href*=.xls],a[href*=.ppt]'); 												                             	//Get all links with rel="external" and place them into the 'external'

    external.attr("title", external.attr("title") + " - Link opens in a new window.."); 	     	//Take the links current title and append it with the external link message

    external.click(function() {															                                 	//When an external link is clicked

        window.open($rr(this).attr('href')); 										                             			//Open its href in a new window

        return false; 																		                                        	//Cancel the links default behaviour

    }); 																					                                             	//End function

    $rr('.headerInner .bioNavigation .aboutYou').addClass("expandable");

    $rr('.pageUtilities').append("<li class='print'><a href='javascript:window.print();'>Print</a></li>");




    //Tabbed Panes function ------------------------------------------

    if ('.tabbedContent') {

        $rr('.tabbedContent').addClass('panes');

        var height = 0;

        $rr('.panes').before("<ul class='tabs'></ul>");

        $rr('.panes div').not('.panes div div').each(function(i) {

            $rr(this).addClass('pane' + i);

            $rr('ul.tabs').append("<li id='" + i + "'><a href='#'>" + $rr(this).find('.panelHeading').text() + "</a></li>");

            $rr(this).find('.panelHeading').remove();


            if ($rr(this).height() > height) {

                height = $rr(this).height();

            }

        });

        $rr('ul.tabs li#0').addClass('active');

        //$rr('.panes').css({'height': height + 40});

        $rr('.panes div').not('.panes div div').hide();
        $rr('.panes div:first').show();

        $rr('ul.tabs a').click(function() {

            $rr('ul.tabs li').removeClass('active');
            $rr(this).parent('li').addClass('active');

            var pane = $rr(this).parent('li').attr('id');

            $rr('.panes div').not('.panes div div').hide();
            $rr('.panes div.pane' + pane).show();

            return false;

        });

    }



    //Clear search fields


    $rr(".frmSiteSearch input").not('.submit').focus(function() {

        if (this.value == this.defaultValue) {
            this.value = "";
        }

    }).blur(function() {

        if (!this.value.length) {
            this.value = this.defaultValue;

        }

    })



    //About us nav ------------------------------------------------------------------------------------

    $rr('.bioNavigation li, .featureNavigation ul li').hover(function() {



        if ($rr(this).children('ul').is(":hidden")) {

            $rr(this).children('ul').show();

            $rr(this).css({ 'z-index': '9000' });


        } else {

            $rr(this).children('ul').hide();

            $rr(this).css({ 'z-index': '500' });

        }

    })




    //Homepage

    $rr('.featureNavigation .noJSLink').hide()

    $rr('.featureNavigation ul').removeClass('offSet');

    $rr('.featureNavigation ul li').mouseover(function() {

        $rr('.featureNavigation ul li').css({ 'z-index': '500' });

        $rr(this).css({ 'z-index': '1000' });

        $rr('.featureNavigation ul li ul').hide();
        $rr(this).children('ul').show();

    })


    $rr('.featureNavigation ul li').mouseout(function() {

        $rr(this).children('ul').hide();

    })



    //----------------------------------------------------------------------------------------------------		

/*
    $rr('.tt').prepend("<a href='#' class='close'></a>");

    $rr('table.eventCalendar a').mouseover(function() {

        if ($rr(this).children('span.tt').is(":hidden")) {

            $rr('table.eventCalendar a span.tt').fadeOut();
            $rr(this).children('span.tt').fadeIn();

        }
    })

    $rr('.tt a.close').click(function() {

        $rr('table.eventCalendar a span.tt').fadeOut();

        return false;

    });

    $rr('body').click(function() {

        $rr('table.eventCalendar a span.tt').fadeOut();


    });

*/


    $rr('table.eventCalendar a').hover(function() {

            $rr('.header').css({ 'z-index': '1' });
            $rr(this).children('span.tt').fadeIn();
            
    }, function() {

            $rr('.header').css({'z-index': '1000'}); 
            $rr(this).children('span.tt').fadeOut();
            
    })

    $rr('table.eventCalendar a span').click( function(){
      
      $rr(this).css('cursor','pointer');
      window.location = $rr(this).parent().find('a').attr('href');
      
    });
    
    $rr('table.eventCalendar a span img').click( function(){
      
      $rr(this).css('cursor','pointer');
      window.location = $rr(this).parent().find('a').attr('href');
      
    });


    //Condition forn areas (hide and show) ------------------------------------------------------------

    //$rr('.conditionalFormArea').hide();

    $rr('.conditionalFormTrigger').wrapInner('<span/>') //Span contains open/close arrow
    $rr('.conditionalFormTrigger').children('span').css({ 'background-image': 'url(/assets/images/site/buttons/collapseForm.gif)', 'background-repeat': 'no-repeat' }) //Default mode is open

    $rr('.conditionalFormTrigger').click(function() {

        if ($rr('.conditionalFormArea').is(":hidden")) {

            $rr('.conditionalFormArea').show();
            $rr(this).children('span').css({ 'background-image': 'url(/assets/images/site/buttons/collapseForm.gif)', 'background-repeat': 'no-repeat' })

        } else {

            $rr('.conditionalFormArea').hide();
            $rr(this).children('span').css({ 'background-image': 'url(/assets/images/site/buttons/expandForm.gif)', 'background-repeat': 'no-repeat' })

        }

        return false;

    })






    //Make whole box clickable ------------------------------------------
    $rr('.resourceBoxWrapper .shadowedBoxSmall').css('cursor', 'pointer');
    $rr('.resourceBoxWrapper .shadowedBoxSmall').click(function() { window.location = $rr('a', this).attr('href'); });

    //Hide submit button for Resource filters
    $rr('.submitFilterRow').hide();



    /* -- Fix required asterix on custom forms -- */


    $rr('.scfRequired').each(function() {

        $rr(this).siblings('label').append("<span class='scfRequired'>*</span>");

        $rr(this).remove();

    })
}); //End document.ready

