/*------------------------------------------------------------------------------
//  CopyRight 2009/06/06 
//  Warning : This computer program is protected by copying law and international treaties.
//  unauthorized reproduction program or any portion of it will be prosecuted to the maximum extent possible under law .
//  Prohibition: prohibit the spread in this entire or part of the code, without the express written permission of author, do not use or are spreading.
//  Prohibition of any commercial or for-profit or public welfare use this source code or binary code.
//  Author : email:ruihade@hotmail.com , ruihade@gmail.com ,location: taiwan, cellphone:0919910435
-----------------------------------------------------------------------------*/

<!-- Beginning of JavaScript -

var your_image=new Array()
your_image[0]="images/logo_small.gif" // 在master目錄下測試要加..
//your_image[1]="image2.gif"
//your_image[2]="image3.gif"
//your_image[3]="image4.gif"
//your_image[4]="image5.gif"

var your_image_link=new Array()
your_image_link[0]="http://www.redhot.com.tw/download/default.aspx"
your_image_link[1]="#"
your_image_link[2]="#"
your_image_link[3]="#"
your_image_link[4]="#"
var run=true
document.onclick = stopMoving
var floatingspeed=5
var tempo=20
var numberofimages=your_image.length-1
var stepx=new Array()
var stepy=new Array()
for (i=0;i<=numberofimages;i++) {
	stepx[i]=randommaker(floatingspeed)
	stepy[i]=randommaker(floatingspeed)
}
var imgwidth=new Array()
var imgheight=new Array()
for (i=0;i<=numberofimages;i++) {
	imgwidth[i]=10
	imgheight[i]=10
}
var x,y
var marginbottom
var marginleft=0
var margintop=0
var marginright
var timer
var spancontent=new Array()
var imgpreload=new Array()
for (i=0;i<=your_image.length;i++) {
	imgpreload[i]=new Image()
	imgpreload[i].src=your_image[i]
	imgpreload[i]
}
// onclick 點擊物件
for (i=0;i<=numberofimages;i++) {
	spancontent[i]="<a href='"+your_image_link[i]+"'><img src='"+your_image[i]+"' border='0' onclick='stopMoving()'></a>"
}
//建立物件
for (i=0;i<=numberofimages;i++) {
    document.write("<span id='movingObj"+i+"' style='position:absolute'></span>")
    document.close()
}
//停止移動
function stopMoving()
{
  run=false;
  Hidepictures();
  ChangeBackground();
}
function ChangeBackground()
{
document.body.className='goldbk' //動態更換背景sunbk->goldbk
}
function setValues() {
	if (document.all) {
      if (document.body.clientHeight==0)
	  { marginbottom=document.body.clientWidth * 0.5}
	  else
      {marginbottom=document.body.clientHeight-5}
    	marginright=document.body.clientWidth-5
		for (i=0;i<=numberofimages;i++) {             
			var thisObj = eval("document.all.movingObj"+i)
    		thisObj.innerHTML=spancontent[i]
			var thisObj = eval("document.all.movingObj"+(i)+".style")
           	thisObj.posLeft=randommaker(marginright)
			thisObj.posTop=randommaker(marginbottom)  
		}
		for (i=0;i<=numberofimages;i++) {
			var thisObj = eval("document.all.movingObj"+i)
			imgwidth[i]=thisObj.offsetWidth
			imgheight[i]=thisObj.offsetHeight
			
		}
		checkmovement()
	}
	if (document.layers) {
    	marginbottom=window.innerHeight-5
    	marginright=window.innerWidth-5
		for (i=0;i<=numberofimages;i++) {             
			var thisObj=eval("document.movingObj"+i+".document")
    		thisObj.write(spancontent[i])
			thisObj.close()
			var thisObj=eval("document.movingObj"+i)
           	thisObj.left=randommaker(marginright)
			thisObj.top=randommaker(marginbottom)  
		}
		for (i=0;i<=numberofimages;i++) {
			var thisObj=eval("document.movingObj"+i+".document")
			imgwidth[i]=thisObj.width
			imgheight[i]=thisObj.height
		}
    	checkmovement()
	}
}

function randommaker(range) {		
	rand=Math.floor(range*Math.random())
	if (rand==0) {rand=Math.ceil(range/2)}
    return rand
}

function checkmovement() {
	if (document.all) {
		checkposition()
		movepictures()
       if (run)	timer=setTimeout("checkmovement()",tempo)
	}
	if (document.layers) {
		checkposition()
   		movepictures()
    	if (run) timer=setTimeout("checkmovement()",tempo)
	}
}
function Hidepictures() {
		if (document.all) {
			for (i=0;i<=numberofimages;i++) {  
    			var thisObj=eval("document.all.movingObj"+(i)+".style")
    			thisObj.visibility='hidden'
    		}
		}
		if (document.layers) {
			for (i=0;i<=numberofimages;i++) {  
    			var thisObj = eval("document.movingObj"+i)
                 thisObj.visibility='hidden'
    		}
		}
}
function movepictures() {
		if (document.all) {
			for (i=0;i<=numberofimages;i++) {  
    			var thisObj=eval("document.all.movingObj"+(i)+".style")
    			thisObj.posLeft+=stepx[i]
				thisObj.posTop+=stepy[i]
    		}
		}
		if (document.layers) {
			for (i=0;i<=numberofimages;i++) {  
    			var thisObj = eval("document.movingObj"+i)
    			thisObj.left+=stepx[i]
				thisObj.top+=stepy[i]
    		}
		}
}

function checkposition() {
	if (document.all) {
		for (i=0;i<=numberofimages;i++) {             
			var thisObj=eval("document.all.movingObj"+i+".style")
			if (thisObj.posLeft>marginright-imgwidth[i]) {
				thisObj.posLeft-=Math.abs(stepx[i]+1)
				stepx[i]=randommaker(floatingspeed)*-1	
			}
			if (thisObj.posLeft<marginleft) {
				thisObj.posLeft+=Math.abs(stepx[i])
				stepx[i]=randommaker(floatingspeed)			
			}	
			if (thisObj.posTop>marginbottom-imgheight[i]) {
				thisObj.posTop-=Math.abs(stepy[i])
				stepy[i]=randommaker(floatingspeed)*-1

			}
			if (thisObj.posTop<margintop) {
				thisObj.posTop+=Math.abs(stepy[i])
				stepy[i]=randommaker(floatingspeed)
			}
		}
	}
	if (document.layers) {
		for (i=0;i<=numberofimages;i++) {             
			var thisObj=eval("document.movingObj"+i)
			if (thisObj.left>marginright-imgwidth[i]) {
				thisObj.left-=Math.abs(stepx[i]+1)
				stepx[i]=randommaker(floatingspeed)*-1	
			}
			if (thisObj.left<marginleft) {
				thisObj.left+=Math.abs(stepx[i])
				stepx[i]=randommaker(floatingspeed)			
			}	
			if (thisObj.top>marginbottom-imgheight[i]) {
				thisObj.top-=Math.abs(stepy[i])
				stepy[i]=randommaker(floatingspeed)*-1

			}
			if (thisObj.top<margintop) {
				thisObj.top+=Math.abs(stepy[i])
				stepy[i]=randommaker(floatingspeed)
			}
		}
	}
}

// - End of JavaScript - -->