/* core.js

	dargaville.net
*/
//
//	Useful functions and extensions
//
// value in array (same type)
//
Array.prototype.inArray=function(value){
	for(var i=0,l=this.length;i<l;i++) if(this[i]==value) return true;
	return false;
};
//
//	useful core functions - Joint Object Encapsulation JOE namespave
//
if(!window.JOE) var JOE={};
if(!JOE.core) JOE.core={};
if(!JOE.core.checkEmail) JOE.core.checkEmail=function(email){
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	return filter.test(email);
};
if(!JOE.core.hide) JOE.core.hide=function(){
	var a=arguments;
	for(var x=0;x<a.length;x++){
		document.getElementById(a[x]).style.visibility='hidden';
		document.getElementById(a[x]).style.display='none';
	}
};
if(!JOE.core.checkPassword) JOE.core.checkPassword=function(password){
	// password must contain at least 1 number and 1 character with minimum length 5
	var filter=/((?=.*\d)(?=.*([A-Z]|[a-z]))){5,}/
	return filter.test(password);
};
if(!JOE.core.show) JOE.core.show=function(){
	var a=arguments;
	for(var x=0;x<a.length;x++){
		document.getElementById(a[x]).style.visibility='visible';
		document.getElementById(a[x]).style.display='block';
	}
};

window.addEvent('domready',function(){
	// accordion
	if($('accordion')){
		var accordion=new Accordion('#accordion dt','#accordion dd',{
			opacity:true,
			onActive:function(toggler,element){
				toggler.setStyle('color','#008080');
				toggler.setProperty('title','');
				},
			onBackground:function(toggler,element){
				toggler.setStyle('color','#222');
				toggler.setProperty('title','click to open section');
				}
			},
			$('accordion'));
		// mouseover trigger
		// slight delay to prevent opening when just passing over - about 1/2 sec
		$$('#accordion dt em').each(function(el,i){
			el.addEvent('mouseover',function(){slightDelay=setTimeout(function(){accordion.display(i);},500);});
			el.addEvent('mouseout',function(){clearTimeout(slightDelay);});
		});
		// menu
		if($defined('accordionMenu')){
			$$('#accordionMenu a').each(function(el,i){
				// click
				el.addEvent('click',function(){accordion.display(i);});
				// delayed mouseover
				el.addEvent('mouseover',function(){slightDelay=setTimeout(function(){accordion.display(i);},700);});
				el.addEvent('mouseout',function(){clearTimeout(slightDelay);});
				// prompt
				if(el.getProperty('title')==null) el.setProperty('title','click to open section');
			});
		}
		// link reference
		if(window.location.href.indexOf('#')!=-1){
			var x=window.location.href.substr(window.location.href.indexOf('#')+1);
			if(!isNaN(parseInt(x))&&parseInt(x)<accordion.togglers.length){
				accordion.display(parseInt(x));
			}
		}
		// prompts
		$$('#accordion dt').setProperty('title','click to open section');
	}
});

