runinit();
var scrolldirection=1;

//	alert(document.cookie);
//	document.title = document.title + 'This page would look better if you used Firefox :-P' ;
//	alert(parent.frames.length);
//	alert(window.parent.main.document);
//	alert(document.cookie);
//	alert(navigator.appName + ' | ' + navigator.appVersion + ' | ' + navigator.appCodeName + ' | ' + navigator.userAgent);


function runinit(){
	if (document.cookie.indexOf('style=') != -1) {
		mystyle = readCookie('style');
		setActiveStyleSheet(mystyle);
	}
	if (navigator.appName == "Microsoft Internet Explorer" && (parseInt(navigator.appVersion) >= 4)) scrollbarcolor();
	if (navigator.appName == "Microsoft Internet Explorer" && (parseInt(navigator.appVersion) >= 4) && (parseInt(navigator.appVersion) < 7) && navigator.userAgent.indexOf('Opera') == -1) window.onload = fixpngalphaforshittybrowser;
	if (window.name == 'left') {
		styleswitcher();
		if (document.cookie.indexOf('style=') != -1) stylemenuactive(mystyle); //don't call before styleswitcher() has run
	}
}


function styleswitcher(){
	document.write('<style type="text/css">');
	document.write('span.styleswitcher { display: none; position: absolute; bottom: 15px; left: 0px; line-height: 15px; font-size: 12px; background: #FFFFFF; opacity: 0.7; margin: 0px; padding: 3px; z-index: 10; border-width: 1px ; border-color: #000000; border-style: solid ; background-image: url("backbw.jpg")} html>body span.styleswitcher {background-image: none}');
	document.write('span.styleswitcher a { color: #000000; text-decoration: none; white-space: nowrap ; font-weight: normal }');
	document.write('span.styleswitcher a:hover { color: #000000; text-decoration: none; background-color: #BBBBBB }');
	document.write('span.styleswitchericon { position: absolute; bottom: 4px; left: 4px; background: #FFFFFF; width: 56px; height: 15px; margin: 0px; color: #000000; font-size: 12px; padding-left: 2px; z-index: 10; border-width: 1px; border-color: #000000; border-style: solid}');
	document.write('</style>');
	document.write('<span class="styleswitchericon" onclick="openclosestyleswitch(1,1)" onmouseover="openclosestyleswitch(1,0)">pick style</span>');
	document.write('<span id="styleswitcher" class="styleswitcher" onclick="openclosestyleswitch(0,1)">');
	var i, a;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("stylesheet") != -1 && a.getAttribute("title")) {
			document.write('<a id="' + a.getAttribute("title") + '" href="javascript:setActiveStyleSheet(\'' + a.getAttribute("title") + '\',1);">' + a.getAttribute("title") + '</a><br>');
		}
	}
	document.write('</span>');
}

function stylemenuactive(title) { // show the current stylesheet as active in the menu. don't call this before styleswitcher()
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("stylesheet") != -1 && a.getAttribute("title")) {
			if (a.disabled == false) {
				document.getElementById(a.getAttribute("title")).style['color'] = '#666666';
				document.getElementById(a.getAttribute("title")).style['font-style'] = 'italic';
			} else {
				document.getElementById(a.getAttribute("title")).style['color'] = '#000000';
				document.getElementById(a.getAttribute("title")).style['font-style'] = 'normals';
			}
		}
	}
}

function openclosestyleswitch(open,close) {   // call with (1,1) for toggle, (1,0) to open only, (0,1) to close only
	if (document.getElementById('styleswitcher').style['display'] != 'inline' && open) {
		document.getElementById('styleswitcher').style['display'] = 'inline' ;
	} else if (document.getElementById('styleswitcher').style['display'] == 'inline' && close) {
		document.getElementById('styleswitcher').style['display'] = 'none' ;
	}
}

function setActiveStyleSheet(title,allframes) {
	var f, i, a;
		for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
			if(a.getAttribute("rel").indexOf("stylesheet") != -1 && a.getAttribute("title")) {
				a.disabled = true; // not doing if/else since IE wont understand turning on a stylesheet without turning it off first..
				if(a.getAttribute("title") == title) a.disabled = false;
			}
		}
	if (allframes && window.parent.frames.length != 0) {	// load style in all frames if called with (title,1)
		for (f=0; f < window.parent.frames.length ; f++) {
			for(i=0; (a = window.parent.frames[f].document.getElementsByTagName("link")[i]); i++) {
				if(a.getAttribute("rel").indexOf("stylesheet") != -1 && a.getAttribute("title")) {
					a.disabled = true;
					if(a.getAttribute("title") == title) a.disabled = false;
				}
			}
		}
	}
	createCookie('style', title, 7);
	if (allframes && window.name == 'left') stylemenuactive(title); // show the new stylesheet as active in the menu
}


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 expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

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 showhide(showorhide,elem){
	if (showorhide == 'show') {
		var displayhideme='inline';
		var displayshowhiddenlink='none';
	} else {
		var displayhideme='none';
		var displayshowhiddenlink='inline';
	}
	var elements = document.getElementsByTagName(elem);
	for(var i = 0; i < elements.length; i++){
		var node = elements.item(i);
		for(var j = 0; j < node.attributes.length; j++) {
			if(node.attributes.item(j).nodeName == 'class') {
				if(node.attributes.item(j).nodeValue.slice(0,6) == 'hideme') {
					eval('node.style.display=displayhideme');
				}
			}
		}
	}
	document.getElementById('hidehidden').style['display'] = displayhideme;
	document.getElementById('showhidden').style['display'] = displayshowhiddenlink;
}		//document.styleSheets[0].cssRules[1]].style.display='inline')


function scrollpage(scrollpixels,secondrun){
	var position=document.documentElement.scrollTop;
	var scrolltot = 0;
	var scrollstep = 0;
	var scrollthis = 0;
	while (scrolltot  < scrollpixels) {
		if ((scrolltot + scrollstep + 1) * 2 < scrollpixels ) {
			scrollstep++;	// speedup for first half of scrolldistance
			scrollthis=scrollstep;
		} else if (scrolltot * 2 < scrollpixels) {
			scrollthis=(scrollpixels - scrolltot * 2); // middle
		} else {
				scrollthis=scrollstep;
				scrollstep--; //slowdown for second half
		}
		scrollthis=scrollthis-10; // -10 : will scroll 10 pixels one-by-one before speeding up and 30 after slowing down
		if (scrollthis < 1) scrollthis = 1;
		scrolltot = scrolltot + scrollthis;
		self.scrollBy(0,scrollthis * scrolldirection);
	}
	if (secondrun != 1) {if (position == document.documentElement.scrollTop ) { // switch direction at top/bottom
		scrolldirection = -scrolldirection ;
		scrollpage(scrollpixels,1);
	}}
}


function scrollbarcolor(){		// for IE (..importing from .js to have valid .css)
	document.write('<style type="text/css">');
	document.write('html {');
	document.write('scrollbar-face-color: #eeeeff;		');
	document.write('scrollbar-highlight-color: #ffffff;	');
	document.write('scrollbar-shadow-color: #555566;	');
	document.write('scrollbar-3dlight-color: #ffffff;	');
	document.write('scrollbar-arrow-color: #000000;		');
	document.write('scrollbar-track-color: #bbbbcc;		');
	document.write('scrollbar-drawshadow-color: #ccccdd}');
	document.write('</style>');
}


function fixpngalphaforshittybrowser(){    // Fix PNG alpha transparency for all images for IE. Thanks http://homepage.ntlworld.com/bobosola/pnghowto.htm
//alert(document.images.length);
   for(var i=0; i<document.images.length; i++)
   {
      var img = document.images[i]
      var imgName = img.src.toUpperCase()
//	alert(imgName);
      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 imgwidth=img.width + "px";
//if (imgName.substring(imgName.length-6, imgName.length) == "HR.PNG") {imgwidth='100%';}
//alert(img.width);
         var strNewHTML = "<span " + imgID + imgClass + imgTitle
         + " style=\"" + "width:" + img.width + "; height:" + img.height + "px;" + imgStyle + ";"
         + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
         + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
         img.outerHTML = strNewHTML
         i = i-1
      }
   }
}

function fixpngie(img){    // Fix PNG alpha transparency for one image for IE.
    if (navigator.appName == "Microsoft Internet Explorer" && (parseInt(navigator.appVersion) >= 4) && (parseInt(navigator.appVersion) < 7) && navigator.userAgent.indexOf('Opera') == -1) {
	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 mOver = (img.onmouseover) ? "onmouseover='" + img.onmouseover + "' " : ""
//	 alert('ok:' + img.onmouseover);
//	 alert(mOver);
	 var mOver = "";
	 if (img.id == 'up') var mOver = "onmouseover='uphover();' onmousedown='uppress();' onmouseup='upexitpress();' onmouseout='upexithover();'";
	 if (img.id == 'down') var mOver = "onmouseover='downhover();' onmousedown='downpress();' onmouseup='downexitpress();' onmouseout='downexithover();'";
	var strNewHTML = "<span " + imgID + imgClass + imgTitle + mOver
	+ " style=\"" + "width:" + img.width + "; height:" + img.height + "px;" + imgStyle + ";"
	+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
	+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
	img.outerHTML = strNewHTML
    }
}
