//************************************************************************************
// Cross Browser Funcitons ver 3.0 
// Copyright (C) by Audi audi@calcom.com.tw
// http://www.carousel.com.tw
// http://www.calcom.com.tw
// http://www.toocool.com.tw
// http://www.inkstar.com.tw


var layerRef="null",layerStyleRef="null",styleSwitch="null";
var widthClipSwitch="null";
var heightClipSwitch="null";
var bWidth,bHeight,offsetX,offsetY;
var layerTop,layerLeft;
var pxSwtch;
var leftStopPoint=0;
var currTop=120;
var clipScale=7;
var ns=false,ie=false;
var topStop;
var vSpeed;

function init(){
	
	if (navigator.appName == "Netscape") {
		layerStyleRef="layer.";
		layerRef="document.layers";
		styleSwitch="";
		pxSwitch="";
		layerTop=".top";
		layerLeft=".left";
		widthClipSwitch=".clip.right";
		heightClipSwitch=".clip.bottom";
		offsetX= "window.pageXOffset";
		offsetY= "window.pageYOffset";
		bHeight=window.innerHeight;
		bWidth= window.innerWidth;
		topStop=120;
		ns=true;
		document.captureEvents(Event.MOUSEMOVE | Event.MOUSEDOWN | Event.MOUSEUP)
		document.onmousemove=null;
		//document.onmousedown=mouseDown;
		document.onmousedown=null;
		document.onmouseup=null;
	}else{
		layerStyleRef="layer.style.";
		layerRef="document.all";
		styleSwitch=".style";
		pxSwitch='px';
		layerTop=".pixelTop";
		layerLeft=".pixelLeft";
		widthClipSwitch=".clientWidth";
		heightClipSwitch=".clientHeight";
		offsetX= "document.body.scrollLeft";
  		offsetY= "document.body.scrollTop";
  		bHeight=document.body.clientHeight;
  		bWidth= document.body.clientWidth;
  		topStop=120;
  		ie=true;
  		document.onmousemove=null;
		//document.onmousedown=mouseDown;
		document.onmousedown=null;
		document.onmouseup=null;
	}
}

//******************************************************************************
// General functions
// functions: showLayer(), hideLayer(), moveLayerto(), changeLayerContent()

function showLayer(layerName){
	eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="visible"');
}
	
function hideLayer(layerName){
	eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="hidden"');
}

function moveLayerto(layerName,top,left){
	eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.top=top');
	eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.left=left');
}

function changeLayerContent(layerName,text){
        if (navigator.appName == "Netscape") {
                eval('document.layers["'+layerName+'"].document.write("'+text+'")');
                eval('document.layers["'+layerName+'"].document.close()');
        }else{
                eval('document.all["'+layerName+'"].innerHTML="'+text+'"');
        }
}

//******************************************************************************
// For tooCool.com.TW
// Eyes follow

var currLayer=0;

function showSub(n){
	var layerHeight,scrollY,layerName
	
	hideLayer(eval('"submenu'+currLayer+'"'));
	
	eval('scrollY='+offsetY);
	layerName=eval('"submenu'+n+'"');
	layerHeight=eval(layerRef+'["'+layerName+'"]'+heightClipSwitch);
	if (currMY > scrollY+bHeight/2){
		//moveLayerto(eval('"submenu'+n+'"'),currMY+scrollY+10-layerHeight,currMX);
		moveLayerto(eval('"submenu'+n+'"'),125,currMX);
	}
	else{
		//moveLayerto(eval('"submenu'+n+'"'),currMY+10,currMX);
		moveLayerto(eval('"submenu'+n+'"'),125,currMX);
	}	
	showLayer(eval('"submenu'+n+'"'));
	currLayer=n;
	//document.onmousedown=hideSub;
	//window.status="x:"+currMX+" y:"+currMY+" scrollY:"+scrollY+" layerHeight:"+layerHeight+" bHeight:"+bHeight
}

function hideSub(e){
	//document.onmousedown=null;
	hideLayer(eval('"submenu'+currLayer+'"'));
}
var currMX,currMY

function mouseMove(e){
	var sy=0,sx=0,gotopx;
	x=(ns)?e.pageX:event.x;
	y=(ns)?e.pageY:event.y;
	
	//currMX=parseInt((bWidth-760)/2)+130;
	currMX=x-60;
	currMY=y;
	sx=(x>50)?parseInt(x/50):0;
	sy=(y>50)?parseInt(y/50):0;
		
	//moveLayerto('eye1',(86+sy),(642+sx));
	//moveLayerto('eye2',(86+sy),(642+sx+28));
	
	//return false
}

//******************************************************************************
// For tooCool.com.TW
// Funny Effections

function randomFunny(){
	var trigger=6;
	var x,y,newY;
	
	eval('newY='+offsetY);
	if (trigger==parseInt((Math.random()*10))){
		
		x=parseInt((Math.random()*1000))
		y=parseInt((Math.random()*1000))
		
		if (x < bWidth && y < bHeight ){
			changeLayerContent('funny','<img src=/images/Funny/ShutGun.gif>');
			moveLayerto('funny',newY+y,x);
			showLayer('funny');
		}	
	}
	else
	{
		hideLayer('funny');
	}
	setTimeout('randomFunny()',1000);	
}

function mouseDown(e){
	
	x=(ns)?e.pageX:event.x;
	y=(ns)?e.pageY:event.y;
	
	if (ns && (e.which==3 || e.which==2)){
		//alert('chinasofar.com');
		moveLayerto('RightMenu',y+5,x+5);
		showRightMenu();
		return false;
	}
	if (ie && (event.button==2 || event.button==3)){
		alert('chinasofar.com');
		moveLayerto('RightMenu',y+5,x+5);
		showRightMenu();
		return false;
	}
	
	
	hideRightMenu();
	return true;
}

function showRightMenu(){
	//moveLayerto('RightMenu',currMY,currMX);
	showLayer('RightMenu');
}

function hideRightMenu(){
	hideLayer('RightMenu');
}
//*****************************************************

function waterMark(){
        
        var newY;
        eval('newY='+offsetY);
        moveLayerto('waterMark',bHeight+newY-80,bWidth-66);
        setInterval('waterMark()');
}

function openWin(url){
	var winObj
	winObj=window.open(url,'s_win','width=320,height=480,scrollbars=yes');
	winObj.focus();
}

function displayWin(url){ 
        var displayObj
        displayObj=window.open(url,"displayWindow","width=180,height=320")
        displayObj.focus();
}  