$(document).ready(
	function() { 
	  // Popups 
	  $('div.popup').Draggable({
		  zIndex: 	1000,
		  ghosting:	true,
		  opacity: 	0.4
	  });
	  
	  $('ul.listing span').click(function(){
	    var popup = $('#' + this.id.substring(1,this.id.length));
	    $('div.popup').hide();
			popup.fadeIn('normal');
	    this.blur();   
      return false; 	      
	  });
	  
	  $('div.popup span').click(function(){
	    $(this).parent().fadeOut('normal');
        return false;  
	  });
	  // End Popups
	  
	  // Pic Toggler
	  function toggleInfos(cls) {
	    $('div.popup').hide();
	    $('#description div.block').hide();
	    $('#viewer-left img').hide();
	    $('#origin a').hide();
	    $('#browser ul').hide();
	    if(cls) {
	      $('#description div.' + cls).show();
	      $('#viewer-left img#pic-' + cls).show();
	      $('#origin a.' + cls).show();
	      $('#browser ul.' + cls).show();
	    }
	    else {
	      $('#description :first-child').show();
	      $('#viewer-left :first-child').show();
	      $('#origin :first-child').show();
	    }
	  }
	  toggleInfos();
	  
	  	     
	  $('#viewer-right li').click(function() {
	    toggleInfos(this.id);
	  })
	  
	  $('#browser li').click(function() {
	    $('#viewer-left img').hide();
	    $('#viewer-left img#pic-' + this.className.replace('br-', '')).show();
	    if(this.id.indexOf('-off') > -1) {
	      this.id = this.id.replace('-off', '-on');
	      this.innerHTML = "Détails";
	      this.className = this.className + '2';
	    }
	    else if (this.id.indexOf('-on') > -1) {
	      this.id = this.id.replace('-on', '-off');
	      this.innerHTML = "Vue d’ensemble";
	      this.className = this.className.substring(0, this.className.length -1);
	    }
	  })
	  
	  // tabs
	   
	  toggleTabs = function(cls, jump) {
	    jump = jump || false
	    $('div.section').hide();
	    $("#tabs li").css('background', '#eee');
	    $("#tabs li").css('cursor', 'pointer');
	    if(cls) {
	      $('#section-' + cls).show();
	      $('#li-' + cls).css('background', '#fff');
	      $('#li-' + cls).css('cursor', 'default');
	    }
	    else {
	      $('#section-1').show();
	      $('#tabs :first-child').css('background', '#fff');
	      $('#tabs :first-child').css('cursor', 'pointer');
	    }
	    
	    return jump ? true : false
	  }
	  toggleTabs();
	  
	  $("#container li").click(function() {
	    toggleTabs(this.id.replace('li-', ''));
	  })	  
	  
	  $("#map area").click(function() {
	    return toggleTabs(this.id.replace('ma-', ''), true);
	  })
	  
	}
	
)
      
