var lastHeaderMenuId = "";
var lastMenuImg = "";
var flag = false;

$(document).ready(function() {
	$('#menuCommonTransparentDiv, #productsDetailsFloatDiv, #athleteDetailsFloatDiv, #programsDetailsFloatDiv, #productsDownloadDetailsFloatDiv, #advertismentsDownloadDetailsFloatDiv, #otherDownloadDetailsFloatDiv').bind('mouseover', function(event) {
		setFlag();
	});
	$('#menuCommonTransparentDiv, #productsDetailsFloatDiv, #athleteDetailsFloatDiv, #programsDetailsFloatDiv, #productsDownloadDetailsFloatDiv, #advertismentsDownloadDetailsFloatDiv, #otherDownloadDetailsFloatDiv').bind('mouseout', function(event) {
		unsetFlag();
	});
	addMouseOverEvent();
});

function showDetailsDiv(o, divId, detailsWidth, detailsHeight) {
	flag = true;
	if(lastHeaderMenuId) {
		$("#"+lastHeaderMenuId+"DetailsFloatDiv").hide();
		restoreOverImage(lastMenuImg);
	}

	lastMenuImg = o;
	lastHeaderMenuId = divId;

	var position = $(o).position();
	setOverImage(o);
	
	// Div
	var divObj = $("#"+divId+"DetailsFloatDiv");
	divObj.width(detailsWidth);
//	divObj.height(detailsHeight);
	divObj.css("top", position.top+$(o).height());
	divObj.css("left", position.left);
	divObj.css("z-index", 10);
	divObj.show();
	
	//Transparent Div
	var divObjT2 = $("#menuCommonTransparentDiv");
	divObjT2.width(detailsWidth+40);
	divObjT2.height($(divObj).height()+40);
	divObjT2.css("top", position.top+$(o).height());
	divObjT2.css("left", position.left-20);
	divObjT2.css("z-index", 10);
	divObjT2.show();
	
	if(divId=="products") {
		if($("#categoryList").height() < $("#productList").height()) {
			$("#categoryList").height($("#productList").height());
		} else {
			$("#productList").height($("#categoryList").height());	
		}
	} else if(divId=="athlete"){
		// Set first height
		if($("#athleteMenu1").height() < $("#athleteDetails").height()) {
			$("#athleteMenu1").height($("#athleteDetails").height());
		}
	} else if(divId=="programs") {
		// Set first height
		if($("#programMenu1").height() < $("#programDetails").height()) {
			$("#programMenu1").height($("#programDetails").height());
		}
	}
}

function hideDetailsDiv() {
	if(flag==false) {
		var divObj = $("#"+lastHeaderMenuId+"DetailsFloatDiv");
		
		divObj.animate({
			opacity: 0
		}, 200, function() {
			divObj.hide();
			divObj.css('opacity',1);
		});

		restoreOverImage(lastMenuImg);
		$("#menuCommonBlackDiv").hide();
		$("#menuCommonTransparentDiv").hide();

		lastHeaderMenuId = "";
		lastMenuImg = "";
	}
}

var menuTime;
function setFlag() {
	flag = true;
	clearTimeout(menuTime);
	menuTime = setTimeout(function(){hideDetailsDiv();},500);
}

function unsetFlag() {
	flag = false;
	clearTimeout(menuTime);
	menuTime = setTimeout(function(){hideDetailsDiv();},500);
}

function addMouseOverEvent() {
	$('.detailsLink').bind('mouseover', function(event) {
		$(this).parent().children().css("color","#ffffff");
		$(this).css("color", "#ff0000");
	});	
	$('.changeArrow').bind('mouseover', function(event) {
		$(this).parent().find("img").attr("src",SITE_ROOT+"images/common/arrow_gray.png");
		$(this).next().attr("src",SITE_ROOT+"images/common/arrow_red.png");
	});	
	$('.retToWhite').bind('mouseout', function(event) {
		$(this).css("color","#ffffff");
	});	
	$("a, .overUnder").not(".detailsLink, .noOverUnder").mouseover(function() {
		$(this).css('text-decoration','underline');
	});
	$("a, .overUnder").not(".detailsLink, .noOverUnder").mouseout(function() {
		$(this).css('text-decoration','none');
	});	
}
