function parseLink(link){
	
	var charLength = link.length - 1,
		pieces = link.split('/');
		
	if (link.charAt(charLength) == '/'){
		
		var last = [pieces[pieces.length - 2], pieces[pieces.length - 3]];
		
			return last;
	}
	
		if (link.charAt(charLength) !== '/'){
		
		var last = [pieces[pieces.length - 1], pieces[pieces.length - 2]];
		
		return last;
			
		}
	
};

$(function(){

  $(window).hashchange( function(){
	
	
	var subs = $('ul#collect-sub li a');
	
	
	

	
	$.each(subs, function(){
		
		var spec = $(this).attr('href');
		
		if (location.hash.indexOf(spec) !== -1 && !$(this).hasClass('active') ) {
			
			
			if (location.hash.indexOf('pre-' + spec) == -1) {
				
				
			subs.removeClass('active').siblings().remove();	
		
			$(this).addClass("active").parent().append('<img src="' + $baseUrl + 'utility/barre_activite3px.jpg"/>');
			
			
			}

			
		} 
		

	});
	
	
	

	if (window.location.href.indexOf('#') == -1) {
	
	var check = parseLink(window.location.href);
	
	}
	
	if (window.location.href.indexOf('#') !== -1) {
		
		var piece = window.location.href.split('#');
		
				
	
	var check = parseLink(piece[0]);

	
	}
	
	
	var container = '#collections';
	
 
		if(check[0] == 'collections' ){
					
				
					if (location.hash == ''){
						
							var firstChild = $('#collect-sub li:last-child a').attr('href');
						
						
						location.hash = '/' + firstChild;
											
										}
						
						if (location.hash !== ''){
							
								var fragment = parseLink(location.hash);
							
							if (location.hash.indexOf("looks") == -1) {
							
							
							
									patience(createCollection(fragment[0]));
									
									
								} 
								
								if (location.hash.indexOf("looks") !== -1) {
									
										var end = parseLink(location.hash),
											en = end[0].split('-');						
								
										patience(createCollectionLooks(end[1],en[1]));
									
									
								}


							
							
						}

			
				} 
				
	
		if(check[0] == 'lagence' && location.hash == '' || location.hash.indexOf('about') !== -1){
			
	
		patience(about());
		
			
		} 
		
			if(check[0] == 'lagence' && location.hash.indexOf('press') !== -1){

			patience(pressLooks());


			} 
		

				
			});
				
				

  $(window).hashchange();
  
});
