jQuery.expr[':'].containsi = function(a,i,m){
     return jQuery(a).text().toUpperCase().indexOf(m[3].toUpperCase())>=0;
};

////
// Document Ready
//
$(document).ready(function() {
    
    

    
    
    
    ////
    // EOI form
    //
    $('#eoi form').validate({
      rules: {
        eoifirstname: {
          required: true,
          minlength: 2
        }
      }
    });
    
    
    
	////
	// add '_blank' to external links
	//
	$('a[href^="http"]:not([href*="'+location.hostname+'"])').each(function() {
	    var orgTitle = $(this).attr("title");
	    
	    $(this).attr({'target': "_blank", 'title': orgTitle+" [new window]"});
	    
            if ($(this.parentNode).attr("id") !== 'logoholder'){
	    if($(this).parent('.feat').length)
	    {
	    	$(this).after('<img class="out" src="pixels/external-link-min-inverse.png" alt="External Link (Will open in a new window)" width="7" height="7" />');
	    }
	    else
	    {
	        $(this).after('<img class="out" src="pixels/external-link-min.png" alt="External Link (Will open in a new window)" width="7" height="7" />');
	    }
            }
	});
    
    ////
    // add 'target="_blank"' to links to PDFs
    //
    $('a[href$=".pdf"]').each(function() {
        var orgTitle = $(this).attr("title");
        
        $(this).attr({'target': "_blank", 'title': orgTitle+" [.PDF]"});
        $(this).addClass('pdf');
    });
    
        
    
    
    ////
    // back to top link
    //
    /// add links
    $('#content h2:not(:first)').each(function() {
        if(!$(this).isOnScreen())
        {
            $(this).before('<a href="#header" class="totop" title="Return to the top of this page">Back to Top</a>');
        }
        });
    /// animate to top
    $('a.totop').click(function(event){
        event.preventDefault();
         $('html, body').animate({scrollTop: '0px'}, 300);
    });
    
    
    
    
    ////
    //  prevent links parent working when sub nave items are present
    //
    $('#header .nav .parent > a').click(function(event) {
    	event.preventDefault();
    });
    
    $('#header .nav li').hover(
      function () {
        $(this).addClass("hover");
      },
      function () {
        $(this).removeClass("hover");
      }
    );
    
    ////
    // speaker more
    //
    var smore = $('.sspot').has('.more');
	
	smore.children('.more').append('<a class="viewless" href="#">view less</a>');
	smore.children('.more').hide();
	smore.append('<a class="viewmore" href="#">view more</a>');
	
	smore.children('.viewmore').click(function(event) {
		event.preventDefault();
		$(this).prev('.more').slideToggle();
		$(this).hide();
	});
	$('.viewless').click(function(event) {
		event.preventDefault();
		$(this).parent('.more').slideToggle();
		$(this).parents('.sspot').children('.viewmore').show();
	});
	
	
	$('video,audio').mediaelementplayer(/* Options */);
	
	
});
