/**
 *		js/lib.js
 *		------------------------------------------------------------------------
 *		This file is part of the www.justawalk.com's design.
 *		------------------------------------------------------------------------
 *		(c) Copyright 2005 Fabrice Luraine / sofa-design.net.
 *		All Rights Reserved.
 *		------------------------------------------------------------------------  
 */


/* micro api */
function getObj(name)
{
  if (document.getElementById){
		this.obj = document.getElementById(name);
		this.style = document.getElementById(name).style;
  } else if (document.all) {
		this.obj = document.all[name];
		this.style = document.all[name].style;
  } else if (document.layers){
   	this.obj = document.layers[name];
   	this.style = document.layers[name];
  }
}

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; 
 } 
}

/* menu nav */
var blocks=new Array();
function setNav()
{
	var a,i,j,first_id;
	var hash = getBlockTarget();
	
	var first = true; j = 0;
	a=document.getElementsByTagName('a');
	for(i=0;i<a.length;i++){
		if(a[i].className.substr(0,2) == 's_'){
			a[i].onclick=setActiveBlock;
			a[i].onkeypress=a[i].onclick;
			var c = a[i].className;
			var id = c.substr(2);
			blocks[j]='bloc_'+id;
			if(hash=='sessions' || hash=='project' || hash=='documents'){
				if(id==hash) { first_id = blocks[j]; first = false; }
			}
			if(first) { first_id = blocks[j]; first = false; }
			j++;
		}
	}
	setActiveBlock(first_id);
}

function setActiveBlock(id)
{
	var i;
	if(typeof(id) != 'string'){
		var c = this.className;
		id = 'bloc_'+c.substr(2);
	}
	for(i=0;i<blocks.length;i++){
		if(blocks[i]==id){
			showBlock(blocks[i]);
		} else {
			hideBlock(blocks[i]);
		}
	}
	//return false;
}

function showBlock(id)
{
	var e = new getObj(id);
	e.style.display='block';
}

function hideBlock(id)
{
	var e=document.getElementById(id);
	if(typeof(e)!="undefined"){
		e.style.display='none';
	}
}

function getBlockTarget()
{
	return document.location.hash.substr(1);
}

/* ext links */
function extLinks()
{
	var as,i,islink;
	as=document.getElementsByTagName('a');
	for(i=0;i<as.length;i++)
	{
		islink=as[i].href;
		if(islink.indexOf(window.location.hostname)==-1 && islink.indexOf("javascript:")==-1 && islink.indexOf("mailto:")==-1)
		{
		as[i].title += ' ('+islink+')';
		as[i].onclick=function(){
			window.open(this.href,'newwin','');
			return false;};
		as[i].onkeypress=as[i].onclick;
		}
	}
}