function BrowserDetectLite() {
   var ua = navigator.userAgent.toLowerCase(); 
   // browser name
   this.isIE        = ( (ua.indexOf('msie') != -1) && (ua.indexOf('opera') == -1) && (ua.indexOf('webtv') == -1) ); 
   this.isOpera     = (ua.indexOf('opera') != -1); 
   this.versionMajor = parseInt(this.versionMinor); 
   // dom support
   this.isDOM1 = (document.getElementById);
   // platform
   this.isMac   = (ua.indexOf('mac') != -1);
}
var browser = new BrowserDetectLite();

function initDate(){
	var monthNames = new Array("January","February","March","April", "May","June","July","August", "September","October","November","December");
	var now = new Date();
	var theYear = now.getYear()
	if (theYear < 2000)
    	theYear += 1900;
	if (document.getElementById("jsdate"))
		document.getElementById("jsdate").innerHTML = "Today's Date is " + monthNames[now.getMonth()] + " " + now.getDate() + ", " + theYear;
	else if (document.getElementById("jsdate"))
		document.getElementById("jsdate").innerHTML = "Today's Date is " + now.getDate() + " " + monthNames[now.getMonth()] + " " + theYear;

if (document.getElementById("bodyhome") && document.getElementById("h-photo")) homePhoto();
initMenu;
}

function genRand(x) {
 var range = x;
 return Math.floor(Math.random() * range) + 1;
}

function initMenu() {
    if ( browser.isDOM1 
    	 && !( browser.isMac && browser.isIE ) 
    	 && !( browser.Opera && browser.versionMajor < 7 )
    	 && !( browser.isIE && browser.versionMajor < 5 ) ) {
        // get some element
        var menu = document.getElementById('nav');
        var lis = menu.getElementsByTagName('li');
        // change the style of the menu
        // i am searching for ul element in li element
        for ( var i=0; i<lis.length; i++ ) {            
            // is there a ul element ?
            if ( lis.item(i).getElementsByTagName('ul')[0] ) {
                // improve keyboard navigation with IE
                if ( browser.isIE ) {
                    addAnEvent(lis.item(i),'keyup',visible);
                	// apply the method to DOM compliant browsers
	                addAnEvent(lis.item(i),'mouseover',visible);
    	            addAnEvent(lis.item(i),'mouseout',hidden);
        	        addAnEvent(lis.item(i),'blur',hidden);
            	    addAnEvent(lis.item(i),'focus',visible);
				}
            }
        }
    }
if (document.getElementById("bodyhome") && document.getElementById("rand")) homePhoto();
 initSubNav()
}



function addAnEvent( target, eventName, functionName ) {
    // apply the method to IE
    if ( browser.isIE ) {
        //target.attachEvent( 'on'+eventName, functionName ); // dont work properly with this
        eval('target.on'+eventName+'=functionName');
    }
    // apply the method to DOM compliant browsers
}
    
/* hide the first ul element of the current element */
function hidden() {
    /* setAttribute dont work correctly with IE */
	this.getElementsByTagName('ul')[0].style.display = "none";
}

/* show the first ul element of the current element */
function visible() {
    this.getElementsByTagName('ul')[0].style.display = "block";
}

function initSubNav(){
	if (document.getElementById){
	//turns current subnav item on except on homepage
		if (!document.getElementById('bodyhome')){
			var subnav = document.getElementById('nav');  	//finds subnav element
			var subnavas = subnav.getElementsByTagName('a'); 	//finds all anchors within subnav
			for (var a=0; a<subnavas.length; a++){		//cycles through each link
				var currenthref=String(subnavas[a].href);	//assigns current link href to a string
				var currentloc=String(document.location);	//assigns current document url to a string
			
				//if the current link href matches the document url the anchor is given a class
				if (unescape(currenthref)==unescape(currentloc)){
					subnavas[a].className="navon"
				}
			}
	  	}
	}
	if (document.getElementById){
	//turns current subnav item on except on homepage
		if (!document.getElementById('bodyhome')){
			var subnav = document.getElementById('snav');  	//finds subnav element
			var subnavas = subnav.getElementsByTagName('a'); 	//finds all anchors within subnav
			for (var a=0; a<subnavas.length; a++){		//cycles through each link
				var currenthref=String(subnavas[a].href);	//assigns current link href to a string
				var currentloc=String(document.location);	//assigns current document url to a string
			
				//if the current link href matches the document url the anchor is given a class
				if (unescape(currenthref)==unescape(currentloc)){
					subnavas[a].className="snavon"
				}
			}
	  	}
	}
	 
}

function homePhoto() {
	var ph = genRand(2);
	var phbg = document.getElementById("h-photo");
	var title = document.getElementById("l-photo");
	phbg.style.backgroundImage = "url(img/h-photo" + ph + ".jpg)";
	title.style.backgroundImage = "url(img/l-photo1.jpg)";
	initImage();
}

function genRand(x) {
 var range = x;
 return Math.floor(Math.random() * range) + 1;
}

window.onload=initDate;
