/*
function: divLink()
author: Chris Larsen
email: divlink@clarsen.net
date: 6/10/2007
usage: 
<style>
.divStyle {
	background: #ffcc00;
}

.divStyle a{
	color: #0000ff;
	text-decoration: none;
	font-size: 40px;
}

.divStyle a:hover{
	color: #ff0000;
	background: #00ccff;
	text-decoration: underline;
}

.divStyle a:active{
	color: #000000;
	background: #ffff00;
	text-decoration: none;
}
</style>
<script src="divLink.js"></script>
<div onmouseover="divLink(this)" class="divStyle">
	<a href="http://clarsen.net">clarsen.net</a>
</div>
*/

var dLC = new Array();
function divLink(tD){
	
	if(! tD.aN){
		for (i=0; i<tD.childNodes.length; i++){
			if(tD.childNodes[i].nodeName.toUpperCase() == 'A'){
				tD.aN = tD.childNodes[i];
				var tCT = '';
				for(x=0; x<document.styleSheets.length; x++){
					if(document.styleSheets[x].cssText){
						tCT += document.styleSheets[x].cssText
					}else{
						for(z=0; z<document.styleSheets[x].cssRules.length; z++){
							tCT += document.styleSheets[x].cssRules[z].cssText;
						}
					}
				}
				tCT = tCT.replace(/[\r\n]/g, '').replace(/[\t]/g, ' ').replace(/[\}]/g, '');
				tCC = tCT.split('.');
				for(x=1; x<tCC.length; x++){
					if(tCC[x].substring(0,tD.className.length) == tD.className){
						var nAAs = tCC[x].split('{');
						var ANAV = nAAs[1].split(';');
						if(nAAs[0].substring(nAAs[0].length - 1) == ' '){
							nAAs[0] = nAAs[0].substring(0, nAAs[0].length - 1);
						}
						nAAs[0] = nAAs[0].toLowerCase();
						dLC[nAAs[0]] = new Array();								
						for(z=0; z<ANAV.length; z++){
							var nAV = ANAV[z].split(':');
							if(nAV[0].substring(0,1) == ' '){
								nAV[0] = nAV[0].substring(1);										
							}
							if(nAV[1] && nAV[1].substring(0,1) == ' '){
								nAV[1] = nAV[1].substring(1);										
							}
							dLC[nAAs[0]][nAV[0].toLowerCase()] = nAV[1];
						}
					}
				}
				tD.dLC = dLC;
				tD.tCN = tD.className.toLowerCase();
				tD.style.cursor = 'pointer';
				tD.style.background = dLC[ tD.tCN + ' a:hover']['background'];
				tD.aN.style.color = dLC[ tD.tCN + ' a:hover']['color'];
				tD.aN.style.textDecoration = dLC[ tD.tCN + ' a:hover']['text-decoration'];
				tD.onclick = clickDiv;
				tD.onmouseover = mouseOverDiv;
				tD.onmouseout = mouseOutDiv;
				tD.onmousedown = mousedownDiv;
				break;
			}
		}
	}
}

function clickDiv(){
	document.location.href = this.aN.href; 	
}

function mousedownDiv(){
	this.style.background = this.dLC[ this.tCN + ' a:active']['background'];
	this.aN.style.textDecoration = dLC[ this.tCN + ' a:active']['text-decoration'];
	this.aN.style.color = this.dLC[ this.tCN + ' a:active']['color'];
}

function mouseOverDiv(){
	this.style.background = this.dLC[ this.tCN + ' a:hover']['background'];
	this.aN.style.textDecoration = dLC[ this.tCN + ' a:hover']['text-decoration'];
	this.aN.style.color = this.dLC[ this.tCN + ' a:hover']['color'];
}

function mouseOutDiv(){
	this.style.background = this.dLC[this.tCN]['background'];
	this.aN.style.textDecoration = dLC[ this.tCN + ' a']['text-decoration'];		
	this.aN.style.color = this.dLC[ this.tCN + ' a']['color'];
}
