// This is the implementation of SimpleSwap
// by Jehiah Czebotar
// Version 1.1 - June 10, 2005
// Distributed under Creative Commons
//
// Include this script on your page
// then make image rollovers simple like:
// <img src="/images/ss_img.gif" oversrc="/images/ss_img_over.gif">
//
// http://jehiah.com/archive/simple-swap
// 

function SimpleSwap(el,which){
  el.src=el.getAttribute(which || "origsrc");
}

function SimpleSwapSetup(){
  var x = document.getElementsByTagName("img");
  for (var i=0;i<x.length;i++){
    var oversrc = x[i].getAttribute("oversrc");
    if (!oversrc) continue;
      
    // preload image
    // comment the next two lines to disable image pre-loading
    x[i].oversrc_img = new Image();
    x[i].oversrc_img.src=oversrc;
    // set event handlers
    x[i].onmouseover = new Function("SimpleSwap(this,'oversrc');");
    x[i].onmouseout = new Function("SimpleSwap(this);");
    // save original src
    x[i].setAttribute("origsrc",x[i].src);
  }
}

var PreSimpleSwapOnload =(window.onload)? window.onload : function(){};
window.onload = function(){PreSimpleSwapOnload(); SimpleSwapSetup();}

// Input Focus
// for Search Bar

function inputFocus(ref, defaultString) {
	if (ref.value == defaultString) {
		ref.value = '';
	}
}

function inputBlur(ref, defaultString) {
	if (ref.value == '')  {
		ref.value = defaultString;
	}
}


// For DHTML Micro API
// http://www.quirksmode.org/js/dhtmloptions.html
// *
// Thanks to http://www.quirksmode.org

var DHTML = (document.getElementById || document.all || document.layers);

function getObj(name){
  if (document.getElementById)
  {
  	this.obj = document.getElementById(name);
	this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else if (document.layers)
  {
	this.obj = getObjNN4(document,name);
	this.style = this.obj;
  }
}

function getObjNN4(obj,name)
{
	var x = obj.layers;
	var foundLayer;
	for (var i=0;i<x.length;i++)
	{
		if (x[i].id == name)
		 	foundLayer = x[i];
		else if (x[i].layers.length)
			var tmp = getObjNN4(x[i],name);
		if (tmp) foundLayer = tmp;
	}
	return foundLayer;
}

function changeAtt(obj,att,newValue) {
	if (!DHTML) return;
	var thisObj = new getObj(obj);
	thisObj.obj[att] = newValue;
}

function changeStyle(obj,att,newValue) {
	if (!DHTML) return;
	var thisObj = new getObj(obj);
	thisObj.style[att] = newValue;
}

function changeDesignObjSrc(obj,color) {
	if (!DHTML) return;
	var thisObj = new getObj(obj);
	var thisObjSrc = thisObj.obj.src;
	var arrObjSrc = thisObjSrc.split(".");
	var thisObjExt = arrObjSrc[3]
	var thisObjFirstPart = arrObjSrc[0]+"."+arrObjSrc[1]+"."+arrObjSrc[2]
	var arrObjName = thisObjFirstPart.split("_");
	var thisObjName = arrObjName[0]
	var thisObjColor = color;
	var arrObjColor = thisObjColor.split("#");
	newImage = new Image();
	newImage.src = thisObjName+'_'+arrObjColor[1]+'.'+thisObjExt;
	thisObj.obj.src = newImage.src;
}

function changeText(obj,newValue) {
	if (!DHTML) return;
	var thisObj = new getObj(obj);
	var otherObj = new getObj(newValue);
	otherObj.obj.firstChild.nodeValue=thisObj.obj.value;
}

function toggleStyle(obj,att,t1,t2) {
	if (!DHTML) return;
	var thisObj = new getObj(obj);
	if (thisObj.style[att]  == t1) {
		thisObj.style[att] = t2;
	} else {
		thisObj.style[att] = t1;
	}
}
// PRELOAD

/*var preImages = new Array();
function preloading(){
	for (x=0; x<preloading.arguments.length; x++){
	preImages[x] = new Image();
	preImages[x].src = preloading.arguments[x];
	}
}
preloading("","");*/