var currentURL = window.location.hash;
var currentURL = currentURL.substring(1,currentURL.length);
var oldURL;
var changePage = false;

function listenURL()
{
	
	var currentURL = window.location.hash;
	var currentURL = currentURL.substring(1,currentURL.length);
	if(changePage == true)
	{
		oldURL = currentURL;
		changePage = false;
	}
	
	if(currentURL != oldURL)
	{
		checkAndLoadURL(false);
	}
	else
	{
		//setTimeout("listenURL()", 1000);
	}
	
}


function checkAfk() {

	var url = '/common/php/bhv.updateAfkStamp.php';
	new Ajax.Request(url, {
		method: 'get',
		onComplete: function(transport) {

		}
	});
	
	setTimeout("checkAfk()", 300000);
}


function checkAndLoadURL(wPlayer)
{
 
	var URLanchor =window.location.hash;
	var URLanchor = URLanchor.substring(1,URLanchor.length);
	oldURL = URLanchor;
	
	
	listenURL();

	var reg=new RegExp("/");
	var URLtable=URLanchor.split(reg);
	if(URLtable[0] == "webZeen")
	{
		if(URLtable[1] == "home")
		{
			jumpToSection('comMewNeety',true,'searchMembre');
			//jumpToSection('webZeen',true,false);
		}
	}
	else if(URLtable[0] == "myMewZeec")
	{
		if(URLtable[1] == "home")
		{
			jumpToSection('myMewZeec',true,'myHome');
		}
		else if(URLtable[1] == "newMessage")
		{
			jumpToSection('myMewZeec',true,'newMessage');
		}
		else if(URLtable[1] == "viewMyMessages")
		{
			jumpToSection('myMewZeec',true,'viewMyMessages');
		}
		else if(URLtable[1] == "viewMessages")
		{
			jumpToSection('myMewZeec',true,'viewMessages');
		}
		else if(URLtable[1] == "myFriends")
		{
			jumpToSection('myMewZeec',true,'myFriends');
		}
		
		else if(URLtable[1] == "newPlaylist")
		{
			jumpToSection('myMewZeec',true,'newPlaylist');
		}
		else if(URLtable[1] == "myPlaylists")
		{
			jumpToSection('myMewZeec',true,'myPlaylists');
		}
		else if(URLtable[1] == "myFavourites")
		{
			jumpToSection('myMewZeec',true,'myFavourites');
		}
		
		else if(URLtable[1] == "myInvitationsTo")
		{
			jumpToSection('myMewZeec',true,'myInvitationsTo');
		}
		
		else if(URLtable[1] == "myInvitationsFrom")
		{
			jumpToSection('myMewZeec',true,'myInvitationsFrom');
		}
	}
	else if(URLtable[0] == "comMewNeety")
	{
		if(URLtable[1] == "home")
		{
			jumpToSection('comMewNeety',true,'searchMembre');
		}
		else if(URLtable[1] == "membre")
		{
			jumpToSection('comMewNeety',true,'ficheMembre');
		}
		else if(URLtable[1] == "playlist")
		{
			jumpToSection('comMewNeety',true,'fichePlaylist');
		}
		else
		{
			jumpToSection('comMewNeety',true,'searchMembre');
		}
	}
	else if(URLtable[0] == "inscription")
	{
			jumpToSection('myMewZeec',true,'inscription');
	}
	else
	{
		jumpToSection('comMewNeety',true,'searchMembre');
		//jumpToSection('webZeen',true,false);
	}
	

}

function checkAfterLoadFunction(afterLoadFunction) {
	
	var reg=new RegExp("/");
	var checkParam=currentURL.split(reg);
	
	if(afterLoadFunction=='ficheMembre')
	{
		jumpToFicheMembre(checkParam[2]);
	}
	
	if(afterLoadFunction=='fichePlaylist')
	{
		jumpToFichePlaylist(checkParam[2]);
	}
	
	else if(afterLoadFunction=='myHome')
	{
		jumpToMyHome();
	}
	
	else if(afterLoadFunction=='searchMembre')
	{
		jumpToSearchMembre();
	}
	
	else if(afterLoadFunction=='newMessage')
	{
		jumpToNewMessage(checkParam[2]);
	}
	
	else if(afterLoadFunction=='viewMyMessages')
	{
		jumpToViewMyMessages();
	}
	
	else if(afterLoadFunction=='viewMessages')
	{
		jumpToViewMessages();
	}
	
	else if(afterLoadFunction=='myFriends')
	{
		jumpToMyFriends();
	}
	else if(afterLoadFunction=='myInvitationsTo')
	{
		jumpToMyInvitationsTo();
	}
	else if(afterLoadFunction=='myInvitationsFrom')
	{
		jumpToMyInvitationsFrom();
	}
	
	else if(afterLoadFunction=='newPlaylist')
	{
		jumpToNewPlaylist();
	}
	else if(afterLoadFunction=='myPlaylists')
	{
		jumpToMyPlaylists();
	}
	else if(afterLoadFunction=='myFavourites')
	{
		jumpToMyFavourites();
	}
	else if(afterLoadFunction=='inscription')
	{
		jumpToInscription();
	}
	
}

function sectionLight(nameSection) {
	//$('webZeen').removeClassName('over');
	$('myMewZeec').removeClassName('over');
	$('comMewNeety').removeClassName('over');
	
	$(nameSection).addClassName('over');
}

function rubLight(nameRub) {
	$('rubWall').removeClassName('current');
	$('rubPlay').removeClassName('current');
	$('rubFriends').removeClassName('current');

	$(nameRub).addClassName('current');
}

function rubLightP(nameRub) {
	$('rubWallP').removeClassName('current');
	$('rubFansP').removeClassName('current');
	$('rubSimilairesP').removeClassName('current');
	
	$(nameRub).addClassName('current');
}

function changeTitle(pageTitle) {
	document.title = pageTitle;
}

function jumpToInscription()
{
	$('darkScreen').style.display='block';
	setOpacity(55,'darkScreen');
	var url = '/common/php/navigation.php?container=mainContent&section=inscription&behavior=default';
	new Ajax.Updater('mainContent', url, {
		method: 'get',
		onComplete: function(transport) {
			$('darkScreen').style.display='none';
		}
	});
}

function loadMainMenu() {
	$('darkScreen').style.display='block';
	setOpacity(55,'darkScreen');
	var url = '/common/php/navigation.php?container=mainMenu&section=all&behavior=default';
	new Ajax.Updater('mainMenu', url, {
		method: 'get',
		onComplete: function(transport) {
			$('darkScreen').style.display='none';
			checkAndLoadURL(true);
		}
	});
}

function jumpToFicheMembre(idMembre) {
	changePage = true;
	
	$('darkScreen').style.display='block';
	setOpacity(55,'darkScreen');

	var url = '/common/php/navigation.php?container=mainCol&section=comMewNeety&behavior=ficheMembre&idMembre='+idMembre;
	new Ajax.Updater('mainCol', url, {
	method: 'get',
	onComplete: function(transport) {
		$('darkScreen').style.display='none';
		
		$('darkScreen').style.display='block';
		var url = '/common/php/navigation.php?container=mainContent&section=comMewNeety&behavior=ficheMembre&idMembre='+idMembre;
		new Ajax.Updater('mainContent', url, {
			method: 'get',
			onComplete: function(transport) {
				$('darkScreen').style.display='none';
				
				
				var reg=new RegExp("/");
				var checkParam=currentURL.split(reg);
				
				if(checkParam[3]=='wall')
				{
					jumpToWall(idMembre);
				}
				else if(checkParam[3]=='playlists')
				{
					jumpToPlaylists(idMembre);
				}
				else if(checkParam[3]=='friends')
				{
					jumpToFriends(idMembre);
				}
				else
				{
					jumpToWall(idMembre);
				}
				
				sectionLight("comMewNeety");
				
			}
		});
		
	}
	});
	
}


function jumpToFichePlaylist(idPlaylist) {
	changePage = true;
	
	$('darkScreen').style.display='block';
	setOpacity(55,'darkScreen');

	var url = '/common/php/navigation.php?container=mainCol&section=comMewNeety&behavior=fichePlaylist&idPlaylist='+idPlaylist;
	new Ajax.Updater('mainCol', url, {
	method: 'get',
	onComplete: function(transport) {
		$('darkScreen').style.display='none';
		
		$('darkScreen').style.display='block';
		var url = '/common/php/navigation.php?container=mainContent&section=comMewNeety&behavior=fichePlaylist&idPlaylist='+idPlaylist;
		new Ajax.Updater('mainContent', url, {
			method: 'get',
			onComplete: function(transport) {
				$('darkScreen').style.display='none';
				
				
				var reg=new RegExp("/");
				var checkParam=currentURL.split(reg);
				
				if(checkParam[3]=='wall')
				{
					jumpToWallP(idPlaylist);
				}
				else if(checkParam[3]=='fans')
				{
					jumpToFansP(idPlaylist);
				}
				else if(checkParam[3]=='similaires')
				{
					jumpToSimilairesP(idPlaylist);
				}
				else
				{
					jumpToWallP(idPlaylist);
				}
				
				sectionLight("comMewNeety");
				
			}
		});
		
	}
	});
	
	
}

function jumpToMyHome(){
	
	changePage = true;
	
	$('darkScreen').style.display='block';
	setOpacity(55,'darkScreen');

	var url = '/common/php/navigation.php?container=mainContent&section=myMewZeec&behavior=myHome';
	new Ajax.Updater('mainContent', url, {
	method: 'get',
	onComplete: function(transport) {
		$('darkScreen').style.display='none';

	}
	});	
}

function jumpToNewPlaylist(){
	
	changePage = true;
	
	$('darkScreen').style.display='block';
	setOpacity(55,'darkScreen');

	var url = '/common/php/navigation.php?container=mainContent&section=myMewZeec&behavior=newPlaylist';
	new Ajax.Updater('mainContent', url, {
	method: 'get',
	onComplete: function(transport) {
		$('darkScreen').style.display='none';

	}
	});	
}

function jumpToMyPlaylists(){
	
	changePage = true;
	
	$('darkScreen').style.display='block';
	setOpacity(55,'darkScreen');

	var url = '/common/php/navigation.php?container=mainContent&section=myMewZeec&behavior=myPlaylists';
	new Ajax.Updater('mainContent', url, {
	method: 'get',
	onComplete: function(transport) {
		$('darkScreen').style.display='none';

	}
	});	
}


function jumpToMyFavourites(){
	
	changePage = true;
	
	$('darkScreen').style.display='block';
	setOpacity(55,'darkScreen');

	var url = '/common/php/navigation.php?container=mainContent&section=myMewZeec&behavior=myFavourites';
	new Ajax.Updater('mainContent', url, {
	method: 'get',
	onComplete: function(transport) {
		$('darkScreen').style.display='none';

	}
	});	
}


function jumpToNewMessage(idMembre) {
	changePage = true;
	
	$('darkScreen').style.display='block';
	setOpacity(55,'darkScreen');

	var url = '/common/php/navigation.php?container=mainContent&section=myMewZeec&behavior=newMessage&idMembre='+idMembre;
	new Ajax.Updater('mainContent', url, {
	method: 'get',
	onComplete: function(transport) {
		$('darkScreen').style.display='none';

	}
	});	
	
}

function jumpToMyFriends() {
	changePage = true;
	
	$('darkScreen').style.display='block';
	setOpacity(55,'darkScreen');

	var url = '/common/php/navigation.php?container=mainContent&section=myMewZeec&behavior=myFriends';
	new Ajax.Updater('mainContent', url, {
	method: 'get',
	onComplete: function(transport) {
		$('darkScreen').style.display='none';

	}
	});	
	
}

function jumpToMyInvitationsTo() {
	changePage = true;
	
	$('darkScreen').style.display='block';
	setOpacity(55,'darkScreen');

	var url = '/common/php/navigation.php?container=mainContent&section=myMewZeec&behavior=myInvitationsTo';
	new Ajax.Updater('mainContent', url, {
	method: 'get',
	onComplete: function(transport) {
		$('darkScreen').style.display='none';

	}
	});	
	
}

function jumpToMyInvitationsFrom() {
	changePage = true;
	
	$('darkScreen').style.display='block';
	setOpacity(55,'darkScreen');

	var url = '/common/php/navigation.php?container=mainContent&section=myMewZeec&behavior=myInvitationsFrom';
	new Ajax.Updater('mainContent', url, {
	method: 'get',
	onComplete: function(transport) {
		$('darkScreen').style.display='none';

	}
	});	
	
}

function jumpToViewMyMessages() {
	changePage = true;
	
	$('darkScreen').style.display='block';
	setOpacity(55,'darkScreen');

	var url = '/common/php/navigation.php?container=mainContent&section=myMewZeec&behavior=viewMyMessages';
	new Ajax.Updater('mainContent', url, {
	method: 'get',
	onComplete: function(transport) {
		$('darkScreen').style.display='none';

		
	}
	});
	
	
}

function jumpToViewMessages() {
	changePage = true;
	
	$('darkScreen').style.display='block';
	setOpacity(55,'darkScreen');

	var url = '/common/php/navigation.php?container=mainContent&section=myMewZeec&behavior=viewMessages';
	new Ajax.Updater('mainContent', url, {
	method: 'get',
	onComplete: function(transport) {
		$('darkScreen').style.display='none';

		
	}
	});
	
	
}

function jumpToSearchMembre() {
	changePage = true;
	$('darkScreen').style.display='block';
	setOpacity(55,'darkScreen');
	var url = '/common/php/navigation.php?container=mainContent&section=comMewNeety&behavior=searchMembre';
	new Ajax.Updater('mainContent', url, {
		method: 'get',
		onComplete: function(transport) {
			$('darkScreen').style.display='none';
		}
	});
	
}

function jumpToWall(idMembre) {
	changePage = true;
	$('darkScreen').style.display='block';
	setOpacity(55,'darkScreen');
	var url = '/common/php/navigation.php?container=reactivZoneMembre&section=comMewNeety&behavior=wall&idMembre='+idMembre;
	new Ajax.Updater('reactivZoneMembre', url, {
		method: 'get',
		onComplete: function(transport) {
			$('darkScreen').style.display='none';
			rubLight('rubWall');
		}
	});
	
}

function jumpToWallP(idPlaylist) {
	changePage = true;
	$('darkScreen').style.display='block';
	setOpacity(55,'darkScreen');
	var url = '/common/php/navigation.php?container=reactivZoneMembre&section=comMewNeety&behavior=wallP&idPlaylist='+idPlaylist;
	new Ajax.Updater('reactivZonePlaylist', url, {
		method: 'get',
		onComplete: function(transport) {
			$('darkScreen').style.display='none';
			rubLightP('rubWallP');
		}
	});
	
}

function jumpToPlaylists(idMembre) {
	changePage = true;
	$('darkScreen').style.display='block';
	setOpacity(55,'darkScreen');
	var url = '/common/php/navigation.php?container=reactivZoneMembre&section=comMewNeety&behavior=playlists&idMembre='+idMembre;
	new Ajax.Updater('reactivZoneMembre', url, {
		method: 'get',
		onComplete: function(transport) {
			$('darkScreen').style.display='none';
			rubLight('rubPlay');
		}
	});
	
}

function jumpToFriends(idMembre) {
	changePage = true;
	$('darkScreen').style.display='block';
	setOpacity(55,'darkScreen');
	var url = '/common/php/navigation.php?container=reactivZoneMembre&section=comMewNeety&behavior=friends&idMembre='+idMembre;
	new Ajax.Updater('reactivZoneMembre', url, {
		method: 'get',
		onComplete: function(transport) {
			$('darkScreen').style.display='none';
			rubLight('rubFriends');
		}
	});
	
}

function jumpToSimilairesP(idPlaylist) {
	changePage = true;
	$('darkScreen').style.display='block';
	setOpacity(55,'darkScreen');
	var url = '/common/php/navigation.php?container=reactivZoneMembre&section=comMewNeety&behavior=similairesP&idPlaylist='+idPlaylist;
	new Ajax.Updater('reactivZonePlaylist', url, {
		method: 'get',
		onComplete: function(transport) {
			$('darkScreen').style.display='none';
			rubLightP('rubSimilairesP');
		}
	});
}

function jumpToFansP(idPlaylist) {
	changePage = true;
	$('darkScreen').style.display='block';
	setOpacity(55,'darkScreen');
	var url = '/common/php/navigation.php?container=reactivZoneMembre&section=comMewNeety&behavior=fans&idPlaylist='+idPlaylist;
	new Ajax.Updater('reactivZonePlaylist', url, {
		method: 'get',
		onComplete: function(transport) {
			$('darkScreen').style.display='none';
			rubLightP('rubFansP');
		}
	});
	
}

function jumpToSection(nameSection,wPlayer,afterLoadFunction)
{
	changePage = true;
	$('darkScreen').style.display='block';
	setOpacity(55,'darkScreen');
	
	// mainCol >>
	var url = '/common/php/navigation.php?container=mainCol&section='+nameSection+'&behavior=default';
	new Ajax.Updater('mainCol', url, {
		method: 'get',
		onComplete: function(transport) {
			$('darkScreen').style.display='none';
			
			// mainContent >>
			var url = '/common/php/navigation.php?container=mainContent&section='+nameSection+'&behavior=default';
			$('darkScreen').style.display='block';
			new Ajax.Updater('mainContent', url, {
					method: 'get',
					onComplete: function(transport) {
					$('darkScreen').style.display='none';
					
						// breadCrumbs >>
						var url = '/common/php/navigation.php?container=breadCrumbs&section='+nameSection+'&behavior=default';
						$('darkScreen').style.display='block';
						new Ajax.Updater('breadCrumbs', url, {
							method: 'get',
							onComplete: function(transport) {
								$('darkScreen').style.display='none';
								
								// LoginLink >>
								var url = '/common/php/navigation.php?container=loginLink&section=all&behavior=default';
								$('darkScreen').style.display='block';
								new Ajax.Updater('loginLink', url, {
									method: 'get',
									onComplete: function(transport) {
										$('darkScreen').style.display='none';
										
								
										if(wPlayer == true)
										{
											// altCol >>
											var url = '/common/php/navigation.php?container=altCol&section='+nameSection+'&behavior=default';
											$('darkScreen').style.display='block';
											new Ajax.Updater('altCol', url, {
												method: 'get',
												onComplete: function(transport) {
													$('darkScreen').style.display='none';
													
													if(afterLoadFunction)
													{
														checkAfterLoadFunction(afterLoadFunction);
													}
													
												}
											});
											// end altCol					
										}
										else
										{
											if(afterLoadFunction)
													{
														checkAfterLoadFunction(afterLoadFunction);
													}
										}
										
										if(nameSection == "webZeen")
										{
											changeTitle("MewZeec, Listen & Live - WebZeen, univers musical");
										}
										else if(nameSection == "myMewZeec")
										{
											changeTitle("MewZeec, Listen & Live - MyMewZeec, espace perso");
										}
										else if(nameSection == "comMewNeety")
										{
											changeTitle("MewZeec, Listen & Live - ComMewNeety, exprimer, partager");
										}
										else
										{
											changeTitle("MewZeec, Listen & Live - WebZeen, univers musical");
										}
										
										sectionLight(nameSection);
										
									}
								});
								// end loginLink
							}
						});
						// end breadCrumbs

				}
			});
			// end mainContent
			
		}
	});
	// end mainCol
	
}
