$(document).ready(function(){
	PEPS.rollover.init();

	//Main menu scripts to show and hide lists on hover of parent
	$("#nav .topLevelNav > li").hover(function(){
		$(this).addClass("liactive")
	},function(){
		$(this).removeClass("liactive")
	});
	$("#nav .topLevelNav > li").children("ul").hide();
	
	$("#nav .topLevelNav > li").hover(function(){
		$(this).children("ul").show();
	},function(){
		$(this).children("ul").hide();
	}); 
	
		
	$("#nav .topLevelNav li ul").each(function(i){
		$(this).children("li:last").children("a").addClass("bb");
	});
	
	//Making the mega menu always show the children and not only on hover of parent
	$("#nav .topLevelNav > li.navid-1184").hover(function(){
		$(this).children("ul").show();
		$(this).children("ul").children("li").children("ul").show();	
	},function(){
		$(this).children("ul").hide();
	});
	
	$("#nav .topLevelNav > li.navid-1184 > ul > li").hover(function(){
		$(this).children("ul").show();
	},function(){
		$(this).children("ul").show();
	}); 

	
	// hide all popups initially
	$('#popupbox_1, #popupbox_3, #popupbox_4').hide();
 	
	// show and hide popup 1 - communications
  	$('#tab1link a, #tab1 .slideShade').click(function() {$('#popupbox_1').slideDown('slow');return false; });
  	$('#popupbox_1 .popclose a').click(function() { $('#popupbox_1').slideUp('fast');return false;});
	
	// show and hide popup 2 - metal detection
	$('#tab2link a, #tab2 .slideShade').click(function() {$('#popupbox_2').slideDown('slow');return false; });
  	$('#popupbox_2 .popclose a').click(function() { $('#popupbox_2').slideUp('fast');return false;});
	
	// show and hide popup 3 - Activities
	$('#tab3link a, #tab3 .slideShade').click(function() {$('#popupbox_3').slideDown(700);return false;});
  	$('#popupbox_3 .popclose a').click(function() {$('#popupbox_3').slideUp(400);return false;});
	
	// show and hide popup 4 - News
	$('#tab4link a, #tab4 .slideShade').click(function() {$('#popupbox_4').slideDown('slow');return false;});
  	$('#popupbox_4 .popclose a').click(function() {$('#popupbox_4').slideUp('fast');return false;});	
	
	// show and hide popup 5 - Mining Tech
  
  	$('.slideShade').hide();
  	$('.hometab').hover(
     function(){
       $(this).find('.slideShade').slideDown('fast')
     },
     function(){
       $(this).find('.slideShade').slideUp('fast')
     });
	 
	 
	/* ----------------------------------------------------
	Quirks mode means no input[type] selectors. DNN doesn't class anything. So jQuery it is!
	 ---------------------------------------------------- */
	$("#dnn_search input[type=text]").css({
		'min-width': '118px',
		'width': '118px'
		})
	//.width("118").attr("size","10");
	
	/* ----------------------------------------------------
	Admin Logout Button
	----------------------------------------------------- */
	if( $("#dnnOtherTools").length>0 ) {
		$("#dnnOtherTools").after("<li><a href='/Logoff.aspx' style='color: red; font-weight: bold;'>Log Out</a></li>");
	}
});


function pageLoad() {
	//Add a class the first news listing item
	$("ul#news_list li:first a").addClass("firstnewsitem");
};



//Image rollover when the image class is set to 'rollover' replaces the images with imagename_r on hover
PEPS = {};
PEPS.rollover =
{
   init: function()
   {
      this.preload();
      $(".rollover").hover(
         function () { $(this).attr( 'src', PEPS.rollover.newimage($(this).attr('src')) ); },
         function () { $(this).attr( 'src', PEPS.rollover.oldimage($(this).attr('src')) ); }
      );
   },
   preload: function()
   {
      $(window).bind('load', function() {
         $('.rollover').each( function( key, elm ) { $('<img>').attr( 'src', PEPS.rollover.newimage( $(this).attr('src') ) ); });
      });
   },   
   newimage: function( src )
   {
      return src.substring( 0, src.search(/(\.[a-z]+)$/) ) + '_r' + src.match(/(\.[a-z]+)$/)[0];
   },
   oldimage: function( src )
   {
      return src.replace(/_r\./, '.');
   }
};




