jQuery(function($) {

	//New window
	jQuery('a.newWin').click(function(){
	    window.open(this.href,'');
	    return false;
	});
	
    // --------------------------------------------------------------
    // quick plugin to make it easier to check if an element exists
    // --------------------------------------------------------------
    jQuery.fn.exists = function(){
        return jQuery(this).length > 0;
    }

    // --------------------------------------------------------------
    // makes tab magic
    // --------------------------------------------------------------
        
    $(".tab-content").hide(); //Hide all content
    $(".tab-nav li:nth-child(2n)").addClass("active").show(); //Activate first tab
    $(".tab-content:eq(1)").show(); //Show first tab content
    									


    $(".tab-nav li").click(function() {

        $("ul.tab-nav li").removeClass("active"); //Remove any "active" class
        $(this).addClass("active"); //Add "active" class to selected tab
        $(".tab-content").hide(); //Hide all tab content

        var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
        $(activeTab).show().jScrollPane({
									'showArrows': true
								});
        return false;
    });
    
    // --------------------------------------------------------------
    // custom scrollbar for the homepage
    // --------------------------------------------------------------
    $('.homepage').find('.tab-content').jScrollPane({
									'showArrows': true
								});
								
	// --------------------------------------------------------------
    // Randomise Homepage Hero
    // --------------------------------------------------------------
    
    
    var mycount =  $('.banner').size();    
    var rand = Math.floor(Math.random()*mycount+1);
    $('#banner'+ rand +'').show();
    $('#headline'+ rand +'').show();
    
    // --------------------------------------------------------------
    // Open all PDFs in a new window
    // --------------------------------------------------------------
	
	$('div.search-item a:not([href^=mailto])').live('click', function(event){
			window.open($(this).attr('href'));
			event.preventDefault();
	});
	
	$('.mod_article:not(#Latest) div.news-item a:not([href^=mailto])').live('click', function(event){
			window.open('/'+ $(this).attr('href'));
			event.preventDefault();
	});
	
	$('#Latest div.news-item a:not([href^=mailto])').live('click', function(event){
			window.open($(this).attr('href'));
			event.preventDefault();
	});
	
	$('#media-table a').live('click', function(event){
			window.open('/'+ $(this).attr('href'));
			event.preventDefault();
	});
	
	
	// --------------------------------------------------------------
    // Print Page
    // --------------------------------------------------------------
    
    $('a.print').click(function() {
  		window.print();
  		return false;
 	});
    
    
    // --------------------------------------------------------------
    // Bookmark Page
    // --------------------------------------------------------------
	
	// Setup bookmark links
	// add a "rel" attrib if Opera 7+
	if(window.opera) {
		if ($("a.jqbookmark").attr("rel") != ""){ // don't overwrite the rel attrib if already set
		$("a.jqbookmark").attr("rel","sidebar");
		}
	}
	$("a.jqbookmark").click(function(event){
	event.preventDefault(); // prevent the anchor tag from sending the user off to the link
	var url = this.href;
	var title = this.title;
	
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
	window.external.AddFavorite( url, title);
	} else if(window.opera) { // Opera 7+
		return false; // do nothing - the rel="sidebar" should do the trick
	} else { // for Safari, Konq etc - browsers who do not support bookmarking scripts (that i could find anyway)
	}
	});
	if (((!window.sidebar)&&(!window.external)&&(!window.opera))) {
	$("a.jqbookmark").hide();
	} 
    
    // --------------------------------------------------------------
    // image gallery modal
    // --------------------------------------------------------------	
	$("#image-library").find('a').fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	false
	});
});

$(window).load(function(){
    
    
});
