$(document).ready(function() {
/*
	$("#utilitiesmenu li .utilitieshide").hover(function() {
	    $("#specialty").slideToggle('slow');
    },function() { 
		$("#specialty").slideToggle('medium');
	});
	$(".searchContainer div").hover(function() {
	    $("#search").slideToggle('slow');
    },function() { 
		$("#search").slideToggle('medium');
	});
*/
	if($("#featured").length){
		$("#featured > ul").tabs({fx:{opacity: "toggle"}}).tabs("rotate", 7500, true);
	}

	if($("div#topnav").length){
		var topnav_default = '#nav'+$('div#topnav ul li a.on').attr('id');
		var topsub_default = '#'+$(topnav_default + ' span').attr('id');
	
		function manage_topnav(){
			var showmenu='';
			$(showmenu).removeClass('on');
			$(showmenu + ' span').removeClass('on');
			if(topnav_over || topsub_over){
				if(topnav_over && (!topsub_over)){
					showmenu = topnav_over;
				}else if((!topnav_over) && topsub_over){
					showmenu = topsub_over;
				}else if(topnav_over.replace("nav","") == topsub_over){
					showmenu = topnav_over;
				}
				$(topnav_default).removeClass('on');
				$(topsub_default).removeClass('on');
				$(showmenu).addClass('on');
			}else{
				if($(topnav_default).attr('class') != 'on'){
					$(topnav_default).addClass('on');
					$(topsub_default).addClass('on');
				}
			}
		}
		
		var timer_mainnav = setInterval(manage_topnav,250);
		
		var topnav_over = '';
		var topsub_over = '';
		
		$('div#topnav ul:first>li').hover(function(){
			topnav_over = '#'+$(this).attr('id');
			topsub_over = '#'+$(topnav_over + ' a').attr('id');
			if(topnav_over != topnav_default){
				$(topnav_default).removeClass('on');
				$(topsub_default).removeClass('on');
			}
		},function(){
			topnav_over='';
			topsub_over='';
		});
	}

	if($('div#searchresultswrapper').length){
		var tabContainers = $('div#searchresultswrapper > div');
		tabContainers.hide().filter(':first').show();

		$('div#searchresultswrapper ul#displaytabs a').click(function () {
			tabContainers.hide();
			tabContainers.filter(this.hash).show();
			$('div#searchresultswrapper ul#displaytabs a').removeClass('showtab');
			$(this).addClass('showtab');
			return false;
		}).filter(':first').click();
	}

	if($('#vehiclesstage a').length){
	    $('#vehiclesstage a').lightBox();
	}

	if($('#vehiclessubmit').length){
		$('#vehiclessubmit').lightBox();
	}

	if($('div#extras').length){
		var tabContainers = $('div#extras > div');

		$('div#extras ul.tabnav a').click(function () {
			tabContainers.hide().filter(this.hash).show();
			
			$('div#extras ul.tabnav a').removeClass('ui-state-active');
			$(this).addClass('ui-state-active');
			
			return false;
		}).filter(':first').click();
	}
});
