// 19-09-2010
//
// Changelog
// - Added window.external (19-09-2010)
// - Addes slideshow (03-06-2010)
// - Added eventHandler.handleRaw


/*
HTMLSelectElement.prototype.clear = function(){
	this.length = 0;
};
*/

var startTime = 0;




function timerStart(){
	startTime = new Date().getTime();
}
function timerStop(){
	var elapsed = new Date().getTime() - startTime;
	alert(elapsed);
}


/**
 * Short notation of getting the element.
 * 
 * @param id 			The element ID.
 * 
 * @return				The element.
 **/
function $(id) {
	var element = (typeof(id)=='object'?id:document.getElementById(id));
//	alert(element);
//	alert(id);
	if ((element == null)||(element.nodeName=='#text')){
	//	alert('Element = null : '+id);
		return null;
//		return DummyElement; // return a dummy so the page will process normally if you use chainability
	}
	if (element.defined != undefined)	return element;

	
	element._debug = function(elem,newWindow,maxDepth) {
		if (maxDepth==0) {
			newWindow.document.write(String(elem));
			return null;
		}
		newWindow.document.write("<table cellpadding=1 cellspacing=1><style>td{font : normal normal 11px/13px Verdana, Arial, sans-serif;}</style>");
		var a = new Array();
		for (var j in elem) {
			a[a.length] = j;
		}
		a.sort();
		
		for (var i = 0; i < a.length; i++) {
			var key = new String(a[i]);
			if ((key != "debug")&&(key !="_debug")) {
				try {
					var h = new String(elem[key]);
					
					h = h.replaceAll('<script>','');
					h = h.replaceAll('</script>','');
					h = h.replaceAll('</script>','');
					h = h.replaceAll('<','&lt;').replaceAll('>','&gt;').replaceAll('\n','<br>');
					
					newWindow.document.write("<tr><td valign=top>" + key + "</td><td valign=top bgcolor=#EEEEEE NOWRAP><pre>");
					if (typeof(elem[key])=="object"){
						if ((key!="debug")&&(key!="_debug"))
							this._debug(elem[key],newWindow,maxDepth-1);
					}else{
	  				newWindow.document.write(h);
					}
					
  				newWindow.document.write("</pre></td></tr>");
				} catch(err) {
					newWindow.document.write("<tr><td valign=top>" + key + "</td><td valign=top bgcolor=red NOWRAP><pre>" + err.description + "</pre></td></tr>");
				}
			}
		}	
		
		newWindow.document.write("</table>");
	}
	element.debug = function() {
		var keys     = ((arguments[0]!=null)&&(arguments[0]!="")?String(arguments[0]).split('.'):"");
		var maxDepth = arguments[1] || 3;
		var elem = this;
		if (keys!=""){
			for (var i=0;i<keys.length;i++){
				elem = elem[keys[i]];
			}
		}
		var newWindow = window.open("", "", "resizable=yes,scrollbars=yes,toolbar=0,status=1,menubar=no,width=800,height=600");
		newWindow.document.open("text/html");
		this._debug(elem,newWindow,maxDepth);
		newWindow.document.close();
	}

	element.mouseEvent = new Object();
	element.defined   = true;
	return element;
}
/**
 * retrieve the scroll top position
 **/
function scrollTop(){
	if (document.documentElement && !document.documentElement.scrollTop){
		return document.documentElement.scrollTop
	}else if (document.documentElement && document.documentElement.scrollTop){
		return document.documentElement.scrollTop
	}	else if (document.body && document.body.scrollTop){
		return body.scrollTop
	}
}


var getChildnodes = new function( ){
	this.elem = null;
	this.childnodes = new Array();
	
	this.clear = function(){
		this.childnodes = new Array();
		this.elem       = null;
	}
	
	this.checkRequired = function(parent){
		this.clear();
		this.elem = $(parent);
		this._getChildren( this.elem );
		var goodtogo = true;
		var radioID        = new Array();
		var radioChecked   = new Array();		

		for (var i=0;i<this.childnodes.length;i++){
			var className = this.childnodes[i].className.split(' ');
			for (var i2=0;i2<className.length;i2++){
				if (className[i2].trim()=='required'){
					with (this.childnodes[i]){
						switch (tagName){
						case 'INPUT':
							switch (type.toUpperCase()){
								case 'TEXT':
								if (value.trim()==''){
									goodtogo = false;
									style.backgroundColor = '#FFAAAA';
								}else{
									style.backgroundColor = 'white';
								}
								break;
								case 'RADIO':
									radioFound = false;
									for (var i3=0;i3<radioID.length;i3++){
										if (radioID[i3]==id){
											radioFound = true;
											currentRadioID = i3;
											if (checked==true)
												radioChecked[ i3 ] = true;
										}
									}
									// If this is false the item is added for the first time
									if (radioFound==false){
										radioID[ radioID.length ]           = id;
										radioChecked[ radioChecked.length ] = checked;
									}
									break;
							}
							break;
						case 'SELECT':
							value = value.trim();
							
							if ((value=='') || (value=='-1')){
								goodtogo = false;				
								style.backgroundColor = '#FFAAAA';
							}else{
								style.backgroundColor = 'white';
							}
							break;
						}
						
					}
				}
			}
		}
		if (radioChecked.length>0)
			for (var i=0;i<radioChecked.length;i++)
				if (radioChecked[i]==false) {
					$(radioID[i]).style.backgroundColor = '#FFAAAA';
					return false;		
				}else{
					$(radioID[i]).style.backgroundColor = '#FFFFFF';
					
				}
		return goodtogo;
	}
	
	this.parse = function( parent ){
		this.clear();
		this.elem = $(parent);
		this._getChildren( this.elem );
		return this.childnodes;
//		alert(this.childnodes);
	}
	this._getChildren = function( currentElement ){
		if (currentElement.children.length>0){
			for (var i=0;i<currentElement.children.length;i++){
				if (currentElement.children[i].id!=''){
					switch (currentElement.children[i].tagName){
						case 'INPUT':
							this.childnodes[this.childnodes.length] = currentElement.children[i];
						break;
						case 'SELECT':
							this.childnodes[this.childnodes.length] = currentElement.children[i];
						break;
						case 'TEXTAREA':
							this.childnodes[this.childnodes.length] = currentElement.children[i];
						break;
					}
				}
				this._getChildren( currentElement.children[i] );
				
			}
		}else{
			return 'Element has no children...';
		}
	}
	this.getPostString = function(){
		var str   = '';
		var value = '';
		if (this.childnodes.length>0){
			for (var i=0;i<this.childnodes.length;i++){
				value = '';
				switch (this.childnodes[i].type.toUpperCase()){
					case 'CHECKBOX':
						value = (this.childnodes[i].checked==false?0:1);
						break;
					case 'RADIO':
						if (this.childnodes[i].checked)
							value = this.childnodes[i].value
						else
							value = null;
						
							
						break;
					default:
						value = escape(this.childnodes[i].value);
						break;
				}
				if (value != null)
					str +='&' + this.childnodes[i].id + '=' + value;
			}
		}
		return str;
	}
}

var eventHandler = new function(){


	this.attic        = Array();
	this.handle = function(elem,handleValue,ownerValue,waitelem,callBack,raw){
		timerStart();
		this.attic[ this.getFreeIndex() ] = new Attic(elem,handleValue,ownerValue,waitelem,callBack,raw);
	}
	
	
	this.post = function( elem,parent,handleValue,waitelem,callBack ){
		timerStart();
		if ($(elem)==null) return false;
		getChildnodes.parse( parent );
		this.attic[ this.getFreeIndex() ] = new AtticPost( elem, getChildnodes.getPostString() ,handleValue,waitelem,callBack);
	};
	
	this.getFreeIndex = function(){
		index = 0;
		for (var i=0;i<this.attic.length;i++){
			if (this.attic[i].active==false){
				index = i;
				break;
			}
			index = i+1;
		}
		return index;
	};
	

};



function AtticReady( attic ){
	if (attic.owner.elem!=null){
		/*
		if(attic.owner.elem.tagName.toUpperCase()=='IFRAME'){
			var doc; 
			if(attic.owner.elem.contentDocument) { 
			    doc = attic.owner.elem.contentDocument; 
			} else {
			    doc = attic.owner.elem.contentWindow.document; 
			}
			doc.body.innerHTML = attic.responseText; 			
		}else*/
		attic.owner.elem.innerHTML = attic.responseText;
	}
	if (attic.owner.callBack!=null){
		if (typeof(attic.owner.callBack)=='string'){
			eval(attic.owner.callBack+'(attic.owner.elem,attic.responseText);');
		}else{
			attic.owner.callBack(attic.owner.elem,attic.responseText);
		}	
	}

	if (attic.owner.waitelem!=null)
		attic.owner.waitelem.style.visibility = 'hidden';

	attic.owner.active = false;
}


function AtticPost( elem, str, handleValue, waitelem,callBack ){
	this.waitelem = $(waitelem);
	this.elem     = $(elem);
	this.active   = true;
	this.callBack = callBack;
	if (this.waitelem!=null)
		this.waitelem.style.visibility = 'visible';
	
	this.handleValue = handleValue;
	this.xmlHttp = getXmlHttp();
	str = '&atticPost=1&handleValue='+this.handleValue + str;
	
	// Check for IFRame options
	if(this.elem.tagName.toUpperCase()=='IFRAME'){
		this.elem.src = window.hostname+'eventHandler.php?iframe=1'+str;
		if (this.waitelem!=null)
			this.waitelem.style.visibility = 'hidden';
		return true;
	}else{
		this.xmlHttp.owner = this;
		this.xmlHttp.open("POST", window.hostname+'eventHandler.php', true);
		this.xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	// Add a ready state handler to the XML HTTP object:
		this.xmlHttp.onreadystatechange = function( ){
		if (this.readyState == 4){
	        if(this.status == 200) {
	        	AtticReady( this );
	        	}	
			}
		};
	
		// Send the request:
		this.xmlHttp.send(str);
	}
	
}

function getInputChildren( elem ){
	if (elem.children.length>0)
		return elem.children;
}

function getXmlHttp(){
	var xmlHttp = null;
	try {
		xmlHttp = new XMLHttpRequest();
	} catch (e) {
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

function Attic(elem,handleValue,ownerValue,waitelem,callBack,raw){
	this.active      = true;
	this.elem        = $(elem);
	this.handleValue = handleValue;
	this.ownerValue  = ownerValue;
	this.waitelem    = $(waitelem);
	this.callBack    = callBack;
	if (this.waitelem!=null)
		this.waitelem.style.visibility = 'visible';
	this.xmlHttp = getXmlHttp();
	//alert(window.external);
	
	if (raw==null){
		this.xmlHttp.open("GET", window.hostname+'eventHandler.php?handleValue='+this.handleValue+'&ownerValue='+this.ownerValue, true);
	}else{
		this.xmlHttp.open("GET",window.hostname+'eventHandler.php'+this.handleValue+'&ownerValue='+this.ownerValue, true);
	}
	/* why the hellw as here window.external ??!!
	if (raw==null){
		this.xmlHttp.open("GET", (window.external==undefined ? window.hostname : window.external)+'eventHandler.php?handleValue='+this.handleValue+'&ownerValue='+this.ownerValue, true);
	}else{
		this.xmlHttp.open("GET", (window.external==undefined ? window.hostname : window.external)+'eventHandler.php'+this.handleValue+'&ownerValue='+this.ownerValue, true);
	}
	*/
	this.xmlHttp.owner = this;
	
	// Add a ready state handler to the XML HTTP object:
	this.xmlHttp.onreadystatechange = function(){
		if (this.readyState == 4){
			if (this.status == 200){
	        	AtticReady( this );
	        	/*
				if (this.owner.elem!=null){
					this.owner.elem.innerHTML = this.responseText;
					//timerStop();
				}
				if (this.owner.callBack!=null){
					if (typeof(this.owner.callBack)=='string'){
						eval(this.owner.callBack+'(this.owner.elem,this.responseText);');
					}else{
						this.owner.callBack(this.owner.elem,this.responseText);
					}	
				}
					
				if (this.owner.waitelem!=null)
					this.owner.waitelem.style.visibility = 'hidden';
				this.owner.active = false;
				*/
			}else{
				this.owner.elem.innerHTML = 'Error loading x-site :';
			}
		}
	}
	
	// Send the request:
	this.xmlHttp.send(null);	
	
}
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}


function debug( elem ){
	
	var raam = window.open('','mywindow','width=800,height=600');
	raam.document.write(' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"	"http://www.w3.org/TR/html4/strict.dtd">	<html>	  <head></head><body><table style="width:100%">');
	for (property in elem){
		raam.document.write('<tr><td>'+property+'</td><td>'+elem[property]+'</td></tr>');
//		alert(property);
	}
	raam.document.write('</body></html>');
	
}



function setCookie( name, value, expires, path, domain, secure )
{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	
	/*
	if the expires variable is set, make the correct
	expires time, the current script below will set
	it for x number of days, to make it for hours,
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires ){
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	
	document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
		( ( path ) ? ";path=" + path : "" ) +
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}

function getCookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ ){
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name ){
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 ){
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found ){
		return null;
	}
}
// TODO: make this chainable
function showElem( elem,e ){
	e = e || window.event;
	elem = $(elem);
	elem.style.top  = ((e.clientY + scrollTop())+10)+'px';
	elem.style.display = 'block';
	elem.style.left = (((e.clientX) -10)-elem.offsetWidth) + 'px';
}
// TODO: make this chainable
function hideElem( elem ){
	$(elem).style.display = 'none';
}

function getRadiogroupValue( id ){
	
}

var inputCorrection = new function(){
	
	this.email = function( elem ){
		if (elem==null) return false;
		var value = elem.value;
		if (value.trim().length==0) return false;
		// remove the spaces...wicked people
		value = value.split(' ').join('');
		// split it to check if it is an email address
		if ((value.split('@').length==2)&&(value.split('@')[1].split('.').length>1)){
			elem.value = value;
			return true;
		}else
			return false;
	}
	
	this.date = function( elem ){ // dd-mm-yyyy
		if (elem==null) return false;
		if (elem.value.trim().length==0) return false; 
		// Remove all the spaces
		var value = elem.value.split(' ').join('');
		var date  = new Array();
		if (value.split('-').length==3){ // Correct date seperated with dashes
			date = value.split('-');
			if (date[2].length==2)
				date[2] = (date[2]>30?'19':'20')+date[2];
				
		}else if(value.length==8){       // Date written out without the dashes
			date[0] = value.substr(0,2);
			date[1] = value.substr(2,2);
			date[2] = value.substr(4,4);
		}else if(value.length==6){       // date written out as 121281
			date[0] = value.substr(0,2);
			date[1] = value.substr(2,2);
			date[2] = (value.substr(4,2)>30?'19':'20')+value.substr(4,2);
		}else{
			return false;
		}
		if ((date[0]>31)||(date[1]>12)||(date[0]<1)||(date[1]<1)||(date[2]<1930)){
			return false;
		}else{
			elem.value = date[0]+'-'+date[1]+'-'+date[2];
			return true;
		}
	}
	this.firstName = function( elem ){
		if (elem==null) return false;
		var value = elem.value;
		if (value.trim().length==0) return false;
		// make the word lowercase and upper only the first letter
		value = value.toUpperCase().substr(0,1) + value.toLowerCase().substr(1,value.length-1);
		elem.value = value;
		return true;

	}
	this.lastName = function( elem ){
		if (elem==null) return false;
		var value = elem.value;
		elem.value = value.toLowerCase();
		return true;
		// TODO: dingetjes hier met tussenvoegesel enzo
		/*
		var tussenVoegsel = '';
		if (value.split(' ')==2){ // tussen voegsel
			tussenVoegsel = value.split(' ')[0].toLowerCase();
		}
		if (value.trim().length==0) return false;
		// make the word lowercase and upper only the first letter
		value = value.toUpperCase().substr(0,1) + value.toLowerCase().substr(1,value.length-1);
		elem.value = value;
		return true;
		*/
	}
	
	this.dutchPostalCode = function( elem ){ //@TODO: Make the postal code check improved
		if (elem==null) return false;
		var value = elem.value.split(' ').join('');
		if (value.length!=6) return false;
		var firstFour = value.substr(0,4);
		var lastTwo   = value.substr(4,2);
		if ( isNaN(firstFour) ) return false;
		elem.value = firstFour + ' ' + lastTwo.toUpperCase();
		return true;
		
	}
	this.city = function( elem ){
		if (elem==null) return false;
		var value = elem.value;
		if (value.trim().length==0) return false;
		elem.value = value.toUpperCase().substr(0,1) + value.toLowerCase().substr(1,value.length-1);
		return true;
	}
	this.streetWithNumber = function( elem ){
		if (elem==null) return false;
		var value = elem.value;
		if (value.trim().length==0) return false;
		elem.value = value.toUpperCase().substr(0,1) + value.toLowerCase().substr(1,value.length-1);
		return true;
	}
};

function stopBubble( e ){
	e = (e ? e : window.event);
    if (e.stopPropagation) e.stopPropagation(); // DOM Level 2
    else e.cancelBubble = true; 	
}

var groupCache = {};
function elementsById(id){
  if(!groupCache[id]){
    groupCache[id] = [];
  }
  var nodes = groupCache[id];
  for(var x=0; x<nodes .length; x++){
    if(nodes[x].id != ""){
      nodes.splice(x, 1);
      x--;
    }
  }
  var tmpNode = document.getElementById(id);
  while(tmpNode){
    nodes.push(tmpNode);
    tmpNode.id = "";
    tmpNode = document.getElementById(id);
  }
  return nodes;
}


var timers = Array();

function fadeColor(toColor,step,readyfunc){
	alert(this.id);
	this.readyfunc = readyfunc;
	var timerFound = null;
	for (var i = 0 ; i<timers.length ;i++){
		
	}
	if (timerFound == null)
		timers[  timers.length ] = setTimeout(this.fade,1000);
}

var _sliders = Array();

var oplossing = Array();

function heightSlide(element,newheight,steps,style,opacity,index){
	this.index = index;
//	document.getElementById('fapfap').value = 'asasas';
	this.elem          = $(element);
	if (this.elem==null) return false;
	this.height        = (newheight=='old' ? this.elem.oldHeight + 5 : newheight);
	if ((this.elem.oldHeight==undefined)&&(newheight=='old')&&(this.elem.style.display=='none')){
		this.elem.style.display    = 'block';
		this.elem.oldHeight        = this.elem.clientHeight;
		this.elem.style.height     = '0px';
		this.height                = this.elem.oldHeight;
//		this.elem.style.display    = 'block';
		this.elem.style.visibility = 'visible';
	}else{
		this.elem.oldHeight     = this.elem.clientHeight;
	}
	//document.all['fapfap'].value = this.height;
//	document.getElementById('fapfap').innerHTML = newheight;
	if (BrowserDetect.browser == 'Explorer'){
		if ((BrowserDetect.version == 7)||(BrowserDetect.version == 8)){
			this.elem.style.height = this.height;
			return;
		}
	}	
//	alert(newheight);
//	this.currentHeight = this.elem.currentHeight;
	this.steps         = steps;
	this.currentStep   = 0;
	this.heightSteps   = Array();
	this.opacitySteps  = Array();
	this.sinStep       = 90 /steps;
	this.opStep        = 100 / steps;
	this.active        = true;
	_this              = this;
	timers             = Array();
	if (style='curve'){
		if (this.height > this.elem.clientHeight){
			for (var i=0;i<this.steps;i++){
				this.heightSteps[i] = (this.height * Math.sin( ((i*this.sinStep)) * Math.PI/180)) ;// Math.sin( (90+(i*sinStep))*rad);
				this.opacitySteps[i]      = (i*this.opStep);
			}
		}else{
			//alert(this.clientHeight);
			for (var i=(steps-1);i>0;i--){
				this.heightSteps[i] = this.elem.clientHeight -(this.elem.clientHeight * Math.sin( ((i*this.sinStep)) * Math.PI/180)) ;// Math.sin( (90+(i*sinStep))*rad);
				this.opacitySteps[i]      = 100-(i*this.opStep);
			}
	}
	}else{
		return false;
	}
	//alert(this.opacitySteps);
//	alert(_this.index);
	oplossing[this.index] = this.elem;
	setTimeout(_heightSlide,50);
//	setTimeout(this.slide,100);
}


function _heightSlide(){

	for (var i=0;i<_sliders.length;i++){
		if (_sliders[i].active==true){
			
//				alert(_sliders[i]);
			_sliders[i].currentStep++;
			//Math.floor(_sliders[i].heightSteps[_sliders[i].currentStep ]);
//oplossing[i]			alert(_sliders[i].elem.style.height);
			oplossing[i].style.height = Math.floor( _sliders[i].heightSteps[_sliders[i].currentStep ] )+'px';
		//	_sliders[i].fadeoutItem.filter="alpha(opacity="+parseInt(100-(100*(_sliders[i]._this.counter)))+")";				
			oplossing[i].style.filter="alpha(opacity="+parseInt(_sliders[i].opacitySteps[ _sliders[i].currentStep ])+")";
			oplossing[i].style.opacity = (_sliders[i].opacitySteps[ _sliders[i].currentStep ]/100);
				if (_sliders[i].currentStep < _sliders[i].steps){
					setTimeout(_heightSlide,10);
				}else{
					_sliders[i].active = false;
				}
			

		}
	}
	return;
	_this.currentStep++;
	
}

heightSlide.prototype = {
		slide : function(){
			// Loop through the _sliders
		}
};


function _slide(){
}

_slide.prototype = {
	_this : '',
	sliders : Array(),
	
	init : function(){
		//_this = this;
		
	},
	height : function(element, newheight, steps,style,opacity){
		_sliders[ _sliders.length ] = new heightSlide( element, newheight, steps,style,opacity,_sliders.length);
	},
	slide : function( element, height, steps,slidestyle,fadeopacity ){
		_this = this;
		var found        = -1;
		var elem         = $(element);
//		var sinSteps     = 90 / steps;
//		var opacitySteps = 100 / steps;
		
//		var rad = 3.141592654 / 180;
//		alert(rad);
	//	alert(100*sinStep);
//		alert(Math.sin ((182) * (Math.PI/180)));
		if (elem==null) return false;
		for (var i=0;i<this.sliders.length;i++){
			if (this.sliders[i] == null)
				found = i;
		}
		if (found==-1) found = this.sliders.length;
		if (slidestyle=='curve'){
		}
		
		this.sliders[found] = {'heightSteps' :heightSteps,
						       'opacitySteps':opacitySteps,
						       'steps'       :steps,
						       'currentStep' :steps,
						       'timer'       : null,
						       'index'       : found
						       };
		// create the timers
		
		this.sliders[found].timer = setTimeout(_this._slide,0);
		
	},
	
	_slide : function(){
		alert(_this.sliders);
		
	}
	
};


var slide = new _slide();
slide.init();
var BrowserDetect = {
		init: function () {
			this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
			this.version = this.searchVersion(navigator.userAgent)
				|| this.searchVersion(navigator.appVersion)
				|| "an unknown version";
			this.OS = this.searchString(this.dataOS) || "an unknown OS";
		},
		searchString: function (data) {
			for (var i=0;i<data.length;i++)	{
				var dataString = data[i].string;
				var dataProp = data[i].prop;
				this.versionSearchString = data[i].versionSearch || data[i].identity;
				if (dataString) {
					if (dataString.indexOf(data[i].subString) != -1)
						return data[i].identity;
				}
				else if (dataProp)
					return data[i].identity;
			}
		},
		searchVersion: function (dataString) {
			var index = dataString.indexOf(this.versionSearchString);
			if (index == -1) return;
			return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
		},
		dataBrowser: [
			{
				string: navigator.userAgent,
				subString: "Chrome",
				identity: "Chrome"
			},
			{ 	string: navigator.userAgent,
				subString: "OmniWeb",
				versionSearch: "OmniWeb/",
				identity: "OmniWeb"
			},
			{
				string: navigator.vendor,
				subString: "Apple",
				identity: "Safari",
				versionSearch: "Version"
			},
			{
				prop: window.opera,
				identity: "Opera"
			},
			{
				string: navigator.vendor,
				subString: "iCab",
				identity: "iCab"
			},
			{
				string: navigator.vendor,
				subString: "KDE",
				identity: "Konqueror"
			},
			{
				string: navigator.userAgent,
				subString: "Firefox",
				identity: "Firefox"
			},
			{
				string: navigator.vendor,
				subString: "Camino",
				identity: "Camino"
			},
			{		// for newer Netscapes (6+)
				string: navigator.userAgent,
				subString: "Netscape",
				identity: "Netscape"
			},
			{
				string: navigator.userAgent,
				subString: "MSIE",
				identity: "Explorer",
				versionSearch: "MSIE"
			},
			{
				string: navigator.userAgent,
				subString: "Gecko",
				identity: "Mozilla",
				versionSearch: "rv"
			},
			{ 		// for older Netscapes (4-)
				string: navigator.userAgent,
				subString: "Mozilla",
				identity: "Netscape",
				versionSearch: "Mozilla"
			}
		],
		dataOS : [
			{
				string: navigator.platform,
				subString: "Win",
				identity: "Windows"
			},
			{
				string: navigator.platform,
				subString: "Mac",
				identity: "Mac"
			},
			{
				   string: navigator.userAgent,
				   subString: "iPhone",
				   identity: "iPhone/iPod"
		    },
			{
				string: navigator.platform,
				subString: "Linux",
				identity: "Linux"
			}
		]

	};
	BrowserDetect.init();

window.onload = function(){
	/*
	var lis = document.getElementsByTagName('li');
	for ( var i =0; i<lis.length;i++ ){
		lis[i].onmouseover = function(){
			this.fadeColor( '#ffffff',10, this.fadeColor('#000000',10,null) );
		}
		lis[i].fadeColor = fadeColor;
		lis[i].fade = function(){
			alert( this );
		}
	}
	*/
}

