// 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 = "/2008%20Site/images/home/";

var images = new Array("offsite.jpg",
					   "webexpress.jpg",
					   "networking.jpg",
					   //"image_placeholder.jpg", // image_placeholder
					   "webdesign.jpg"
					   );

var imageAlts = new Array("Ciphertek Systems Offsite Backup Solution",
						  "Get Your Own Website for as low as $9.99 per month!",
						  "Netork Solutions from Ciphertek Systems, LLC",
						  //"Ciphertek Systems, LLC",  // image_placeholder
						  "We're here for all of your website development needs!"
						  );

var imageLinks = new Array("/promotions/offsitebackup/",
						   "/webexpress/",
						   "/networking.php",
						   //"#", // image_placeholder
						   "/web.php"
						   );

var imageLinksTargets = new Array("_self",
								  "_self",
								  "_self",
								  //"_self",
								  "_self" // image_placeholder
								  );


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';
}