/*
    common.js
*/

/*
============================================================
	Page Top
============================================================
*/
function WinDisIE (){
	var Ypix = document.body.scrollTop || document.documentElement.scrollTop;

	return Ypix;
}

function WinDisNN (){
	Ypix = window.pageYOffset;
	return Ypix;
}

function pagetop () {
	if (navigator.appName.charAt (0) == "N") {
		Ypix = WinDisNN ();
	} else {
		Ypix = WinDisIE ();
	}

	var disY = (Ypix - (Ypix / 3));
	disY = Math.floor (disY);
	if (disY > 0) {
		window.scrollTo (0, disY);
		setTimeout ("pagetop ()", 3);
		clearTimeout ();
	} else {
		clearTimeout ();
	}
}


/*
============================================================
	Pop Up
============================================================
*/
function openImgPop (fi, na, w, h) {
	window.open (fi,na,"width=" + w + ",height=" + h + ",left=0,top=0,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,favorites=no,resizable=yes").focus ();
}


/*
============================================================
	Window Close
============================================================
*/
function window_close () {
	window.opener = window;
	var win = window.open (location.href, "_self");
	win.close ();
}

/* image rollover */
/*
	Standards Compliant Rollover Script
	Author : Daniel Nolan
	http://www.bleedingego.co.uk/webdev.php
*/

function initRollovers() {
	if (!document.getElementById) return
	
	var aPreLoad = new Array();
	var sTempSrc;
	var aImages = document.getElementsByTagName('img');

	for (var i = 0; i < aImages.length; i++) {		
		if (aImages[i].className == 'imgover') {
			var src = aImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			var hsrc = src.replace(ftype, '_o'+ftype);

			aImages[i].setAttribute('hsrc', hsrc);
			
			aPreLoad[i] = new Image();
			aPreLoad[i].src = hsrc;
			
			aImages[i].onmouseover = function() {
				sTempSrc = this.getAttribute('src');
				this.setAttribute('src', this.getAttribute('hsrc'));
			}	
			
			aImages[i].onmouseout = function() {
				if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_o'+ftype, ftype);
				this.setAttribute('src', sTempSrc);
			}
		}
	}
}

// window.onload = initRollovers;
// >>StyleSwitcher


/* Style Switcher */
/*
	Style Sheets change Script
	Author :  Paul Sowden
	http://alistapart.com/stories/alternate/
*/

function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

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;
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
  // for Roll Over
  initRollovers();
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 90);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);





