

$(document).ready(function() {
	
	
	
	
	// Scroll de la map
	init_col2height();
        if ($('html.ie6,html.ie7').length > 0) {
            $(window).scroll(function(){
                var top = $(window).scrollTop();
                var margin = top - distFromTop;
                if(margin >= marginMax) margin = marginMax;
                else if(margin <= 0) margin = 0;
                $('#col1').css('margin-top',margin+'px');
            });
        } else {
            $(window).scroll(function(){
                var top = $(window).scrollTop();
                //console.log('top:'+top+' / distFromTop:'+distFromTop+' distFromBottom:'+distFromBottom+' marginMax:'+marginMax);
                if (top > distFromTop && top < distFromBottom) {
                    $('#scrollpart').css({
                        position: 'fixed',
                        top: '0px'
                    });
                } else if (top > distFromBottom) {
                    //var pos = colHeight - $('#scrollpart').height() - $('#wrap_compteur').height();
                    $('#scrollpart').css({
                        position: 'relative',
                        top: marginMax+'px'
                    });
                } else {
                    $('#scrollpart').css({
                        position: 'relative'
                    });
                }
            });
        }

		
}); 



function init_col2height(){
	marginMax = 0;
        distFromTop = $('#bandeau').height() + $('#menu').height() + 20 + $('#compte').height() + 10 + 30 + $('#iphone').height();
        distFromTop += 0; // ajustement
	distFromBottom = $('body').height() - $('#footer').height() - $('#scrollpart').height();
}

function init_pan_map(){
	//pan to
	jQuery.each($(".show_rollmap"),function() {
		$(this).click(function(){		
			ens_id = $(this).attr("id");
			indiceDepart = ens_id.lastIndexOf('p')+1;
			indiceArrivee = ens_id.length;
			ens_id = ens_id.substring(indiceDepart, indiceArrivee);
			$.getJSON(base_ville_url + "thematiques/ajax/?method=getcoord&id="+ens_id+"=&callback=?",
				function(data){							
					if( data.length != 0 ){
						//$.scrollTo( "#content", 700);
						point = new GLatLng( parseFloat(data.ens_latitude), parseFloat(data.ens_longitude) );//coordonnées du marker
						$("div.rollmap").hide();	
						map.panTo( point );
						$("#rollmap"+ens_id).show();
						$("h3.close").click(function() {
							$("div.rollmap").hide();
						});
						$("#map").click(function() {
							$("div.rollmap").hide();
						});
					}
				}
			);
			return false;
		});
	});	
}