var ubImageArray = new Array();
var sqImageArray = new Array();
var ubImageIterator = new imageIterator();
var sqImageIterator = new imageIterator();

function showImages(ubImageObject, sqImageObject) {
	ubImageId = 'ubPhoto';
	ubImage = document.getElementById(ubImageId);
	ubImage.style.visibility = 'visible';
	ubImage.setAttribute("src", ubImageObject.image.src);
	
	sqImageId = 'sqPhoto';
	sqImage = document.getElementById(sqImageId);
	sqImage.style.visibility = 'visible';
	sqImage.setAttribute("src", sqImageObject.image.src);

	setOpacity(ubImage, 0);
	setOpacity(sqImage, 0);
	
	fadeIn(ubImageId,sqImageId, 0);
	
	document.getElementById("ubImageHREF").setAttribute("href", ubImageObject.href);
    document.getElementById("sqImageHREF").setAttribute("href", sqImageObject.href);
}



function fadeIn(objId1, objId2 ,opacity) {
	if (document.getElementById) {
		obj1 = document.getElementById(objId1);
		obj2 = document.getElementById(objId2);
		if (opacity > 101) {

           

            document.getElementById("ubImageContainer").style.backgroundImage = "url(" + obj1.getAttribute('src') + ")";
			document.getElementById("sqImageContainer").style.backgroundImage = "url(" + obj2.getAttribute('src') + ")";

        }
		if (opacity <= 100) {
			setOpacity(obj1, opacity);
			setOpacity(obj2, opacity);
			opacity += 10;
			window.setTimeout("fadeIn('"+objId1+"','"+objId2+"',"+opacity+")", 50);
		}
	}
}

function setOpacity(obj, opacity) {
  opacity = (opacity == 100)?99.999:opacity;
  
  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";
  
  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;
  
  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;
  
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}

function imageObject(s,h,c) {
	this.src = s;
	this.href = h;
	this.caption = c;
	var i = new Image();
	this.image = i;
	this.image.src = s;
}

function imageIterator(_imageArray) {
	this.iterator = 0;
	this.array = _imageArray;
	this.increment = function() { this.iterator = (this.iterator == (this.array.length - 1)) ? 0 : this.iterator+1; };
	this.decrement = function() { this.iterator = (this.iterator == 0) ? (this.array.length - 1) : this.iterator-1; };
	this.getNext = function() { this.increment(); next = this.array[this.iterator];  return next; };
	this.getPrevious = function() { this.decrement(); previous = this.array[this.iterator];  return previous; };
}

function executeInterval() {
	showImages(ubImageIterator.getNext(),sqImageIterator.getNext());
}

function addLoadEvent(func) {
	var ssArray = "";
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

// begin help options dropdown area
var isHelpDDVisible = false;
var onHelpDD = false;

function onClickInit(e){
	if (isHelpDDVisible) {
		if (onHelpDD == false) helpDDToggle();
	}
	onHelpDD = false;
} 

function onMouseDownPop(e) {
	onHelpDD = true;
}

function helpDDToggle() {
	var ref = document.getElementById("helpOptionsContainer");
	if (isHelpDDVisible){
		ref.style.display = "none";
		isHelpDDVisible = false;
	} else {
		ref.style.display = "block";
		isHelpDDVisible = true;
	}
}
// end help options dropdown area

// function to set a bookmark
function bookmark(title, url) {
	if (document.all)
		window.external.AddFavorite(url, title);
	else if (window.sidebar)
		window.sidebar.addPanel(title, url, '')
}

addLoadEvent( function() {
	if (document.getElementById('ubPhoto')) { 
		showImages(ubImageArray[0],sqImageArray[0]);
		showtime = setInterval("executeInterval()", 6000);
	}
} );



var currentPhoto = 0;
var photos = new Array();
var isOmnitureSet = false;

function photo(url, caption) {
	this.url = url;
	this.caption = caption;
}
function showNextPhoto() {
	var photoToShow = getNextPhoto();
	displayPhoto(photoToShow);
	return false;
}
function showPreviousPhoto() {
	var photoToShow = getPreviousPhoto();
	displayPhoto(photoToShow);
	return false;
}
function displayPhoto(photo) {
	document.getElementById('caption').innerHTML = photo.caption;
	document.getElementById('count').innerHTML = currentPhoto + 1;
	document.getElementById('largeImage').src = photo.url;
	return false;
}
function getNextPhoto() {
	if (currentPhoto + 1 > photos.length - 1) {
		currentPhoto = 0;
	} else {
		currentPhoto = currentPhoto + 1;
	}
	setOmniture(currentPhoto);
	return photos[currentPhoto];
}
function getPreviousPhoto() {
	if (currentPhoto - 1 < 0 ) {
		currentPhoto = photos.length - 1;
	} else {
		currentPhoto = currentPhoto - 1;
	}
	setOmniture(currentPhoto);
	return photos[currentPhoto];
}
function setOmniture(currentPhoto) { //Omniture tracking for onclick views
	//var origPageName = '';
	//var origProp2 = '';
	//var origProp6 = '';
	//var mediaID = ":" + currentPhoto;

	//if (isOmnitureSet == false){
//		origPageName = s_pageName;
		//origProp2 = s_prop2;
		//origProp6 = s_prop6;
		//isOmnitureSet = true;
	//}

	//redefine the page-level tracking with tagging of offer placement
	//s_pageName = origPageName + mediaID;
	//s_prop2 = origProp2 + mediaID;
	//s_prop6 = origProp6 + mediaID;

	//fire off omniture function to track new page view, passing in omniture account information
	//s_gs(omniture_account_info);
}
