$(function(){
  	var cache = {
    	'': $('.default')
  	};
  	$(window).bind( 'hashchange', function(e) {
    	var url = $.param.fragment();
    	var lienperso = creationlien(url);
    	$( '.contentajax' ).children( ':visible' ).hide();
    	if ( cache[ lienperso ] ) {
      		cache[ lienperso ].show();
    	} else {
      		$( '.loadingajax' ).show();
      		cache[ url ] = $( '<div class="bbq-item"/>' )
        	.appendTo( '.contentajax' )
        	.load( lienperso,function(){
          		$( '.loadingajax' ).hide();
        	}); 
    	}
  	})
  	$(window).trigger( 'hashchange' );		  	
});
  
function getXPos(e){
    return e.pageX || (e.clientX+(document.documentElement.scrollLeft || document.body.scrollLeft));
}  
  
$(function(){	
	$( "#progressbar" ).progressbar({
			value: 0
	});	

	jQuery( "#progressbar" ).click(function(e) {
		var inporcent;
		  posx = 0; posy = 0; 
		  var offset = $(this).offset();
		  if (e.pageX || e.pageY) posx = e.pageX;   
		  else if (e.clientX || e.clientY) posx = e.clientX;
		  inporcent = (posx - offset.left - 1)  * 100 / 190;
		  jwplayer().seek(inporcent * jwplayer().getPlaylistItem()['duration'] / 100); 
	});
	
	$("ul#ticker01").liScroll();
	$(".imagecolorbox").colorbox({height:"100%"});
	$(".colorboxlink").colorbox({width:"700", height:"100%", iframe:true});
});

$(function(){
  SyntaxHighlighter.highlight();
  
});

function creationlien(urlatraiter) {
	var urlaretourner;
	var titre = "Empreintes-digitales";
	if(urlatraiter.substr(0,12) == "categorie?id") {
		$( 'a.selected' ).removeClass( 'selected' );
		titre = titre+" : ";
		if(urlatraiter.substr(13,13) == 2) document.title = titre+"Musique";
		if(urlatraiter.substr(13,13) == 3) document.title = titre+"Culture";
		if(urlatraiter.substr(13,13) == 5) document.title = titre+"Mode";
		if(urlatraiter.substr(13,13) == 4) document.title = titre+"Interviews";
		if(urlatraiter.substr(13,13) == 1) document.title = titre+"Agenda";
		
		urlaretourner = 'pages/categorielayout.php?id'+urlatraiter.substr(12);
		urlatraiter && $( 'a[href="#' + urlatraiter + '"]' ).addClass( 'selected' );
	} else if(urlatraiter.substr(0,7) == "post?id") {
		urlaretourner = 'pages/articlelayout.php?id='+urlatraiter.substr(8);
	} else {
		document.title = titre;
		urlaretourner = urlatraiter;
		$( 'a.selected' ).removeClass( 'selected' );
		$( 'a[href="#"]' ).addClass( 'selected' );
	}
	return urlaretourner;
}
