$(document).ready(function() {
    $('#mainmenu').supersubs({
	minWidth: 14,
	maxWidth: 25,
	extraWidth: 1
    }).superfish({
	dropShadows: false,
	autoArrows: false
    });
    
    $('.hover_highlight').live("mouseover", function(){
        $(this).addClass('ui-state-hover');
    });

    $('.hover_highlight').live("mouseout", function(){
        $(this).removeClass('ui-state-hover');
    });

    $('#topmenu_ajax_indicator').ajaxStart(function(){
        $(this).fadeIn(200);
    });

    $('#topmenu_ajax_indicator').ajaxStop(function(){
        $(this).fadeOut(300);
    });

    $('.open_with_colorbox').colorbox({
	overlayClose: true,
	initialWidth: 200,
	initialHeight: 100,
	transitionSpeed: 300
    });

    // Track outgoing clicks with google analytics...
    $('a:not(.nogatrack)').filter(function() { // all links which doesn't have the "nogatrack" class
	var theHref = this;
	if (theHref.hostname && theHref.hostname !== location.hostname) { // If it points to a different host than the current one
	    // $(theHref).not(".noAutoIcon").addClass("offSite"); in case we want a separate class (for an "external image" or somthing
	    $(theHref).not(".noAutoLink").attr('target','_blank').bind('click keypress', function(event) { // unless we flag it to not link
		var code=event.charCode || event.keyCode; // also check events via keyboard (highlighted and clicked)
		if (!code || (code && code == 13)) {
		    if(typeof(pageTracker) != 'undefined'){
			var fixedLink = this.href;
			fixedLink = fixedLink.replace(/https?:\/\/(.*)/,"$1"); // remove the http(s):// from the beginning
			fixedLink = '/outgoing/' + fixedLink; // add /outgoing/ to it
			pageTracker._trackPageview(fixedLink); // and track it
		    };
		};
	    });
	};
    });
});