/****************************************************************************
 * Equalize the heights of elements.
 * Example 1: $(".cols").equalHeights(); Sets all columns to the same height.
 * Example 2: $(".cols").equalHeights(400); Sets all cols to at least 400px tall.
 * Example 3: $(".cols").equalHeights(100,300); Cols are at least 100 but no more
 * than 300 pixels tall. Elements with too much content will gain a scrollbar.
 ***************************************************************************/
(function($) {
	$.fn.equalHeights = function(minHeight, maxHeight) {
		var tallest = (minHeight) ? minHeight : 0;
		this.each(function() {
			if($(this).height() > tallest) {
				tallest = $(this).height();
			}
		});
		if((maxHeight) && tallest > maxHeight) tallest = maxHeight;
		return this.each(function() {
			$(this).height(tallest).css("overflow","visible");
		});
	}
})(jQuery);
/****************************************************************************
 * Drop Down Menu
 ***************************************************************************/
var timeout	= 500;
var closetimer	= 0;
var ddmenuitem	= 0;
var topMenu = 0;

// open hidden layer
function mopen(id)
{	
	// cancel close timer	
	mcancelclosetime();
	
	// close old layer
	if(ddmenuitem) 
	{
		ddmenuitem.style.visibility = 'hidden';
		topMenu.className = '';		
	}

	// get new layer and show it
	ddmenuitem = document.getElementById(id);
	topMenu = document.getElementById("open_" + id);
	topMenu.className = "highlight";
	ddmenuitem.style.visibility = 'visible';
}
// close showed layer
function mclose()
{
	if(ddmenuitem) 
	{
		ddmenuitem.style.visibility = 'hidden';
		topMenu.className = '';		
	}
}

// go close timer
function mclosetime()
{
	closetimer = window.setTimeout(mclose, timeout);
}

// cancel close timer
function mcancelclosetime()
{
	if(closetimer)
	{
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

// close layer when click-out
//document.onclick = mclose; 

jQuery(function($) {
	$('#open_m0')
		.mouseover(function(event) {
			mopen('m0');
		})
		.mouseout(function(event) {			
			mclosetime();
		})
		.focus(function(event) {
			mopen('m0');
		})
		.blur(function(event) {
			mclosetime();
 	});
	
	$('#m0 :a')
		.mouseover(function(event) {
			mcancelclosetime();
		})
		.mouseout(function(event) {
			mclosetime();
		})
		.focus(function(event) {
			mcancelclosetime();
		})
		
		.blur(function(event) {
			mclosetime();
		});
	$('#open_m1')
		.mouseover(function(event) {
			mopen('m1');
		})
		.mouseout(function(event) {			
			mclosetime();
		})
		.focus(function(event) {
			mopen('m1');
		})
		.blur(function(event) {
			mclosetime();
 	});
	
	$('#m1 :a')
		.mouseover(function(event) {
			mcancelclosetime();
		})
		.mouseout(function(event) {
			mclosetime();
		})
		.focus(function(event) {
			mcancelclosetime();
		})
		
		.blur(function(event) {
			mclosetime();
		});
	$('#open_m2')
		.mouseover(function(event) {
			mopen('m2');
		})
		.mouseout(function(event) {			
			mclosetime();
		})
		.focus(function(event) {
			mopen('m2');
		})
		.blur(function(event) {
			mclosetime();
 	});
	
	$('#m2 :a')
		.mouseover(function(event) {
			mcancelclosetime();
		})
		.mouseout(function(event) {
			mclosetime();
		})
		.focus(function(event) {
			mcancelclosetime();
		})
		
		.blur(function(event) {
			mclosetime();
		});
	$('#open_m3')
		.mouseover(function(event) {
			mopen('m3');
		})
		.mouseout(function(event) {			
			mclosetime();
		})
		.focus(function(event) {
			mopen('m3');
		})
		.blur(function(event) {
			mclosetime();
 	});
	
	$('#m3 :a')
		.mouseover(function(event) {
			mcancelclosetime();
		})
		.mouseout(function(event) {
			mclosetime();
		})
		.focus(function(event) {
			mcancelclosetime();
		})
		
		.blur(function(event) {
			mclosetime();
		});
	$('#open_m4')
		.mouseover(function(event) {
			mopen('m4');
		})
		.mouseout(function(event) {			
			mclosetime();
		})
		.focus(function(event) {
			mopen('m4');
		})
		.blur(function(event) {
			mclosetime();
 	});
	
	$('#m4 :a')
		.mouseover(function(event) {
			mcancelclosetime();
		})
		.mouseout(function(event) {
			mclosetime();
		})
		.focus(function(event) {
			mcancelclosetime();
		})
		
		.blur(function(event) {
			mclosetime();
		});
});

/****************************************************************************
 * Search and Minitel
 ***************************************************************************/
jQuery(function($) {
	//Highlights searchBox when it is selected and deletes the word search
	$("#searchbox").focus(function()
	{
		if ($("#searchbox").val() == "Search") {
			$("#searchbox").val("");
		}
	});
	//Unhightlight search and returns the word Search if box is empty
	$("#searchbox").blur(function()
	{
		if ($("#searchbox").val() == "") {
			$("#searchbox").val("Search");
		}
	});
	//Removes the word search if search button is clicked
	$("#searchButton").click(function () {
		if ($("#searchbox").val() == "Search") {
			$("#searchbox").val("");
		}
	});
	//Highlights minitelBox when it is selected and deletes the word Lastname
	$("#minitelbox").focus(function()
	{
		if ($("#minitelbox").val() == "Mini-Tel") {
			$("#minitelbox").val("");
		}
	});
	//Unhightlight minitel and returns the word lastname if box is empty
	$("#minitelbox").blur(function()
	{
		if ($("#minitelbox").val() == "") {
			$("#minitelbox").val("Mini-Tel");
		}
	});
	//Removes the word lastname if it is still there when button is clicked
	$("#minitelButton").click(function () {
		if ($("#minitelbox").val() == "Mini-Tel") {
			$("#minitelbox").val("");
		}
	});
});