
var mouse_over = false;
var tooltip_margin_left = 0;
var tooltip_flipped = false;

function flipTooltip(id) {
	if (id=="menu_6") {
		if (!tooltip_flipped) {
			$("#menu_upper_left").addClass("menu_upper_left");
			$("#menu_upper_right").addClass("menu_upper_right_pointer");
			tooltip_flipped = true;
		}
	}
	else {
		if (tooltip_flipped) {
			$("#menu_upper_left").removeClass("menu_upper_left");
			$("#menu_upper_right").removeClass("menu_upper_right_pointer");
			tooltip_flipped = false;
		}
	}
}

function mapBaseActions() {
	$("a.newwindow").attr("target","_blank");
	$('a.lightbox').lightBox();
	$('a.lightbox2').lightBox();
}

function menu_fadeOut() {
	$("#animate").fadeOut("fast",function() {
		$("#animate").fadeIn("fast",function() {	
			if (!mouse_over) {
				$("#menu_tooltip1").fadeOut("fast");
			}
		})
	});
}

$(document).ready(function() {
	tooltip_margin_left = parseInt($("#menu_tooltip1").css("left"));
	
	$("div.text a").each(function() {
		var link = $(this);
		var new_href = "";
						//za ?url=
		var ile_dodac = 5;
		
		var search_str = "popup.php";
		
		if (link.attr('href')=='javascript:void(0)') {
			var onclick = new String(link.attr('onclick'));
			
			new_href = onclick.substring(onclick.indexOf(search_str)+ile_dodac+search_str.length,onclick.indexOf("&clTxt"));
			
			$(this).attr('href',new_href);
			$(this).attr('onclick',"void(0)");
			$(this).attr('title',"");
			$(this).addClass("lightbox2");
		}
	});
	
	mapBaseActions();

	$("#menu_tooltip1").mouseover(function() {
		mouse_over = true;
	}).mouseout(function() {
		mouse_over = false;
		
		menu_fadeOut();
	});
	
	$("#menu li a").mouseover(function() {
		mouse_over = true;
		var add = parseInt($(this).attr('rel'));
		var id = $(this).parent().attr('id');
		
		var new_html = new String($("#sub"+id).html());
		
		$("#menu_options").html(new_html+" ");
		
		$("#menu_tooltip1").css("left",tooltip_margin_left + add);
		
		var new_html = new String($("#menu_options").html());
		
		if (new_html.replace(/^\s+|\s+$/g, '')!="") {
			flipTooltip(id);
			$("#menu_tooltip1").fadeIn("fast");
			$("#menu_tooltip1").fadeTo("fast",0.90);
		}
		else {
			mouse_over = false;
		}
		
	}).mouseout(function() {
		mouse_over = false;
				
		menu_fadeOut();
		
	});
});
