var jStruttureTesto;
var jToggleLink;
$(window).load(function(){

	$('#p').change(function(e){
		$.get('AjaxComuni.asp?p='+$(this).val(), function(data) {
			$('#tdComuni').html(data);
		});
	});

	jSidebar = $('#Sidebar');
	jToggleLink = $('#ToggleLink');
	jLegendaLink = $("#LegendaLink");
	jStruttureLink = $("#StruttureLink");
	jSidebarFrame = $('#SidebarFrame');
	jSidebarBody = $('#SidebarFrame').contents().find("body");
	jLegenda = jSidebarBody.find("#Legenda");
	jStrutture = jSidebarBody.find("#Strutture");
	jStruttureTesto = jStrutture.find("#StruttureTesto");
	jGoogleMap = $('#GoogleMap');
	jBody = $('body');

	
	isIE = navigator.userAgent.indexOf("IE") > -1;

	Span = (isIE)?20:0;
	Closed = 30;
	Opened = 300;
	Border = 2;
	
	if(!isIE)
	jGoogleMap.css("margin-left",(Closed+Border+Span)+"px");

	jGoogleMap.width( jBody.width()-Closed-Border-Span );
	//jSidebar.fadeIn(500);
	
	jStruttureLink.click(function(e){
	  	e.preventDefault();
		jStrutture.show();
		jLegenda.hide();
	});
	
	jLegendaLink.click(function(e){
	  	e.preventDefault();
		jLegenda.show();
		jStrutture.hide();
	});


	jToggleLink.click(function(e){
		e.preventDefault();
		var t = $(this);
		if( t.hasClass("Closed" ) ){
			t.removeClass("Closed");
			t.addClass("Opened");
			t.html("&lt;&lt;");
			jSidebar.width(Opened+"px");
			jGoogleMap.width( jBody.width()-Opened-Border-Span );
			if(!isIE)
			jGoogleMap.css("margin-left",(Opened+Border+Span)+"px");
			jSidebarFrame.fadeIn(500);
			jStruttureLink.show();
			jLegendaLink.show();
		}
		else if( t.hasClass("Opened" ) ){
			t.removeClass("Opened");
			t.addClass("Closed");
			t.html("&gt;&gt;");
			jSidebarFrame.hide();
			jSidebar.width(Closed+"px");
			jGoogleMap.width( jBody.width()-Closed-Border-Span );
			if(!isIE)
			jGoogleMap.css("margin-left",(Closed+Border+Span)+"px");
			jStruttureLink.hide();
			jLegendaLink.hide();
		}
	});
	
	initialize();

});
