//domCorners by Alessandro Fulciniti on http://web-graphics.com/mtarchive/001660.php

var _ROUND_UPPER = 1
var _ROUND_LOWER = 2;
var _ROUND_ALL = 3;

// IE < 9 do not support getElementsByClassName ...
if (!document.getElementsByClassName) {
	document.getElementsByClassName = function (cn) { 
		var rx = new RegExp("(?:^|\\s)" + cn+ "(?:$|\\s)");
		var allT = document.getElementsByTagName("*"), allCN = [], ac="", i = 0, a;
			while (a = allT[i=i+1]) {
			  ac=a.className;
			  if ( ac && ac.indexOf(cn) !==-1) {
				if(ac===cn){ allCN[allCN.length] = a; continue;   }
				rx.test(ac) ? (allCN[allCN.length] = a) : 0;
			  }
			}
		return allCN;
	}
}


function DomCheck(){
	return(document.createElement && document.getElementById)
}

function DomCorners(type,name,bk,h,mask,withBorder,tries){
	if(type == "id")
		roundIdCorners(name,bk,h,mask,withBorder,tries);
	else	
		roundClassCorners(name,bk,h,mask,withBorder,tries);
}

/* Round corners of one element id */
function roundIdCorners(id,bk,h,mask,withBorder,tries){
	var el=document.getElementById(id);
	if (mask == null) mask = 3;
	if (withBorder == null) withBorder = false;
	if (h == null) h = 6;
	//alert(mask);
	if(el==null){
		if(tries==null) tries=200;
		if(tries>0)
			setTimeout("roundIdCorners('"+id+"','"+bk+"',"+h+","+mask+","+withBorder+","+(--tries)+")",50);
		return;
	}
	doCorners(el,bk,h,mask,withBorder);
}

/* Round corners of element class */
function roundClassCorners(cls,bk,h,mask,withBorder,tries){
    if (mask == null) mask = 3;
	if (withBorder == null) withBorder = false;
	if (h == null) h = 6;
    var els = document.getElementsByClassName(cls);
	if(els.length==0){
		if(tries==null) tries=200;
		if(tries>0)
			setTimeout("roundClassCorners('"+cls+"','"+bk+"',"+h+","+mask+","+withBorder+","+(--tries)+")",50);
		return;
	}
	
    for (var k = 0; k < els.length; k++) {
        var el = els[k];
		doCorners(el,bk,h,mask,withBorder);
    }
}

function doCorners(el,bk,h,mask,withBorder) {
	//alert("h="+h+", mask="+mask+", withBorder="+withBorder);
	
	var c=new Array(4);
	for(var i=0;i<4;i++){
		c[i]=document.createElement("b");
		c[i].style.display="block";
		c[i].style.height=h+"px";
		c[i].style.fontSize="1px";
		
		/*
		if(i%2==0)
        c[i].style.background="url("+bk+") no-repeat 0 -"+ i*h + "px";
    else
        c[i].style.background="url("+bk+") no-repeat 100% -"+ i*h + "px";
		*/
		
		if(i==0) {
			c[i].style.background="url("+bk+") 0 -"+ i*h + "px no-repeat";
			if(withBorder){
				c[i].style.marginLeft="-1px";
				c[i].style.marginTop="-1px";
			}
		} else if(i==1) {
			c[i].style.background="url("+bk+") 100% -"+ i*h + "px no-repeat";
			if(withBorder){
				c[i].style.marginRight="-1px";
				c[i].style.marginTop="-1px";
			}
		} else if(i==2) {
			c[i].style.background="url("+bk+") 0 -"+ i*h + "px no-repeat";
			if(withBorder){
				c[i].style.marginLeft="-1px";
				c[i].style.marginBottom="-1px";
			}
		} else if(i==3) {
			c[i].style.background="url("+bk+") 100% -"+ i*h + "px no-repeat";
			if(withBorder){
				c[i].style.marginRight="-1px";
				c[i].style.marginBottom="-1px";
			}
		}
		
	}
	
	if (mask & _ROUND_UPPER) {
		c[0].appendChild(c[1]);
		el.insertBefore(c[0], el.firstChild);
	}
	if (mask & _ROUND_LOWER) {
		c[2].appendChild(c[3]);
		el.appendChild(c[2]);
	}
	
	if(mask == _ROUND_ALL){
		el.style.padding="0";
	} else if(mask == _ROUND_LOWER) {
		el.style.paddingBottom="0";
	} else if(mask == _ROUND_UPPER) {
		el.style.paddingTop="0";
	}
	
}

// Browser Detect  v2.1.6
// documentation: http://www.dithered.com/javascript/browser_detect/index.html
// license: http://creativecommons.org/licenses/by/1.0/
// code by Chris Nott (chris[at]dithered[dot]com)


function BrowserDetect() {
   var ua = navigator.userAgent.toLowerCase(); 

   // browser engine name
   this.isGecko       = (ua.indexOf('gecko') != -1 && ua.indexOf('safari') == -1);
   this.isAppleWebKit = (ua.indexOf('applewebkit') != -1);

   // browser name
   this.isKonqueror   = (ua.indexOf('konqueror') != -1); 
   this.isSafari      = (ua.indexOf('safari') != - 1);
   this.isOmniweb     = (ua.indexOf('omniweb') != - 1);
   this.isOpera       = (ua.indexOf('opera') != -1); 
   this.isIcab        = (ua.indexOf('icab') != -1); 
   this.isAol         = (ua.indexOf('aol') != -1); 
   this.isIE          = (ua.indexOf('msie') != -1 && !this.isOpera && (ua.indexOf('webtv') == -1) ); 
   this.isMozilla     = (this.isGecko && ua.indexOf('gecko/') + 14 == ua.length);
   this.isFirefox     = (ua.indexOf('firefox/') != -1 || ua.indexOf('firebird/') != -1);
   this.isNS          = ( (this.isGecko) ? (ua.indexOf('netscape') != -1) : ( (ua.indexOf('mozilla') != -1) && !this.isOpera && !this.isSafari && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1) ) );
   
   // spoofing and compatible browsers
   this.isIECompatible = ( (ua.indexOf('msie') != -1) && !this.isIE);
   this.isNSCompatible = ( (ua.indexOf('mozilla') != -1) && !this.isNS && !this.isMozilla);
   
   // rendering engine versions
   this.geckoVersion = ( (this.isGecko) ? ua.substring( (ua.lastIndexOf('gecko/') + 6), (ua.lastIndexOf('gecko/') + 14) ) : -1 );
   this.equivalentMozilla = ( (this.isGecko) ? parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) ) : -1 );
   this.appleWebKitVersion = ( (this.isAppleWebKit) ? parseFloat( ua.substring( ua.indexOf('applewebkit/') + 12) ) : -1 );
   
   // browser version
   this.versionMinor = parseFloat(navigator.appVersion); 
   
   // correct version number
   if (this.isGecko && !this.isMozilla) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('/', ua.indexOf('gecko/') + 6) + 1 ) );
   }
   else if (this.isMozilla) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) );
   }
   else if (this.isIE && this.versionMinor >= 4) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );
   }
   else if (this.isKonqueror) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('konqueror/') + 10 ) );
   }
   else if (this.isSafari) {
      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('safari/') + 7 ) );
   }
   else if (this.isOmniweb) {
      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('omniweb/') + 8 ) );
   }
   else if (this.isOpera) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera') + 6 ) );
   }
   else if (this.isIcab) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab') + 5 ) );
   }
   
   this.versionMajor = parseInt(this.versionMinor); 
   
   // dom support
   this.isDOM1 = (document.getElementById);
   this.isDOM2Event = (document.addEventListener && document.removeEventListener);
   
   // css compatibility mode
   this.mode = document.compatMode ? document.compatMode : 'BackCompat';

   // platform
   this.isWin    = (ua.indexOf('win') != -1);
   this.isWin32  = (this.isWin && ( ua.indexOf('95') != -1 || ua.indexOf('98') != -1 || ua.indexOf('nt') != -1 || ua.indexOf('win32') != -1 || ua.indexOf('32bit') != -1 || ua.indexOf('xp') != -1) );
   this.isMac    = (ua.indexOf('mac') != -1);
   this.isUnix   = (ua.indexOf('unix') != -1 || ua.indexOf('sunos') != -1 || ua.indexOf('bsd') != -1 || ua.indexOf('x11') != -1)
   this.isLinux  = (ua.indexOf('linux') != -1);
   
   // specific browser shortcuts
   this.isNS4x = (this.isNS && this.versionMajor == 4);
   this.isNS40x = (this.isNS4x && this.versionMinor < 4.5);
   this.isNS47x = (this.isNS4x && this.versionMinor >= 4.7);
   this.isNS4up = (this.isNS && this.versionMinor >= 4);
   this.isNS6x = (this.isNS && this.versionMajor == 6);
   this.isNS6up = (this.isNS && this.versionMajor >= 6);
   this.isNS7x = (this.isNS && this.versionMajor == 7);
   this.isNS7up = (this.isNS && this.versionMajor >= 7);
   
   this.isIE4x = (this.isIE && this.versionMajor == 4);
   this.isIE4up = (this.isIE && this.versionMajor >= 4);
   this.isIE5x = (this.isIE && this.versionMajor == 5);
   this.isIE55 = (this.isIE && this.versionMinor == 5.5);
   this.isIE5up = (this.isIE && this.versionMajor >= 5);
   this.isIE6x = (this.isIE && this.versionMajor == 6);
   this.isIE6up = (this.isIE && this.versionMajor >= 6);
   this.isIE6less = (this.isIE && this.versionMajor < 7);
   
   this.isIE4xMac = (this.isIE4x && this.isMac);
}
var browser = new BrowserDetect();
