Effect.Notify = function(element) {
  element = $(element);
    return new Effect.Appear(element, 
      { afterFinishInternal: function(effect) {
          new Effect.Fade(effect.element,{ delay: 3.6 });
      }});
}

$$("a.hastooltip").each( function(input) {
	new Tooltip(input, {backgroundColor: "#BEE600", 
	                    borderColor: "#9C6", 
	                    textColor: "#000", 
	                    textShadowColor: "#FFF",
	                    delay: 0,
	                    opacity: .85});
});

function checkPasswords()
{
	var password = $('password').getValue();
	var confirmpassword = $('confirmpassword').getValue();
	
	if(confirmpassword != '')
	{
		if(password == confirmpassword )
		{
			$('passwordstatus').update('<span class="success">Passwords match</span>');
		}
		else
		{
			$('passwordstatus').update('<span class="error">Passwords must match</span>');
		}
	}
	else
	{
		$('passwordstatus').update('');
	}
}

function scrollUp(element, class, numvisible)
{
	if(!class)
	{
		class = "thumb";
	}
	
	if(!numvisible)
	{
		numvisibile = 2;
	}
	
	if($(element))
	{
		var offset = $(element).getStyle('top');
		
		if(offset)
		{
			offset = offset.replace(/[a-zA-Z]/gi,"");
		}
		else
		{
			offset = 0;
		}
		
		var child = $(element).firstDescendant();
		var sheight = 0;
		var scrolloffset = 0;
		
		if(child)
		{
			sheight = child.getHeight();
			scrolloffset = sheight * numvisible;
		}
		
		if(offset < 0)
		{
			if( offset % scrolloffset == 0)
			{
				new Effect.MoveBy($(element), scrolloffset, 0, {duration: 1,
																transition: Effect.Transitions.sinoidal
															   }
								 );
			}
		}
	}
}

function scrollDown(element, class, numvisibile)
{
	if(!class)
	{
		class = "thumb";
	}
	
	if(!numvisibile)
	{
		numvisibile = 2;
	}
	
	if($(element))
	{
		var offset = $(element).getStyle('top');
		
		if(offset)
		{
			offset = offset.replace(/[a-zA-Z]/gi,"");
		}
		else
		{
			offset = 0;
		}
		
		var children = $(element).childElements();
		var sheight = 0;
		var scrolloffset = 0;
		var height = 0;
		
		if(children.length > 0)
		{
			sheight = children.first().getHeight();
			scrolloffset = sheight * numvisibile;
			height = children.length * sheight;
		}
		
		if(offset <= 0 && Math.abs(offset) + scrolloffset < height)
		{
			if(offset % scrolloffset == 0)
			{
				new Effect.MoveBy($(element), -scrolloffset, 0, {duration: 1,
																 transition: Effect.Transitions.sinoidal
																}
								 );
			}
		}
	}
}

function scrollShowcasesUp()
{
	var offset = $('showcasethumbs').getStyle('top');
	
	if(offset)
	{
		offset = offset.replace(/[a-zA-Z]/gi,"");
	}
	else
	{
		offset = 0;
	}
	
	var sheight = $$('div.showcasethumb').first().getHeight();
	var scrolloffset = sheight * 2;
	
	if(offset < 0)
	{
		if( offset % scrolloffset == 0)
		{
			new Effect.MoveBy($('showcasethumbs'), scrolloffset, 0, {duration: 1,
																	 transition: Effect.Transitions.sinoidal
																	}
							 );
		}
	}
}

function scrollShowcasesDown()
{
	var offset = $('showcasethumbs').getStyle('top');
	
	if(offset)
	{
		offset = offset.replace(/[a-zA-Z]/gi,"");
	}
	else
	{
		offset = 0;
	}
	
	var sheight = $$('div.showcasethumb').first().getHeight();
	var scrolloffset = sheight * 2;
	var height = $$('div.showcasethumb').length * sheight;
	
	if(offset <= 0 && Math.abs(offset) + scrolloffset < height)
	{
		if(offset % scrolloffset == 0)
		{
			new Effect.MoveBy($('showcasethumbs'), -scrolloffset, 0, {duration: 1,
																	  transition: Effect.Transitions.sinoidal
																	 }
							 );
		}
	}
}

function scrollShowcasesLeft()
{
	var offset = $('showcasesoverview').getStyle('left');
	
	if(offset)
	{
		offset = offset.replace(/[a-zA-Z]/gi,"");
	}
	else
	{
		offset = 0;
	}
	
	var swidth = $$('div.showcaseoverview').first().getWidth();
	var scrolloffset = swidth * 2;
	
	if(offset < 0)
	{
		if( offset % scrolloffset == 0)
		{
			new Effect.MoveBy($('showcasesoverview'), 0, scrolloffset, {duration: 0.5,
																		transition: Effect.Transitions.sinoidal
																	   }
							 );
		}
	}
}

function scrollShowcasesRight()
{
	var offset = $('showcasesoverview').getStyle('left');
	
	if(offset)
	{
		offset = offset.replace(/[a-zA-Z]/gi,"");
	}
	else
	{
		offset = 0;
	}
	
	var swidth = $$('div.showcaseoverview').first().getWidth();
	var width = $$('div.showcaseoverview').length * swidth;
	var scrolloffset = swidth * 2;
	
	if(offset <= 0 && Math.abs(offset) + scrolloffset < width)
	{
		if(offset % scrolloffset == 0)
		{
			new Effect.MoveBy($('showcasesoverview'), 0, -scrolloffset, {duration: 0.5,
																		 transition: Effect.Transitions.sinoidal
																		}
							 );
		}
	}
}

function addEvent(obj, evType, fn)
{ 
	if (obj.addEventListener)
	{ 
		obj.addEventListener(evType, fn, false); 
		return true; 
	}
	else if(obj.attachEvent)
	{ 
		var r = obj.attachEvent("on"+evType, fn); 
		return r; 
	}
	else
	{ 
		return false; 
	} 
}

/***********************************************
* Textarea Maxlength script- © Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for legal use.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

function ismaxlength(obj){
var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
if (obj.getAttribute && obj.value.length>mlength)
obj.value=obj.value.substring(0,mlength)
}

function saveColumns() {
    var notice = $('col_reorder_button');
    notice.update('Momentje...');
    
    var url = '/profiles/savelayout';
    var postBody = '';    

    var col1 = $('portal-column-0');    
    var blocks = document.getElementsByClassName('block', col1);
    postBody += blocks.pluck('id').join(',');
    var col1 = $('portal-column-1');    
    var blocks = document.getElementsByClassName('block', col1);
    postBody += ':' + blocks.pluck('id').join(',');
    var col1 = $('portal-column-2');    
    var blocks = document.getElementsByClassName('block', col1);
    postBody += ':' + blocks.pluck('id').join(',');
    
    postBody = 'order=' + escape(postBody);
    new Ajax.Request(url, {
              method: 'post',
              postBody: postBody,
              onSuccess: function(transport) {                  
                  var notice = $('col_reorder_button');
                  notice.update('Opgeslagen!');
              }
            } );
}