// Main JS Functions

function ImageUpdate(){

	var w=0;
	
	for(w=0;w<10;w++){
		
		var g = document.getElementById("ii" + w).src;
		document.getElementById("ii" + w).src = g;	
	
	}

}

function entry(){
	
	RefreshC(29);
	
	var va=Math.floor(Math.random()*4);
	//alert(va);
	if(va==3){
		//DistributedContribution();
	}
}

function RefreshC(i){

	var colour = "#ffffff";
	var d = 0;
	
	//33% - Show Cube
	//var one = Math.floor(Math.random()*2);
	//if(one==1){
	var ee = i;
	
	for(op=0;op<2;op++){
	
	var randomnumber=Math.floor(Math.random()*14);
	randomnumber = randomnumber + 3;
	document.getElementById("a" + ee).style.width = randomnumber +"px";
	document.getElementById("a" + ee).style.height = randomnumber +"px";
	document.getElementById("i" + ee).style.width = randomnumber +"px";
	document.getElementById("i" + ee).style.height = randomnumber +"px";
	document.getElementById("i" + ee).src = "/images/zero.gif";
	document.getElementById("i" + ee).style.padding = "0px 0px 0px 0px";
	document.getElementById("i" + ee).style.margin = "0px 0px 0px 0px";
	
	var r=Math.floor(Math.random()*10);
	var ava=new Array("1","2","3","4","5","6","7","8","9","A","B","C","D","E","F")
	var HexOne=Math.floor(Math.random()*15);
	var HexTwo=Math.floor(Math.random()*15);
	var HexThree=Math.floor(Math.random()*15);
	var HexFour=Math.floor(Math.random()*15);
	var HexFive=Math.floor(Math.random()*15);
	var HexSix=Math.floor(Math.random()*15);
	document.getElementById("a" + i).style.backgroundColor= "#" + ava[HexOne] + ava[HexTwo] + ava[HexThree] + ava[HexFour] + ava[HexFive] + ava[HexSix];
	
	
	}
	//} else {
	//
	//}
	//1.8% - Blank out Cube
	var two=Math.floor(Math.random()*40);
	if(two==1){

		document.getElementById("a" + i).style.backgroundColor='#FFFFFF';
	} else {
	//
	}
			
	// - Make one cube randomly large per cycle
	var four=Math.floor(Math.random()*165);
	if(four==1){

		var lucky = Math.floor(Math.random()*122);
		t = Math.floor(Math.random()*22) + 11;
		document.getElementById("a" + lucky).style.width = t + "px";
		document.getElementById("a" + lucky).style.height = t + "px";
		document.getElementById("i" + lucky).style.width = t + "px";
		document.getElementById("i" + lucky).style.height = t + "px";
		document.getElementById("i" + lucky).src = "/images/zero.gif";
		document.getElementById("i" + lucky).style.padding = "0px 0px 0px 0px";
		document.getElementById("i" + lucky).style.margin = "0px 0px 0px 0px";
	} else {
	//
	}
	
	// slow down Fluid and Total request - ease up on the bandwidth
	var five_a=Math.floor(Math.random()*106);
	var five_b=Math.floor(Math.random()*18);
	
	if(five_a==1){
		//Fluid();
	}
	if(five_b==1){
		//Total();
	}
	
	//update one cube to a thumbnail per session 
	//var six=Math.floor(Math.random()*66);
	//if(six==1){
		//setTimeout('UpdateThumb(Math.floor(Math.random()*233))',10);
	//}

setTimeout('RefreshC(Math.floor(Math.random()*144))',34);

}

function UpdateThumb(c) {
	
	var q=Math.floor(Math.random()*1);
	if(q==0){
		var chosen = c;
		//c = int chosen cube
		var imgC = "i" + chosen;
		var backC = "a" + chosen; 
		
		var givenDiv = document.getElementById(imgC);
		givenDiv.style.width = "120px";
		givenDiv.style.height = "90px";
		//givenDiv.style.padding = "2px 2px 2px 2px";
		givenDiv.style.margin = "4px 2px 2px 2px";
		
		var cradleDiv = document.getElementById(backC);
		var title = givenDiv.name;
		var url = "http://images.websnapr.com/?size=t&key=t4pP9uE4vu4K&url=" + title;
		givenDiv.src = url;
	
		cradleDiv.style.width = "128px";
		cradleDiv.style.height = "98px";
	}
}

//function update(passI,passX) {
	//var passI = passI;
	//var passX = passX;		
	//if lucky - slow the show thumbnail routine down
	//var q=Math.floor(Math.random()*2);
	//if(q==1){
	//if(lucky==i){
			//document.getElementById("a" + passI).style.width = passX +"px";
			//document.getElementById("a" + passI).style.height = passX +"px";
			//document.getElementById("i" + passI).style.width = passX +"px";
			//document.getElementById("i" + passI).style.height = passX +"px";
			//document.getElementById("i" + passI).src = "/images/zero.gif";
	//}
	//}
//}

//function clickc(j){
//document.getElementById(j).innerHTML = parseFloat(document.getElementById(j).innerHTML)+1;
///window.location = 'http://www.randomcube.co.uk/includes/random.php';
//} 

//function test123(){
//	Fluid()
//	setTimeout('test123()',1000);
//} 

function LiveI(){
	var sw=Math.floor(Math.random()*2);
		if(sw==1){
	
		sample();
		
		}	
	setTimeout('LiveI()',333);
}

function toggleLayer(whichLayer) {
  var elem, vis;
  if(document.getElementById) // this is the way the standards work
    elem = document.getElementById(whichLayer);
  else if(document.all) // this is the way old msie versions work
      elem = document.all[whichLayer];
  else if(document.layers) // this is the way nn4 works
    elem = document.layers[whichLayer];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}
