/** FastInit
* http://tetlaw.id.au/view/javascript/fastinit
* Andrew Tetlaw
* Version 1.4.1 (2007-03-15)
* Based on:
* http://dean.edwards.name/weblog/2006/03/faster
* http://dean.edwards.name/weblog/2006/06/again/
* Help from:
* http://www.cherny.com/webdev/26/domloaded-object-literal-updated
* 
*/
/*var FastInit = {
	onload : function() {
		if (FastInit.done) { return; }
		FastInit.done = true;
		for(var x = 0, al = FastInit.f.length; x < al; x++) {
			FastInit.f[x]();
		}
	},
	addOnLoad : function() {
		var a = arguments;
		for(var x = 0, al = a.length; x < al; x++) {
			if(typeof a[x] === 'function') {
				if (FastInit.done ) {
					a[x]();
				} else {
					FastInit.f.push(a[x]);
				}
			}
		}
	},
	listen : function() {
		if (/WebKit|khtml/i.test(navigator.userAgent)) {
			FastInit.timer = setInterval(function() {
				if (/loaded|complete/.test(document.readyState)) {
					clearInterval(FastInit.timer);
					delete FastInit.timer;
					FastInit.onload();
				}}, 10);
		} else if (document.addEventListener) {
			document.addEventListener('DOMContentLoaded', FastInit.onload, false);
		} else if(!FastInit.iew32) {
			if(window.addEventListener) {
				window.addEventListener('load', FastInit.onload, false);
			} else if (window.attachEvent) {
				return window.attachEvent('onload', FastInit.onload);
			}
		}
	},
	f:[],done:false,timer:null,iew32:false
};

FastInit.listen();*/
/** FastInit End Here */

/* rollover */
var keyLocked = false;
var noWindowClose = false;

var Rollovers = function(opt){
  var o = opt;
  var load = function() {
    $A(o.selector).each(function(s) {
      $$(s).each(
        function(i) {
          var os = i.src, ni = document.createElement('img');
          $(i).observe('mouseout', function(e){i.src = os;});
          ni.src = o.srcFunction(i,o);
          i.observe('mouseover', function(e){i.src = ni.src;});
        }
      );
    });
  };
  if(window.FastInit) {
  	FastInit.addOnLoad(load);
  } else {
  	Event.observe(window, 'load', load);
  }
}
Rollovers({
  selector : ['img.rollover'],
  srcFunction : function(i, o) {
    return i.src.replace(/(.*)\.(jpg|gif|png)$/i, "$1_b.$2");
  }
});
var ButtonInputs = function(opt){
  var o = opt;
  var load = function() {
    $A(o.selector).each(function(s) {
      $$(s).each(
        function(i) {
          var os = i.className;
          $(i).observe('mouseout', function(e){i.className = os;});
          i.observe('mouseover', function(e){i.className = o.overFunction(i.className);});
        }
      );
    });
  };
  if(window.FastInit) {
  	FastInit.addOnLoad(load);
  } else {
  	Event.observe(window, 'load', load);
  }
}
ButtonInputs({
	selector : ['input.inputButton','input.inputButtonBig'],
	overFunction : function(c) {
		if(c.substring(c.length-4,c.length) == "Over") return c;
		return c+"Over";
	}
});

/* pursuit CURSOR */
var pursuitLock = false;
var exX = 0;
var exY = 0;
var pursuitCalled = false;
function pursuitCURSOR(cursorId, x, y) {
	if (!pursuitCalled) {
		pursuitCalled = true;
		var cursorMove = function (ev) {
			var cursor = $(cursorId);
			if (cursor) {
				if(pursuitLock) return;
				if(!x) x = 0; else x = parseInt(x); if(!y) y = 0; else y = parseInt(y);
				cursor.style.left = (Event.pointerX(ev) + x + exX) + "px";
				cursor.style.top  = (Event.pointerY(ev) + y + exY) + "px";
			}
		}.bindAsEventListener();

		Event.observe(document, "mousemove", cursorMove);
		Event.observe(window, "unload", function () {
			Event.stopObserving(document, "mousemove", cursorMove);
		});
	}
}

function setCookie(c_name, value, expiredays) {
	var exdate = new Date();
	exdate.setDate(exdate.getDate() + expiredays);
	document.cookie = c_name+"="+encodeURIComponent(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString())+";path=/;";
}

function getCookie(c_name) {
	if (document.cookie.length > 0) {
		c_start = document.cookie.indexOf(c_name + "=");
		if (c_start != -1) {
			c_start = c_start + c_name.length + 1;
			c_end = document.cookie.indexOf(";", c_start);
			if (c_end == -1) c_end = document.cookie.length;
			return unescape(document.cookie.substring(c_start, c_end));
		}
	}
	return "";
}

function changeOpac(opacity, id) {
	var o = document.getElementById(id).style;
	o.opacity = (opacity / 100);
	o.MozOpacity = (opacity / 100);
	o.KhtmlOpacity = (opacity / 100);
	o.filter = "alpha(opacity=" + opacity + ")";
}

function setLang(value) {
	setCookie("lang"+Ss, value, 365);
	//location.reload(true);
	var theHref = top.location.href.replace(/lang\=/g,'lastlang=');
	if(theHref != top.location.href)
		top.location.href=theHref;
	else
		location.reload(true);
}

function setCSSStyle(value) {
	setCookie("style", value, 365);
	location.reload(true);
}

var Lang = getCookie("lang"+Ss);
if(Lang != "zh" && Lang != "en") Lang = "zh";

//open doc in new window
function openDoc(a) {
	window.open(a, "new"+Math.round(Math.random()*10000), "width=800,height=600,scrollbars,resizable");
}

//display menu
function displayMenu(n, arg) {
	$(n).style.display = arg ? 'block' : 'none';
}

//switch tab
var oldTabNo = 1;
function switchTab(n)
{
	document.getElementById("tabN"+n).blur();
	//if(!oldTabNo || n == oldTabNo) return;
	document.getElementById("tabN"+oldTabNo).className = "tab";
	document.getElementById("contDiv"+oldTabNo).style.display = "none";
	document.getElementById("tabN"+n).className = "tab1";
	document.getElementById("contDiv"+n).style.display = "block";
	oldTabNo=n;
}

//category check height
function checkHeight(id) {
	if($(id).getHeight()>100)
		$(id).style.height='100px';
}

//show shop det
function showDet(id) {
	document.getElementById("Det"+id).style.display = document.getElementById("Det"+id).style.display == "block" ? "none" : "block";
}

function checkFooterTop() {
	var maxH = 0;
	if($('FMainRight')) {
	//	if($('FMainRight').getHeight() > maxH) maxH = $('FMainRight').getHeight();
	}
	$$('.FMainRight').each(function(e) {
		if(e.getHeight() > maxH) maxH = e.getHeight();
	});
	if(maxH && $('FMainFooter') && maxH > $('FMainLeft').getHeight()) {
		//alert(maxH);
		$('FMainFooter').style.top = (maxH-400)+"px";
	}
}
