$(document).ready(function() {
    
	//if ($.browser.msie && $.browser.version.substr(0, 1) < 7) {		
	//	$("ul#topnav li").hover(function() { //Hover over event on list item
	//		$(this).css({ 'background' : '#389bc7 url(nav-hover.gif) repeat-x'}); //Add background color and image on hovered list item
	//	$(this).find(".sub").css('display', 'block'); //Show the subnav
	//	$(this).find(".sub").stop().fadeTo('fast', 1).show();
	//} , function() { //on hover out...
	//	$(this).css({ 'background' : 'none'}); //Ditch the background
	//	$(this).find(".sub").hide(); //Hide the subnav
	//});
	//	$(this).find(".sub").css('display', 'block');
    //    $(this).find(".sub").css('width', $(window).width());
    //   }


        function megaHoverOver() {

            if ($.browser.msie && $.browser.version.substr(0, 1) < 7) {

                $(this).find(".sub").css('display', 'block');

                $(this).find(".sub").css('width', $(window).width());

            }

            $(this).find(".sub").stop().fadeTo('fast', 1).show();

        }



        function megaHoverOut() {

            $(this).find(".sub").stop().fadeTo('fast', 0, function() {

                $(this).hide();

            });

        }





        var config = {

            sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)    

            interval: 100, // number = milliseconds for onMouseOver polling interval    

            over: megaHoverOver, // function = onMouseOver callback (REQUIRED)    

            timeout: 500, // number = milliseconds delay before onMouseOut    

            out: megaHoverOut // function = onMouseOut callback (REQUIRED)    

        };



        $("ul#topnav li .sub").css({ 'opacity': '0' });

        $("ul#topnav li").hoverIntent(config);

        
        //Added by Profero on 3/12/2010 1:25pm for analytics tracking of meganav links
        
			var sPath = window.location.pathname;
			var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
		
			// Grabs all download links and calls a pseudo pageview using /download/$nameoffile
			$('a[href]').filter(function() {
				return this.href.match('(\.pdf|\.doc|\.docx|\.xls|\.xlsx|\.csv|\.ppt|\.pptx)');
			}).click(function(){
			var dld_result = /\/([a-z0-9-_]+\.(pdf|doc|docx|xls|xlsx|csv|ppt|pptx))$/i.exec(this.href);
			_gaq.push(['_trackPageview', sPage + '/download/' + dld_result[1]]);
			});
			
			// ditto for any mailto links
			$('a[href]').filter(function() {
				return this.href.match('(mailto)');
			}).click(function(){
			_gaq.push(['_trackPageview', sPage + '/mailto/' + this.href.replace("mailto:","")]);
			});
			
			// ditto for any asx brand site links, added on 22 Dec 2010
			$('a[href]').filter(function() {
				return this.href.match('(asx.com.au)');
			}).click(function(){
			_gaq.push(['_trackPageview', sPage + '/asx:/' + this.href]);
			});
			
			// locates any printer links on a page and runs pageload using /print/$pageurl
			$('a[onclick]').filter(function() {
				var str=String(this.onclick);
				return str.match('(print)');
			}).click(function(){
			_gaq.push(['_trackPageview', sPage + '/print/']);
			});
			
			 //Added by Profero on 16/12/2010 for automatically opening attachements in a new window
			 
			 $('a[href]').filter(function() {
				return this.href.match('(\.pdf|\.doc|\.docx|\.xls|\.xlsx|\.csv|\.ppt|\.pptx)');
					}).click(function() {
							window.open(this.href);
							return false;
					});
					
			 //Added by Profero on 16/02/2011 for detecting link clicks within Meganav for analytics
					
			$('#topnav .sub a').click(function(){
				_gaq.push(['_trackPageview', '/meganav/' + $(this).text()]);
			});
			
	
    });
