var elwidth =  700;

$(document).ready(function() {
	
	$(".droplink, .closedroplink").click(
		function() {
			contentid = $(this).attr("href");

			if($("#menurollovers").hasClass("shown") && $(contentid+":visible").length>0) {
				//Check if this subnav is currently showing. if so, the action is to hide it
				hideRollovers();
			}
			else if($("#menurollovers").hasClass("shown")) {
				//Check for existing rollovers and hide them if present, and reset the droplink classes
				hideRollovers();
				showRollover($(this));
			}
			else {
				//Do the rollover
				showRollover($(this));
			}

			return false;
	});
	
	$("#offers-container").accordion({autoHeight : false, clearStyle : true});
	
});
function showRollover(clickel) {
	contentid = $(clickel).attr("href");
	$(clickel).addClass("dl_active");
		
	//Check which li we clicked on. If it's not further left then 
		//Calculate offset
		offs = $(clickel).parent().offset();
		offsbody = $("#container").offset();
		lioffset = offs.left - offsbody.left;
		
		//Specs for dropdown
		elx = -4;
		
	if(lioffset > 500) {
		//We've clicked a link on the right side of the menu
		elx = 980 - 34 - elwidth;
		//elx = 407;
	}
	
	
	//Show the rollover divs
	$("#menurollovers").addClass("shown");
	//Add hover class to parent li
	$(clickel).parent().addClass("subshown");
	
	//Show and position sub nav holder
	$("#menurollovers").css("left",elx+"px").css("width",elwidth+"px");
	
	//Show relevant div in subnav
	$(contentid).show();
	//Set the link to close for the in-box close link
	$(".closedroplink").attr("href",contentid);
}

function hideRollovers() {
	$(".dl_active").each(function() {
		$(this).removeClass("dl_active");
	});
	//$("#menurollovers div:not(.closesubnav)").hide();
	$("#menurollovers div.mr_wrap").hide();
	$("#menurollovers").removeClass("shown");
	$(".subshown").removeClass("subshown");
}
function getLIwidth() {
	$("#nav ul li").each(function() {
		liwid = $(this).width();
		cwid = cwid + liwid;
	});
	cwid = cwid+20;
	return cwid;
}
function getULwidth() {
	cwid = 0;
	$("#nav ul li").each(function() {
		liwid = $(this).width();
		cwid = cwid + liwid;
	});
	cwid = cwid+20;
	return cwid;
}