/**
 * @author rgaumond
 */

function loadHeaderButtons()
{
	function_initiated("loadHeaderButtons");
	
	header_buttons_main_container.innerHTML="";
	if(currentUser.status < 24)//make sure header is small
		$("header").style.height=50;
	if (currentUser.status > 19) //organisateurs and up
		team_buttons();
	if(currentUser.status>24)//VP and UP{
		advanced_buttons();	
	if (currentUser.status > 90)//WEBMASTERS 
	{
		/*
		new Buttons.create({
			id: "TEST_PayPal",
			theCaption: "TEST PAYPAL",
			enabled: true,
			onclick_actions: function(){
				window.location.href = "http://localhost/cyclo/index.aspx?execute=paid_paypal&item=396&user=1781";
			},
			positionning: {
				cssFloat: 'left'
			},
			child_of: "button_container",
			class_Prefix: "header",
			tip: null,
			type: "custom"
		});
		*/
		
	}
	
	


	if (currentUser.status > 9)//assistant and up
	{
		load_email_buttons();
	//	load_advance_option();
	}	
	
	if(selected_user.status>0)
		load_logged_in_buttons();
	
	load_navigation_buttons();
	function_completed("loadHeaderButtons");
}

function load_navigation_buttons()
{
	function_initiated("load_navigation_buttons");
	new Buttons.create({id:"faq",
					   theCaption:"FAQ",
					   enabled:true,
					   onclick_actions:function(){
					   	show_faq();
					   	},
					    positionning:{cssFloat:'right'},
					   child_of:"header_buttons_main_container",
					   class_Prefix:"header",
					   tip:null,
						   type:"link"});
	new Buttons.create({id:"Information",
					   theCaption:"Information",
					   enabled:true,
					   onclick_actions:function(){
					   	show_info()
					   	},
					    positionning:{cssFloat:'right'},
					   child_of:"header_buttons_main_container",
					   class_Prefix:"header",
					   tip:null,
						   type:"link"});

	new Buttons.create({id:"Photos",
					   theCaption:"Photos",
					   enabled:true,
					   onclick_actions:function(){
					   	show_albums();
					   	},
					    positionning:{cssFloat:'right'},
					   child_of:"header_buttons_main_container",
					   class_Prefix:"header",
					   tip:null,
						 type:"link"});	
						   						   
	new Buttons.create({id:"Liens Utiles",
					   theCaption:"Liens Utiles",
					   enabled:true,
					   onclick_actions:function(){show_liens()},
					   positionning:{cssFloat:'right'},
					   child_of:"header_buttons_main_container",
					   class_Prefix:"header",
					   tip:null,
						   type:"link"});
	
	new Buttons.create({id:"Calendrier",
					   theCaption:"Calendrier",
					   enabled:true,
					   onclick_actions:function(){calendrier();},
					    positionning:{cssFloat:'right'},
					   child_of:"header_buttons_main_container",
					   class_Prefix:"header",
					   tip:null,
						   type:"link"});
	
	if (current_window == "activite") {
		new Buttons.create({
			id: "Activite",
			theCaption: "Activité",
			enabled: true,
			onclick_actions: function(){
				return false;
			},
			positionning: {
				cssFloat: 'right'
			},
			child_of: "header_buttons_main_container",
			class_Prefix: "header",
			tip: null,
			type: "link"
		});
	}
	new Buttons.create({id:"Accueil",
					   theCaption:"Accueil",
					   enabled:true,
					   onclick_actions:function(){accueil()},
					   positionning:{cssFloat:'right'},
					   child_of:"header_buttons_main_container",
					   class_Prefix:"header",
					   tip:null,
						   type:"link"});
	function_completed("load_navigation_buttons");	
}

function load_logged_in_buttons()
{
		function_initiated("load_logged_in_buttons");				   
		new Buttons.create({id:"Mon Profil",
						   theCaption:"Mon Profil",
						   enabled:true,
						   onclick_actions:function(){show_member_profile(selected_user.id)},
						   positionning:{cssFloat:'right'},
						   child_of:"header_buttons_main_container",
					   	   class_Prefix:"header",
					       tip:null,
						   type:"link"});
		function_completed("load_logged_in_buttons");			
}

function load_email_buttons()
{
	function_initiated("load_email_buttons");
	$("header").style.height=100;
	$("advance_button_container").style.display="block";
	new Buttons.create({id:"cyclo_email",
						   theCaption:"Courriel Cyclo",
						   enabled:true,
						   onclick_actions:function(){javascript:window.open('http://webmail.cycloconcept.ca')},
						   positionning:{cssFloat:'right'},
						   child_of:"advance_button_container",
						   class_Prefix:"header_advance",
						   tip:null,
							   type:"link"});

	new Buttons.create({id:"roue_email",
						   theCaption:"Courriel Roue",
						   enabled:true,
						   onclick_actions:function(){javascript:window.open('http://webmail.larouechampetre.ca')},
						   positionning:{cssFloat:'right'},
						   child_of:"advance_button_container",
						   class_Prefix:"header_advance",
						   tip:null,
							   type:"link"});
	function_completed("load_email_buttons");	
}


function advanced_buttons()
{
	function_initiated("advanced_buttons");
	$("header").style.height=100;
	$("advance_button_container").style.display="block";

	new Buttons.create({id:"Archives",
					   theCaption:"Archives",
					   enabled:true,
					   onclick_actions:function(){
					   	alert("to find the first activity")
					   	//archives(activitees_info.first().id)
					   },
					    positionning:{cssFloat:'right'},
					   child_of:"advance_button_container",
					   class_Prefix:"header_advance",
					   tip:null,
						   type:"link"});	
		new Buttons.create({id:"Parcours",
					   theCaption:"Parcours",
					   enabled:true,
					   onclick_actions:function(){parcours()},
					    positionning:{cssFloat:'right'},
					   child_of:"advance_button_container",
					  class_Prefix:"header_advance",
					   tip:null,
						   type:"link"});	
		new Buttons.create({id:"Parcours_Upload",
					   theCaption:"Ajout Parcours",
					   enabled:true,
					   onclick_actions:function(){parcours_upload()},
					    positionning:{cssFloat:'right'},
					   child_of:"advance_button_container",
					   class_Prefix:"header_advance",
					   tip:null,
						   type:"link"});
						   
		new Buttons.create({id:"Photos_Upload",
					   theCaption:"Ajout Photos",
					   enabled:true,
					   onclick_actions:function(){photo_upload()},
					    positionning:{cssFloat:'right'},
					   child_of:"advance_button_container",
					   class_Prefix:"header_advance",
					   tip:null,
						   type:"link"});
		function_completed("advanced_buttons");		
}

function team_buttons()
{
	function_initiated("team_buttons");
	new Buttons.create({
			id: "ajout_membre",
			theCaption: "Ajouter membre",
			enabled: true,
			onclick_actions: function(){
				selected_user = currentUser;
				show_member_add()
			},
			positionning: {
				cssFloat: 'right'
			},
			child_of: "advance_button_container",
			class_Prefix: "header_advance",
			tip: null,
			type: "link"
		});
		
		new Buttons.create({
			id: "mod_membre",
			theCaption: "Modifier membre",
			enabled: true,
			onclick_actions: function(){
				selected_user = currentUser;
				show_member_list("A");
			},
			positionning: {
				cssFloat: 'right'
			},
			child_of: "advance_button_container",
			class_Prefix: "header_advance",
			tip: null,
			type: "link"
		});
		new Buttons.create({
			id: "ajout_act",
			theCaption: "Ajouter activit&eacute;",
			enabled: true,
			onclick_actions: function(){
				selected_user = currentUser;
				show_activity_add();
			},
			positionning: {
				cssFloat: 'right'
			},
			child_of: "advance_button_container",
			class_Prefix: "header_advance",
			tip: null,
			type: "link"
		});
		function_completed("team_buttons");
}

function is_selected(the_button_id)
{
	function_initiated("is_selected");
	if ($(the_button_id) == null) 
		is_selected.delay(global_delay, the_button_id);
	else {
		if ($(the_button_id + "_selector") == null) {
			createSelector(the_button_id);
			is_selected.delay(global_delay, the_button_id);
		}
		else {
			$$("img.selector").each(function(theImg){
				if(theImg.id!=the_button_id+"_selector"
					&& theImg.id!=current_selected_id)
					theImg.style.display="none";				
			});
			$(the_button_id + "_selector").style.display = "block";
			$(the_button_id + "_selector").onclick = $(the_button_id).onclick;
		}
	}
	function_completed("is_selected");
}

function current_selected(the_button_id)
{
	function_initiated("current_selected");

	if($(the_button_id ) == null && the_button_id!="temp_button")
		current_selected.delay(global_delay, the_button_id);
	else{
		if (the_button_id != "temp_button") {
			if ($(the_button_id + "_selector") == null) {
				createSelector(the_button_id);
				current_selected.delay(global_delay, the_button_id);
			}
			else {
				//current_selected_id is define in globals
				
				if ($(current_selected_id) != null) 
					$(current_selected_id).style.display = "none";
				$(the_button_id).style.cursor = "none";
				$(the_button_id + "_selector").style.display = "block";
				$(the_button_id).setAttribute("selected", true);
				$(the_button_id).onclick = function(){
					return false;
				};
				$(the_button_id).onmouseover = function(){
					return false;
				};
				$(the_button_id).onmouseout = function(){
					return false;
				};
				current_selected_id = the_button_id + "_selector";
			}
		}
		else
		{
			
			if ($(current_selected_id) != null) 
					$(current_selected_id).style.display = "none";
		}
	}
	function_completed("current_selected");
}

function is_deselected(the_button_id)
{
	if($(current_selected_id)!=null)
		$(the_button_id+"_selector").style.display="none";
}

function createSelector(the_button_id)
{
	function_initiated("createSelector");
		var the_selector = document.createElement("img");
		the_selector.id = the_button_id+"_selector";
		the_selector.src = pathToImages+"selected_navigation.gif";
		the_selector.className="selector";
		the_selector.style.position="absolute";
		the_selector.style.display="block";
		the_selector.style.width=20;
		the_selector.style.height=20;
		$("header_buttons_main_container").appendChild(the_selector);
		header_selector = true;	
		var el = $(the_button_id+"_selector");
		
		el.style.left = Element.cumulativeOffset($(the_button_id).parentNode).left
		-Element.cumulativeOffset($("header_buttons_main_container")).left+($(the_button_id).parentNode.getWidth()/2)-10;
		

		el.style.top = Element.cumulativeOffset($(the_button_id).parentNode).top+4;
		function_completed("createSelector");
}

