$(document).ready( function(){
	links = $('link[rel~="alternate"]');
	menu = $('#menu_dolne');
	
	$('#Map > area').each( function(id, obj){
		if( $(obj).is("[alt='Wycieczki']") )
			$(obj).bind('click', function(e){ e.stopImmediatePropagation(); });
		$(obj).bind('mouseover', function(){show(id)}).bind('click', function(e){ e.preventDefault(); changeTo(id)});
	}).bind('mouseout', function(){reverse()}).trigger('mouseover').trigger('mouseout').eq(active).trigger('click')
	
	$('.loginLink').hover(
		function(){ $(this).fadeTo(0,1); },
		function(){ $(this).fadeTo(0,0); }
	).fadeTo(0,0);
	
});

function reverse(){
	show(active);
}

function changeTo(num){
	active = num;
	show(num);
	refreshMenu();
}

function show(num){
	links.eq(num).attr('disabled',false)
	links.each( function(id){
	    if( id!=num )
			this.disabled = true;
	});
}

function refreshMenu(){
	temp = "";
	for(i=0; i<lvl2menu[active].length; i++ ){
		var h = (lvl2menu[active][i][2]!=0)? 'lvl2' : 'additional';
		if( i>0 )
			temp += '<img src="html/gfx/pasek_pion_menu.png" class="pasek_pion" />';
		temp += '<a href="'+lvl2menu[active][i][0]+'" id="'+h+'_'+lvl2menu[active][i][2]+'"'
		if( (typeof lvl2 != 'undefined' && lvl2==lvl2menu[active][i][2]) || (typeof lvl2 == 'undefined' && i==0) )
			temp += ' style="font-weight: 600; text-decoration: underline"';
		temp +=	'>'+lvl2menu[active][i][1]+'</a>';
	}
	menu.html(temp)
}

function include(name)
{
	var path = 'html/js/'
	$('<script type="text/javascript">').attr('src',path+name+'.js').appendTo('head')
}
