var isIE = '';
var bubble_active = '';
var lastShown = '';
var curSt = '';
var laSt = '';
var styles = new Array;
styles[0]="_TURQUOISE";
styles[1]="_CORAL";
styles[2]= "_EMERALD";
var currentStyle;
var lastStyle;
if(readCookie("currentStyle") != null){currentStyle = readCookie("currentStyle");}
if(readCookie("lastStyle") != null){lastStyle = readCookie("lastStyle");}

function randomStyle(){
	var selector= 1;
	if (lastStyle != null){
		//alert("function randomStyle, lastone !=null ->" + lastStyle)
		switch (lastStyle){
			case '_TURQUOISE':
			//alert("switched to ->" + styles[1]);
			bubble_active = styles[1];
			createCookie('lastStyle',styles[1]);
			createCookie('currentStyle',styles[1]);
			lastStyle = styles[1];
			currentStyle = styles[1];
			return styles[1];
			break;
			case '_CORAL':
			//alert("switched to ->" + styles[2]);
			bubble_active = styles[2];
			createCookie('lastStyle',styles[2]);
			createCookie('currentStyle',styles[2]);
			lastStyle = styles[2];
			currentStyle = styles[2];
			return styles[2];
			break;
			case '_EMERALD':
			//alert("switched to ->" + styles[0]);
			bubble_active = styles[0];
			createCookie('lastStyle',styles[0]);
			createCookie('currentStyle',styles[0]);
			lastStyle = styles[0];
			currentStyle = styles[0];
			return styles[0];
			break;
			}		
		}
	else{
	selector= Math.floor(Math.random()*3);
	//alert("function randomStyle, lastone ==null -> " + lastStyle + ", selector == " + selector + ", returned -> " +  styles[selector]);
	bubble_active = styles[selector];
	createCookie('lastStyle',styles[selector]);
	createCookie('currentStyle',styles[selector]);
	lastStyle = styles[selector];
	currentStyle = styles[selector];
	return styles[selector];	
	
	}
}




function switchit(obj, new_style) {
    obj.className = new_style;
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_checkBrowser(NSvers,NSpass,NSnoPass,IEvers,IEpass,IEnoPass,OBpass,URL,altURL) { //v5.0
  var newURL='', userAgent=navigator.userAgent, version=0;
  if (userAgent.indexOf('Netscape') != -1) {
  	version = parseFloat(userAgent.substring(userAgent.indexOf('Netscape')+9,userAgent.length));
    if (version >= NSvers) {if (NSpass>0) newURL=(NSpass==1)?URL:altURL;}
    else {if (NSnoPass>0) newURL=(NSnoPass==1)?URL:altURL;}
  } else if (userAgent.indexOf('MSIE') != -1) {
  	version = parseFloat(userAgent.substring(userAgent.indexOf('MSIE')+4,userAgent.length));
    if (version >= IEvers)
     {if (IEpass>0) newURL=(IEpass==1)?URL:altURL;}
    else {if (IEnoPass>0) newURL=(IEnoPass==1)?URL:altURL;}
  } else if (OBpass>0) newURL=(OBpass==1)?URL:altURL;
  if (newURL) { 
  	 // document.writeln("<link href=\"css/iecss.css\" rel=\"stylesheet\" type=\"text/css\">");
	  isIE = 'true';
 	}
 }

MM_checkBrowser(4.0,0,0,5.5,1,0,0,"IEcase","");

function correctPNG() 
   {
   for(var i=0; i<document.images.length; i++)
      {
	  var img = document.images[i]
	  var imgName = img.src.toUpperCase()
	  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
	     {
		 var imgID = (img.id) ? "id='" + img.id + "' " : ""
		 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
		 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
		 var imgStyle = "display:inline-block;" + img.style.cssText 
		 if (img.align == "left") imgStyle = "float:left;" + imgStyle
		 if (img.align == "right") imgStyle = "float:right;" + imgStyle
		 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle		
		 var strNewHTML = "<span " + imgID + imgClass + imgTitle
		 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
	     + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
		 + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
		 img.outerHTML = strNewHTML
		 i = i-1
	     }
      }
   }
if(isIE=='true'){window.attachEvent("onload", correctPNG);}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_setTextOfLayer(objName,x,newText) { //v4.01
  if ((obj=MM_findObj(objName))!=null) with (obj)
    if (document.layers) {document.write(unescape(newText)); document.close();}
    else innerHTML = unescape(newText);
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function switchStyle(style){
createCookie('currentStyle',style);
currentStyle = style;
bubble_active = style;
createCookie('lastStyle',style);
lastStyle = style;
//alert("Cookie content is: "+ document.cookie);
top.window.location=document.URL; 
}

function getStyle(){
		   /*var i = document.cookie.indexOf('currentStyle');
		   if (i != -1) {
			var  currentStyle = document.cookie.substring(i+13, document.cookie.length)
			 }*/
			if(currentStyle != null){
				 if(isIE == 'true'){
					 //alert("func getStyle, currentStyle != null ->" + currentStyle + ", isIE == "+ isIE +", "+  document.cookie);
					 document.writeln("<link href=\"" + currentStyle + "/css/iecss.css\" rel=\"stylesheet\" type=\"text/css\">");
					 }
					else{
						//alert("func getStyle, currentStyle != null ->" + currentStyle + ", isIE != "+ isIE +", "+ document.cookie)
						document.writeln("<link href=\"" + currentStyle + "/css/css.css\" rel=\"stylesheet\" type=\"text/css\">");
					}
				bubble_active = currentStyle;
			
			}
			else { 
				if(lastStyle != null){
					
					if(isIE == 'true'){
							//alert("func getStyle, currentStyle == null, lastStyle != null " + lastStyle + ", isIE =="+ isIE +", "+ document.cookie);
							 document.writeln("<link href=\"" + randomStyle() + "/css/iecss.css\" rel=\"stylesheet\" type=\"text/css\">");
							 }
						 else{
							 //alert("func getStyle, currentStyle == null, lastStyle != null ->" + lastStyle + ", isIE != " + isIE +", "+ document.cookie)
							 document.writeln("<link href=\"" + randomStyle() + "/css/css.css\" rel=\"stylesheet\" type=\"text/css\">");
							}
					}
					else{
							if(isIE == 'true'){
							//alert("func getStyle, currentStyle == null, lastStyle == null ->" + lastStyle + ", isIE == " + isIE +", "+ document.cookie);
							 document.writeln("<link href=\"" + randomStyle() + "/css/iecss.css\" rel=\"stylesheet\" type=\"text/css\">");
							 }
						 else{
							 //alert("func getStyle, currentStyle == null, lastStyle == null ->" + lastStyle + ", isIE != " + isIE +", "+ document.cookie)
							 document.writeln("<link href=\"" + randomStyle() + "/css/css.css\" rel=\"stylesheet\" type=\"text/css\">");
							}
						}		
						
					}				
		
}
		
getStyle();

function setActiveBubble (){
//	if(bubble_active == null){bubble_active = randomStyle(laSt)}
			//alert("func setActiveBubble, bubble_active == " + bubble_active +", "+ document.cookie)
			switch (bubble_active){
					case "_TURQUOISE":
					document.getElementById("ball1").src="images/ball_1_dwn.png"
					break;
					case "_CORAL":
					document.getElementById("ball2").src="images/ball_2_dwn.png"
					break;
					case "_EMERALD":
					document.getElementById('ball3').src="images/ball_3_dwn.png"
					break;
			}
	}


function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	var ck = name+"="+value+expires+"; path=/";
	if (days != -1) 
	////alert('Cookie\n' + ck + '\ncreated');
	document.cookie = ck;
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i<ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name)
{
	createCookie(name,"",-1);
}


/*  

function saveIt(name)
{
	var x = document.forms[0].cookievalue.value;
	if (!x)
		////alert('Please fill in a value in the input box.');
	else
		createCookie(name,x,'');
}

function readIt(name)
{
	////alert('The value of the cookie is ' + readCookie(name));
}

function eraseIt(name)
{
	eraseCookie(name);
	////alert('Cookie erased');
}
*/