// JavaScript Document


window.onload = init;


var SWAP_INTERVAL = 10; // seconds between swaps
var curr_img = 0;
var curr_opac = 100;
var t = null;
var fade_start = null;
var fade_timer = null;

var imagePath = "/images/home_rotation/";

var images = new Array("guttering_van.jpg",
					   "dodge_truck.jpg",
					   "1053van.jpg",
					   "bike.jpg",
					   "race_car_dirt.jpg" // Always leave this one last
					   );

var imageAlts = new Array("Outlaw Graphics, Crossville, TN",
						  "Outlaw Graphics, Crossville, TN",
						  "Outlaw Graphics, Crossville, TN",
						  "Outlaw Graphics, Crossville, TN",
						  "Outlaw Graphics, Crossville, TN"  // Always leave this one last
						  );

var imageLinks = new Array("/web.php",
						   "/promotions/offsitebackup/",
						   "#",
						   "/networking.php",
						   "#" // Always leave this one last
						   );

var imageLinksTargets = new Array("_self",
								  "_self",
								  "_self",
								  "_self",
								  "_self" // Always leave this one last
								  );


function init() {
  if (images.length > 0) {
    //fade_start = setTimeout("startOpacDec()", (SWAP_INTERVAL-1)*1000);
	t = setInterval("rotateHomeImage()", SWAP_INTERVAL * 1000);
  }
}



function rotateHomeImage() {
  var img = document.getElementById('image_placeholder');
  //var imgLink = document.getElementById('image_placeholder_link');

  if (curr_img >= images.length) {
	curr_img = 0;  
  }
  
  //fade_start = setTimeout("startOpacDec()", (SWAP_INTERVAL-1)*1000);
  img.src = imagePath + images[curr_img];
  img.alt = imageAlts[curr_img];
  //imgLink.href = imageLinks[curr_img];
  //imgLink.alt = imageAlts[curr_img];
  //imgLink.target = imageLinksTargets[curr_img];
  Effect.Shake('image_placeholder');
    
  /*if (imageLinks[curr_img] == '#') {
    imgLink.style.cursor = 'default';
  }
  else {
	imgLink.style.cursor = 'pointer';  
  }*/
  
  curr_img++;  
}



function setOpacity(opac) {
  var decOpac = opac / 100;
  var img = document.getElementById('image_placeholder');
  if (document.all && typeof window.opera == 'undefined') {
    if (img.filters.alpha) {
	  img.filters.alpha.opacity = opac;
	}
  }
  else {
	img.style.MozOpacity = decOpac;  
  }
  img.style.opacity = decOpac;
  curr_opac = opac;
}



function decreaseOpacity() {
  if (curr_opac == 0) {
	clearInterval(fade_timer);
	fade_timer = setInterval("increaseOpacity()", 10);
  }
  else {
    curr_opac -= 1;
	setOpacity(curr_opac);
  }
}



function startOpacDec() {
  fade_timer = setInterval("decreaseOpacity()", 10);
}



function increaseOpacity() {
  if (curr_opac < 100) {
    curr_opac += 1;
	setOpacity(curr_opac);
  }
  else {
	clearInterval(fade_timer);
  }
}



function startOpacInc() {
  fade_timer = setInterval("increaseOpacity()", 10);	
}



function setBackgroundColor(hex) {
  var img = document.getElementById('image_placeholder');
  img.style.backgroundColor = '#FFFFFF';
}