var mT;

$(document).ready(function(){
	//external link setup
	 $("a[href^='http://']").attr("target", "_blank");
	
	//background rollovers setup
	$(".rollover").hover(
		function () {
			var h = "0px -" + $(this).css("height");
			$(this).css("background-position",h);
		},
		function () {
			$(this).css("background-position","0px 0px");
		}
	);
	
	//dropdowns
	$("#mainMenu > li").children("a").hover(
		function(){
			clearTimeout(mT);
			$(".subMenu").css("display","none");
			$(this).siblings("ul").css("display","block");
		},
		function(){
			mT = setTimeout(function(){
				$(".subMenu").css("display","none");
			},500);
		}
	).end()
	.each(function(){
		$(this).find("li:last").css({
			paddingBottom: "0px",
			backgroundImage: "none"
		});
	});
	
	$(".subMenu li").hover(
		function(){
			$(this).addClass("over");
			clearTimeout(mT);	
		},
		function(){
			$(this).removeClass("over");
			mT = setTimeout(function(){
				$(".subMenu").css("display","none");
			},500);
		}
	);
	
	$(".feature, #feature2 a").hover(
		function(){
			$(this).children().css("opacity","0.75");
		},
		function(){
			$(this).children().css("opacity","1");			
		}
	);
	
	//submenu
	
	var f = window.location.pathname;
	
	$("#secondaryMenu").find("a").filter("[href="+f+"]").addClass("current").removeAttr("href")
	.end().not(".current").hover(
		function () {
			var h = "right -" + $(this).css("height");
			$(this).css("background-position",h);
		},
		function () {
			$(this).css("background-position","right top");
		}
	);
	
	//testimonails feature 2
	
	var x = rand(0,2);
	$("#feature2 a img").eq(x).css("display","block");
	
	
	//mailto setup
	$(".mailto").each(function(){
		var name = $(this).attr("title");
		var html = "<a href='mailto:" + name + "@restaurantevents.ca'>" + name + "@restaurantevents.ca</a>";
		$(this).html(html);
	});

});