// JavaScript Document
// Dust main javascript

/*
//random img by time
var currentdate = 0
var core = 0

function StringArray (n) {
  this.length = n;
  for (var i =1; i <= n; i++) {
    this[i] = ' ';
  }
}

image = new StringArray(3);
image[0] = 'top_mid1.jpg';
image[1] = 'top_mid2.jpg';
image[2] = 'top_mid3.jpg';

var ran = 60/image.length;

function ranimage() {
  currentdate = new Date();
  core = currentdate.getSeconds();
  core = Math.floor(core/ran);
    return(image[core]);
}
*/

//random img by Math
var theImages = new Array();

theImages[0] = 'http://dustoffroad.com.br/images/top_mid1.jpg';
theImages[1] = 'http://dustoffroad.com.br/images/top_mid2.jpg';
theImages[2] = 'http://dustoffroad.com.br/images/top_mid3.jpg';

var j = 0
var p = theImages.length;
var preBuffer = new Array();
for (i = 0; i < p; i++){
   preBuffer[i] = new Image();
   preBuffer[i].src = theImages[i];
}
var whichImage = Math.round(Math.random()*(p-1));

function OnLoad(img_path){
   document.getElementById('top_mid').src= theImages[whichImage];
   document.getElementById('top_mid').isMap = true;
}

function JustSoPicWindow(imageName,imageWidth,imageHeight,alt,bgcolor,hugger) {
// by E Michael Brandt of ValleyWebDesigns.com - Please leave this comment intact.
alt=alt+"  ** Click em qualquer lugar para fechar **"
if (bgcolor=="") {
bgcolor="#FFFFFF";
}
var adj=10
var w = screen.width;
var h = screen.height;
var byFactor=1;
if(w<740){
     var lift=0.90;
    }
    if(w>=740 & w<835){
      var lift=0.91;
    }
    if(w>=835){
      var lift=0.93;
    }
if (imageWidth>w){
byFactor = w / imageWidth;
imageWidth = w;
imageHeight = imageHeight * byFactor;
}
if (imageHeight>h-adj){
byFactor = h / imageHeight;
imageWidth = (imageWidth * byFactor);
imageHeight = h; 
}
var scrWidth = w-adj;
var scrHeight = (h*lift)-adj;
if (imageHeight>scrHeight){
imageHeight=imageHeight*lift;
imageWidth=imageWidth*lift;
}
var posLeft=0
var posTop=0
if (hugger=="hug image") {
posTop = (scrHeight-imageHeight)/2;
posLeft = ((w-imageWidth)/2);
scrHeight = imageHeight-adj;
scrWidth = imageWidth-adj;
}
imageHeight=imageHeight-adj;
imageWidth=imageWidth-adj;
newWindow = window.open("","newWindow","width="+scrWidth+",height="+scrHeight+",left="+posLeft+",top="+posTop);
newWindow.document.open();
newWindow.document.write('<html><title>'+alt+'</title><body leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" bgcolor='+bgcolor+' onBlur="self.close()" onClick="self.close()">');  
newWindow.document.write('<table width='+imageWidth+' border="0" cellspacing="0" cellpadding="0" align="center" height='+scrHeight+' ><tr><td>');
newWindow.document.write('<img src='+imageName+' width='+imageWidth+' height='+imageHeight+' alt=\"Click\&nbsp\;screen\&nbsp\;to\&nbsp\;close.\" >'); 
newWindow.document.write('</td></tr></table></body></html>');
newWindow.document.close();
newWindow.focus();
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function swapImg(img_name,target_id){
   document.getElementById(target_id).src = img_name;	
}