/*
	Opel Hero Loader
	Kenneth Kufluk 05/2k5
	Modem Media
	Version 2.0
	Updated for multiple image rotate - 20th Nov 2007 - Michael Steer.
*/
var hero = 0;
var hero_arr = [];
var v2_rotate_herobgsrc = [];

window.onload = function() {
	if (v2_rotate_herobgsrc.length > 1) {
		// Page has rotating banners
		// Set initial state
		heroRotate();
		// Set up rotate timer
		if ( (!isInteger(rotate_time)) || (rotate_time < 3000) ) {rotate_time = 10 * 1000;}
		setInterval( "heroRotate()", rotate_time );
	}
	else {
		// Page does not have rotating banners
		var linkObj = document.getElementById("heroLink");
		var headObj = document.getElementById("heroHead");
		if (hero_arr[0].external == "x") {
			linkObj.href = hero_arr[0].href;
			if (hero_arr[0].sophus) {
				linkObj.onclick = function() {
					tc_redirect('hero', hero_arr[0].href, "/" + hero_arr[0].sophus, hero_arr[0].winprop);
					return false;
				}
			} else {
				linkObj.onclick = function() {
					window.open(hero_arr[0].href,'hero',hero_arr[0].winprop);
					return false;
				}
			}
		} else {
			linkObj.href = "/" + hero_arr[0].goaction;
			linkObj.onclick = function() { goactionTo(hero_arr[0].goaction);return false; }
		}
		if (typeof hero_arr[0].headline=="undefined") return;
		if (hero_arr[0].headline!="") headObj.innerHTML = hero_arr[0].headline;
		headObj.style.color = hero_arr[0].color;
		if (headObj.getElementsByTagName("A")[0]) headObj.getElementsByTagName("A")[0].style.color = hero_arr[0].color;
	}
}

function heroRotate() {
	// function to blend and rotate hero images.
	if (use_hero > max_hero) { use_hero = min_hero; }
	// pre-load next image
	if (use_hero+1 > max_hero) { next_hero = min_hero; } else { next_hero = use_hero+1; }
	nextHero = new Image();
	nextHero.src = v2_rotate_herobgsrc[next_hero];
	// check if browser supports filters and if so, set them.
	if (document.getElementById('heroImage').filters && window.createPopup) {
		document.getElementById('heroImage').style.filter="blendTrans(duration=2)";
		document.getElementById('heroImage').filters.blendTrans(duration=5).Apply();
		document.getElementById('heroImage').filters.blendTrans.Play();
	}
	// set backbround hero image
	document.getElementById('heroImage').style.backgroundImage="url("+v2_rotate_herobgsrc[use_hero]+")";
	// set hero links
	setHeroLinks(use_hero);
	// update cookie
	createCookie("heroRotateImage", use_hero, 7);
	use_hero ++;
}

function setHeroLinks(hero_pointer) {
	var linkObj = document.getElementById("heroLink");
	var headObj = document.getElementById("heroHead");
	if (hero_arr[hero_pointer].external == "x") {
		linkObj.href = hero_arr[hero_pointer].href;
		if (hero_arr[hero_pointer].sophus) {
			linkObj.onclick = function() {
				tc_redirect('hero', hero_arr[hero_pointer].href, "/" + hero_arr[hero_pointer].sophus, hero_arr[hero_pointer].winprop);
				return false;
			}
		} else {
			linkObj.onclick = function() {
				window.open(hero_arr[hero_pointer].href,'hero',hero_arr[hero_pointer].winprop);
				return false;
			}
		}
	} else {
		linkObj.href = "/" + hero_arr[hero_pointer].goaction;
		linkObj.onclick = function() { goactionTo(hero_arr[hero_pointer].goaction);return false; }
	}
	if (typeof hero_arr[hero_pointer].headline=="undefined") return;
	if (hero_arr[hero_pointer].headline!="") headObj.innerHTML = hero_arr[hero_pointer].headline;
	headObj.style.color = hero_arr[hero_pointer].color;
	if (headObj.getElementsByTagName("A")[hero_pointer]) headObj.getElementsByTagName("A")[hero_pointer].style.color = hero_arr[hero_pointer].color;
}

function fixPNG(obj) {
	// correctly handle PNG transparency in Win IE 5.5 or higher.
	var img = obj;
	var imgName = img.src.toUpperCase();
	if (imgName.substring(imgName.length-3, imgName.length) == "PNG" && document.all) {
		var imgID = (img.id) ? "id='" + img.id + "' " : "";
		var imgClass = (img.className) ? "class='" + img.className + "' " : "";
		var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
		var imgStyle = "display:inline-block;" + img.style.cssText;
		if (img.align == "left") imgStyle = "float:left;" + imgStyle;
		if (img.align == "right") imgStyle = "float:right;" + imgStyle;
		var strNewHTML = "<span " + imgID + imgClass + imgTitle
		+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
		+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
		+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>";
		img.outerHTML = strNewHTML;
	}
}

function isInteger(value) {
  return (parseInt(value) == value);
}

// http://www.yourhtmlsource.com/javascript/cookies.html
function createCookie(name, value, days) {
  if (days) {
	var date = new Date();
	date.setTime(date.getTime()+(days*24*60*60*1000));
	var expires = "; expires="+date.toGMTString();
	}
  else var expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var ca = document.cookie.split(';');
  var nameEQ = name + "=";
  for(var i=0; i < ca.length; i++) {
	var c = ca[i];
	while (c.charAt(0)==' ') c = c.substring(1, c.length); //delete spaces
	if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
	}
  return null;
}

function eraseCookie(name) {
  createCookie(name, "", -1);
}
