/**
*	Side menus expand/collapse
*	Requires jQuery 
*/
$(document).ready(function(){
	initMenu();
	cleanStyles();

	// remove href on all expandable links
	//$("ul.menu").find("li.collapsed").find("a:first").attr("href", "javascript:;");
	
	// actions on expandable menu main links
	//$("ul.menu").find("li.expanded").click(function() { toggleMenu(this) });
})
$(window).load(function () {
   balanceHeights("#mini-panel-three_news .panel-panel");
});

 
function initMenu () {
    $("ul.menu li.expanded ul.menu").each(function(){
		makeDropmenu(this);
	})
	$(".side-dropmenu-rel").show();
}

function makeDropmenu (ul) 
{
	$(ul).css({position: "absolute", display: "none"  }).addClass("side-dropmenu").wrap('<div class="side-dropmenu-rel"></div>')
	$(ul).hover(function(){
		$(this).show();
	}, function(){
		$(this).hide();
	});
	$(ul).parent().parent().hover(function(){
		$(this).find(".side-dropmenu").show();
	}, function(){
		$(this).find(".side-dropmenu").hide();
	});
	
	// add a class to the last menu item
	$(ul).find("a:last").addClass("side-dropmenu-last")
}

function toggleMenu(e)
{
	if($(e).attr("class") == "expanded")
	{
		// collapse
		$(e).find("ul.menu").css("display", "none");
		$(e).attr("class", "collapsed");
	} else {
		// expand
		$(e).find("ul.menu").css("display", "block");
		$(e).attr("class", "expanded");
	}
}

function cleanStyles () {
	$("#mini-panel-search_topmenu .leaf:first-child a, #footer .leaf:first-child").css("background-image", "none"); // pipes in footer and header links
	if($.browser.msie) {
		$("#cur_bottom").height(20); //height of iframe
		$("div#mainstory_title div.view-data-node-title").css({top:"-75px"});
	}
	if($.browser.mozilla) $(".country-holder").css("top", "14px");
	
	var isIE6 = /MSIE 6/i.test(navigator.userAgent);
	if(isIE6) {
		// fix main gallery strip position
		$("div#mainstory_title div.view-data-node-title").css({right:"8px", top:"-75px"})
	}
}

function balanceHeights (selector) 
{
	var heighest_col_height = 0;
	$(selector).each(function(){
		if($(this).height() > heighest_col_height) heighest_col_height = $(this).height();
	});
	if(heighest_col_height > 0) {
		$(selector).find(".inside").css("height", heighest_col_height+"px");
	}
}

