jQuery(document).ready(function(){	
	mapWidth 	=  jQuery('#map-width').val();
	mapHeight 	=  jQuery('#map-height').val();
	jQuery("#map").css({'width':mapWidth,'height':mapHeight});
	cssUrlPre	=	'url(';
	cssUrlSuf	=	')';
	imVal		=	jQuery('#image').val();
	

	jQuery('#map').css('background-image',cssUrlPre.concat(imVal).concat(cssUrlSuf))
	
	
	setTimeout('displaySlide()',50);
	
	jQuery('.points').mouseover(handleEvent);
	jQuery('.points').mouseout(handleEvent);
	
	jQuery('A.jx-load-object').click(handleEvent)
})
        
     function   handleEvent(e){
        t   =   e.type
        o   =   e.target
        c   =   jQuery(o).attr('class');
        switch(c){
         	/*
            case 'points':
               
               switch(t){
                    case 'mouseover':
                        newImage    =   '/wp-content/plugins/map-localizer/images/point_grand.png';
                        
                        adresse = "test";
                       // alert(adresse);
                    break;
                    case 'mouseout':
                        newImage    =   '/wp-content/plugins/map-localizer/images/point_petit.png';
                        adresse="";
                    break;
               }
               jQuery(o).attr('src',newImage);
               jQuery("p").text(adresse);
               
            break;
         	*/
            case 'jx-load-object':
                ajaxLoad(jQuery(o))
                return false;
            break;
         
            case 'jx-load-update':
               //alert('toto')
            break;
         
         
            default:
            
            
            break;
        }
        
     }

function ajaxLoad(o){
    p        =   o.attr('jqParam');
    xPp     =   p.split('|');
    itemParam   =   (xPp[2]) ?   xPp[2]  :   0;
    postDatas      =    {'md':xPp[1],'itemID':itemParam}
	jQuery('#'+xPp[0]).load('?md-script=ajax-float',postDatas);
}



function displayInfo(id,m,o){
	switch(m){
		case 'on':
			newImage    =   '/wp-content/plugins/map-localizer/images/point_grand.png';
			postDatas      =    {'md':'display-info','itemID':id}
   			jQuery('#'+o).load('?md-script=ajax-float',postDatas)
		break;
		case 'off':
			jQuery('#'+o).html('');
			newImage    =   '/wp-content/plugins/map-localizer/images/point_petit.png';  
		break;
	}
	jQuery('#'+id).attr('src',newImage);
}


function displayFrontInfo(id,m,o){	
	switch(m){
		case 'on':
			outImage    =   '/wp-content/plugins/map-localizer/images/point_petit.png';  
			jQuery('.point-box-items').each(function(){
				jQuery(this).fadeOut(0)
				jQuery('.points').attr('src',outImage);
			})
			overImage    =   '/wp-content/plugins/map-localizer/images/point_grand.png';
			jQuery('#'+id).attr('src',overImage);
			jQuery('#'+o+id).fadeIn(200)
			/*
			oTop	=	parseInt(jQuery('#'+id).css('top'))
			oLeft	=	parseInt(jQuery('#'+id).css('left'))
			nTop	=	oTop-2;
			nLeft	=	oLeft-2;
			jQuery('#'+id).animate({'src':newImage,'top':nTop,'left':nLeft},100,function(){
				jQuery('#'+o+id).fadeIn(200)
			})			
			*/
		break;
		case 'off':			
			
			/*
			oTop	=	parseInt(jQuery('#'+id).css('top'))
			oLeft	=	parseInt(jQuery('#'+id).css('left'))
			nTop	=	oTop+2;
			nLeft	=	oLeft+2;
			jQuery('#'+id).animate({'src':newImage,'top':nTop,'left':nLeft},100)
			*/
		break;
	}
}



function suppr(id){
   if(id) {
     if(confirm('Etes vous sur de vouloir supprimer ce point ?')){
	  postDatas      =    {'md':'suppr','itemID':id}
      jQuery('#jx-loader').load('?md-script=ajax-float',postDatas)
	 }
   }
   else{
      alert(error);   
   }
}


function changeretat(id)
{
      
      postDatas      =    {'md':'change-etat','itemID':id}
      
      jQuery('#jx-loader').load('?md-script=ajax-float',postDatas)

}


function liveEdit(id,fld,type,itemID){
    postDatas      =    {'md':'live-edit','id':id,'itemID':itemID,'fld':fld,'type':type}
    jQuery('#'+id).load('?md-script=ajax-float',postDatas)
}

function ajaxSubmit(id,c){
   postDatas   =  jQuery('.'+c).serializeArray();
   jQuery('#'+id).load('?md-script=ajax-float',postDatas)
}


function displaySlide()
{

                 
				 

                 jQuery(".slider-range-x").each(function() {
				 	jQuery(this).slider({
                        range: "min",
						value: jQuery( "#fld-"+jQuery(this).attr('id')).val(),
						min: 1,
						max: mapWidth,
						slide: function( event, ui ) 	{
							                                 jQuery( "#fld-"+jQuery(this).attr('id')).val(ui.value);
														}
                        });
						
                          jQuery(this).mouseup(function(){
                           thisId         =    jQuery(this).attr('id');
                           thisVal        =    jQuery( "#fld-"+jQuery(this).attr('id')).val();
                           postDatas2   =   {'md':'upt-point','coord':'x','val':thisVal,'id':thisId}
                           jQuery('#jx-loader').load('?md-script=ajax-float',postDatas2);
                        
                         })
                         
                         
                          
		});
                 
                 
                  jQuery( ".slider-range-y" ).each(function() {
                          jQuery(this).slider({
                          range: "min",
                          value: jQuery( "#fld-"+jQuery(this).attr('id')).val(),
                          min: 1,
                          max: mapHeight,
                          slide: function( event, ui ) {
                                  jQuery( "#fld-"+jQuery(this).attr('id')).val(ui.value);
                          }
                          });
                           
                           jQuery(this).mouseup(function(){
                             thisId         =   jQuery(this).attr('id');
                             thisVal        =   jQuery( "#fld-"+jQuery(this).attr('id')).val();
                             postDatas2   =   {'md':'upt-point','coord':'y','val':thisVal,'id':thisId}
                            jQuery('#jx-loader').load('?md-script=ajax-float',postDatas2);
                           })
                           
                           
                  }); 
				  
}

function changerimg()
{
   alert('test');
}





/*
function edit(td)
{
td.getElementsByTagName("span")[0].style.display = "none";
td.getElementsByTagName("form")[0].style.display = "inline";
}
*/

