/*$('img').load(function() {
    $(this).png();
});*/



jQuery(document).ready(function(){
		
var timer = setInterval(toggleSomething, 10);

   
})

function zoomAmt() {
	rand=Math.floor(5*Math.random()) + 100;
	return rand;
}

function newmargin(zoom) {		
	rand=Math.floor((20*Math.random() * zoom / 100) - 20);
	//if (rand==0) {rand=Math.ceil(range/2)}
  return rand;
}

function randRange(data) {
       var newTime = data[Math.floor(data.length * Math.random())];
       return newTime;
}


function toggleSomething() {
//       var timeArray = new Array(200, 300, 150, 250, 2000, 3000, 1000, 1500);
       var timeArray = new Array(20, 30, 15, 25, 20, 30, 10, 15);
       var durationArray = new Array(2000, 1300, 1700, 1900, 2000, 3000, 1000, 1500);
//       var durationArray = new Array(200, 130, 170, 190, 200, 300, 100, 150);

       // do stuff, happens to use jQuery here (nothing else does)
			var zoomAmount = zoomAmt()
	    $("#top_img")
	      .animate({ "margin-left": (newmargin(100)) + "px" }, { duration: (randRange(durationArray)), queue: true});
//	      .animate({ "margin-top": (newmargin(100)) + "px", "margin-left": (newmargin(100)) + "px" }, { duration: (randRange(durationArray)), queue: true});
//	      .animate({ "zoom" : (zoomAmount) + "%", "margin-left": (newmargin(zoomAmount)) + "px" }, { duration: (randRange(durationArray)), queue: true });
//	      .animate({ "zoom" : (zoomAmount) + "%","margin-top": (newmargin(zoomAmount)) + "px", "margin-left": (newmargin(zoomAmount)) + "px" }, { duration: (randRange(durationArray)), queue: true });
       

//       clearInterval(timer);
//       timer = setInterval(toggleSomething, randRange(timeArray));
}



/*

// number of floating images
var numberofimages=8

// URL of your image
var imgurl="grey_1.gif"

// maximum width of the floating objects
var clipwidthmax=300

// maximum height of the floating objects
var clipheightmax=300

// do not edit the variables below
var floatingspeed=20
var clipleft=new Array()
var clipright=new Array()
var cliptop=new Array()
var clipbottom=new Array()
var clipwidth=new Array()
var clipheight=new Array()

if (document.all) {
	var preloadimage=new Image()
	preloadimage.src=imgurl
}

var tempo=30
numberofimages=numberofimages-1

var shift_x=Math.floor(numberofimages/2)*-1
var shift_y=Math.floor(numberofimages/2)*-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()

var marginbottom=0
var marginleft=0
var margintop=0
var marginright=0
var timer

function setValues() {
	if (document.all) {
		marginleft=0
		margintop=0
    	marginbottom=document.body.clientHeight
    	marginright=document.body.clientWidth
		for (i=0;i<=numberofimages;i++) {             	
			clipheight[i]=randommaker(clipheightmax)+50
			clipwidth[i]=randommaker(clipwidthmax)+50
			clipleft[i]=randommaker(marginright)-clipwidth[i]
			cliptop[i]=randommaker(marginbottom)-clipheight[i]
		}
		for (i=0;i<=numberofimages;i++) { 
			var opacitystrength=randommaker(50)
			var thisspan=eval("flyimage"+i)
			thisspan.innerHTML="<img src='"+imgurl+"' width='"+marginright+"' height='"+marginbottom+"' style='filter:alpha(opacity="+opacitystrength+")'>"
			thisspan=eval("document.all.flyimage"+i+".style")            	
        	thisspan.posLeft=0
			thisspan.posTop=0
			thisspan.visibility="visible"
		}
		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()
    	timer=setTimeout("checkmovement()",tempo)
	}
}

function movepictures() {
		if (document.all) {
			for (i=0;i<=numberofimages;i++) {  
    			var thisspan=eval("document.all.flyimage"+(i)+".style")
    			clipleft[i]+=stepx[i]
				clipright[i]=clipleft[i]+clipwidth[i]
				cliptop[i]+=stepy[i]
				clipbottom[i]=cliptop[i]+clipheight[i]
				thisspan.clip ="rect("+cliptop[i]+" "+clipright[i]+" "+clipbottom[i]+" "+clipleft[i]+")"
    		}
		}
}

function checkposition() {
	if (document.all) {
		for (i=0;i<=numberofimages;i++) {             
			var thisspan=eval("document.all.flyimage"+i+".style")
			if (clipright[i]>marginright) {	
				clipleft[i]-=Math.abs(stepx[i])
				clipright[i]=clipleft[i]+clipwidth[i]
				thisspan.clip ="rect("+cliptop[i]+" "+clipright[i]+" "+clipbottom[i]+" "+clipleft[i]+")"
				stepx[i]=randommaker(floatingspeed)*-1	
			}
			if (clipleft[i]<marginleft) {
				clipleft[i]+=Math.abs(stepx[i])
				clipright[i]=clipleft[i]+clipwidth[i]
				thisspan.clip ="rect("+cliptop[i]+" "+clipright[i]+" "+clipbottom[i]+" "+clipleft[i]+")"
				stepx[i]=randommaker(floatingspeed)			
			}	
			if (clipbottom[i]>marginbottom) {
				cliptop[i]-=Math.abs(stepy[i])
				clipbottom[i]=cliptop[i]+clipheight[i]
				thisspan.clip ="rect("+cliptop[i]+" "+clipright[i]+" "+clipbottom[i]+" "+clipleft[i]+")"
				stepy[i]=randommaker(floatingspeed)*-1
			}
			if (cliptop[i]<margintop) {
				cliptop[i]+=Math.abs(stepy[i])
				clipbottom[i]=cliptop[i]+clipheight[i]
				thisspan.clip ="rect("+cliptop[i]+" "+clipright[i]+" "+clipbottom[i]+" "+clipleft[i]+")"
				stepy[i]=randommaker(floatingspeed)
			}
		}
	}
}
*/
