// JavaScript Document

function hideloginlabel(obj)
{
	if(obj.className=="username" && obj.value=="Gebruikersnaam")
		obj.value = "";
	else if(obj.className=="password" && obj.type=="text")
	{
		var div = $('password').parentNode;
		$('password').remove();
		var newel = new Element('input', {type: 'password', id: 'password', name: 'password'});
		div.insert(newel); 
	}
}
/*
Effect.SlideIn = function(element) {
  return new Effect.Scale(element, window.opera ? 1 : 0, { 
						  
	scaleY: false,
	scaleFrom: 100,
	scaleTo: 0,
    restoreAfterFinish: true,
    beforeSetup: function(effect) {
      effect.element.makeClipping(); 
    },  
    afterFinishInternal: function(effect) {
      effect.element.hide().undoClipping(); 
    }
  });
};
*/
/*Effect.SlideOut = function(element) {
  return new Effect.Scale(element, window.opera ? 1 : 0, { 
	scaleContent: true, 						  
	scaleY: false,
	scaleFrom: 0,
	scaleTo: 100,
    restoreAfterFinish: true,
    beforeSetup: function(effect) {
      effect.element.show().makeClipping(); 
    },  
    afterFinishInternal: function(effect) {
      effect.element.undoClipping(); 
    }
  });
};
*/
Effect.SlideIn = function(element) {
  element = $(element);
  element.makeClipping();
  return new Effect.Scale(element, 0,
    Object.extend({ scaleContent: false, 
		scaleFrom: 95,
		scaleTo: 0,					  
      scaleY: false, 
      restoreAfterFinish: true,
      afterFinishInternal: function(effect) {
        effect.element.hide().undoClipping();
      } 
    }, arguments[1] || { })
  );
};

Effect.SlideOut = function(element) {
  element = $(element);
//  element.makeClipping();
  return new Effect.Scale(element, window.opera ? 1 : 0,
    Object.extend({ scaleContent: false, 
    scaleFrom: 0,
    scaleTo: 95,				  
      scaleY: false, 
      restoreAfterFinish: true,
		beforeSetup: function(effect) {
			effect.element.makeClipping().show(); 
		},  	  
      afterFinishInternal: function(effect) {
        effect.element.show().undoClipping();
      } 
    }, arguments[1] || { })
  );
};

/*Effect.SlideOut = function(element) {
  element = $(element);
  var elementDimensions = element.getDimensions();
  return new Effect.Scale(element, 100, Object.extend({ 
    scaleContent: false, 
    scaleY: false,
    scaleFrom: 0,
    scaleTo: 100,
    restoreAfterFinish: true,
    afterSetup: function(effect) {
      effect.element.makeClipping().setStyle({width: '0px'}).show(); 
    },  
    afterFinishInternal: function(effect) {
      effect.element.undoClipping();
    }
  }, arguments[1] || { }));
};*/

function Snelnaarmenu()
{
//	this.mode = mode;
	this.isExtended=0;
	this.tabtimer = null;
	this.tabtime = 1000;
	this.shakedistance = 3;
	this.shakeduration = 1;
	if($('atletieksubmenu'))
	{
		var li =$('atletieksubmenu').getElementsBySelector('li');
		if(li.length<=3)
			this.mode=true;
		else
			this.mode = false;
	}
	else
		this.mode = true;

	if(this.mode)
	{
		if($('quicklinks56'))
			$('quicklinks56').hide();	
		$('snelnaarbottom').hide();		
		$('snelnaarcontainer').hide();				
		this.showtab(this.mode);
//		$('snelnaartab').addClassName('snelnaartab_in');		
	}
	else
	{
		if($('quicklinks56'))
			$('quicklinks56').show();		
		$('snelnaartab').addClassName('snelnaartab_in');
		//$('snelnaarbottom').show();		
		//$('snelnaarcontainer').show();		
		this.shaketab();
		//this.hidetab();
		Event.observe('snelnaartab', 'click', this.slideSideBar2.bind(this), true);		
	}	
	
}




Snelnaarmenu.prototype = {
	showtab: function()
	{
		this.isExtended=1;	
		/*new Effect.Parallel([
			new Effect.SlideOut('snelnaarcontainer',{sync: true}),
			new Effect.SlideOut('snelnaarbottom',{sync: true})
		],{duration: 0.5, queue: 'end'});		
		*/
		new Effect.SlideOut('snelnaarcontainer',{duration: 0.1, queue: 'end', afterFinish : function() { $('snelnaarbottom').show();	}
							});
		//$('snelnaarbottom').show();		
		//$('snelnaarcontainer').show();
		if(!this.mode)
		{
			$('snelnaartab').removeClassName('snelnaartab_in');
			$('snelnaartab').addClassName('snelnaartab_uit');
		}
	},
	hidetab: function()
	{
		this.isExtended=0;	
		/*new Effect.Parallel([
			new Effect.SlideIn('snelnaarcontainer',{sync: true,duration: 0.5}),
			new Effect.SlideIn('snelnaarbottom',{sync: true,duration: 0.5})
		],
		{duration: 0.5, queue: 'end'});*/

		
		$('snelnaarbottom').hide();
//		$('snelnaarcontainer').hide();	
		new Effect.SlideIn('snelnaarcontainer',{duration: 0.1, queue: 'end'});
		$('snelnaartab').removeClassName('snelnaartab_uit');
		$('snelnaartab').addClassName('snelnaartab_in');
		
	},	
	shaketab: function()
	{
		new Effect.Shake('snelnaar',{distance:this.shakedistance, duration:this.shakeduration, queue: 'front'});
		
		//this.tabtimer = setTimeout(this.shaketab.bind(this), this.tabtime);
	},
	slideSideBar2: function(event) 
	{
		var element = Event.element(event);
		if(element!=$('snelnaartab'))
		{
			return;
		}
		if(this.isExtended==0)
		{
			this.showtab(this.mode);				
			//setTimeout(this.showtab.bind(this), this.tabtime);			

			//clearTimeout(this.tabtimer);
		}
		else
		{
			this.hidetab();
			//setTimeout(this.hidetab.bind(this), this.tabtime);
			//this.shaketab();
		
		}
	}
}

function login()
{
	var url = 'lib/inloggen.php';		
	var form = $('loginform');
	var parameters = Form.serialize(form);
		new Ajax.Request(url, {   
		method: 'post',  
		parameters: parameters,
		onSuccess: function(transport) 
		{  		
			var result = transport.responseText;
			//alert(result);
			var myObject = eval('(' + transport.responseText + ')');
			if(myObject.error!="")
			{
				$('loginerror').update(myObject.error+'<br /><br />Terug').show();
			}
			else
			{
				window.location = 'index.php?page='+myObject.page;	
			}
		}
	});	
}

function logout()
{
	var url = 'lib/inloggen.php';		
	var form = $('logoutform');
	var parameters = Form.serialize(form);
		new Ajax.Request(url, {   
		method: 'post',  
		parameters: parameters,
		onSuccess: function(transport) 
		{  		
			var myObject = eval('(' + transport.responseText + ')');
			if(myObject.error!="")
			{
				$('loginerror').update(myObject.error+'<br /><br />Terug').show();
			}
			else
			{
				window.location = 'index.php?page='+myObject.page;				
			}		
		}
	});	
}

function hideloginerror()
{
	$('loginerror').hide();
}