var characterInfo = ["Character 1<br />Info for this character!", "Character 2<br />Info for this character!", "Character 3<br />Info for this character!", "Character 4<br />Info for this character!", "Character 5<br />Info for this character!"];
var scrollTimer = 0;

var newPosition = 0;
var pageTurners = 1;
var sliderHeight = 20;

var openTimer = 0, closeTimer = 0, slideTimer = 0;

var characterXPos = 0, characterYPos = 0;
var faces;
var pixelCount = 0;
var moveTimer = 0;

var questionSlideTimer = 0;
var questionSpeed = 0;

function pngFix()
{
	/*	IE VERSION CHECK */
	if (navigator.appVersion.search("MSIE") != null && navigator.appVersion.search("MSIE") != -1)
	{
		var arrVersion = navigator.appVersion.split("MSIE");
		var version = parseFloat(arrVersion[1]);
		if ((version >= 5.5) && (document.body.filters)) 
		{
		   for(var i=0; i<document.images.length; i++)
		   {
			  var img = document.images[i];
			  var imgName = img.src.toUpperCase();
			  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
			  {
				 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; z-index: 100;" + img.style.cssText;
				 if (img.align == "left") imgStyle = "float:left;" + imgStyle;
				 if (img.align == "right") imgStyle = "float:right;" + imgStyle;
				 if (img.parentElement.href) imgStyle = "cursor:hand;" + 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;
				 i = i-1;
			  }
		   }
		}
	}
	else
	{
		//alert('Not IE thank god!!');
	}
}


function getObj(id)
{
	return document.getElementById(id);
}


function closeInfo()
{
	var closeButton = getObj('closeButton');
	var nextPage = getObj('nextPage');
	var previousPage = getObj('previousPage');
	var introWindow = getObj('introWindow');
	closeButton.style.display = "none";
	nextPage.style.display = "none";
	previousPage.style.display = "none";
	introWindow.style.display = "none";
}

function findLeftPos(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		do
		{
			curleft += obj.offsetLeft;
		}
		while (obj == obj.offsetParent);
	}
	return curleft;
}

function findTopPos(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		do
		{
			curtop += obj.offsetTop;
		}
		while (obj == obj.offsetParent);
	}
	return curtop;
}


function showBubble(characterNumber)
{
	var character = getObj('character' + characterNumber);
	var leftPosition = findLeftPos(character) - 50;
	var obj = getObj('bubble');
	obj.style.left = leftPosition + "px";
	obj.innerHTML = "<p>" + characterInfo[characterNumber-1] + "</p>";
	obj.style.display = "block";
}
function hideBubble(character) {var obj = getObj('bubble'); obj.style.display = "none";}

//	CHANGES THE CONTENT OF THE IFRAME USING HREF OF LINK
//	AND
//	INDICATE WHICH SECTION YOU ARE IN ON THE ICON
function changeContent(link)
{
	getObj('newPosition').value = 0;
	document.getElementById('contentContainer').src = link.href;
	indicateIcon(link.id);
}

function indicateIcon(linkId)
{
	//	RESET ALL ICONS TO NORMAL STATE
	var menuBar = document.getElementById("menuBar");
	var sections = menuBar.getElementsByTagName("a");
	for (var count = 0; count < sections.length; count++ )
	{
		getObj(sections[count].id).className = "normal";
	}
	//	SET THIS ICON TO HIGHLIGHT STATE
	getObj(linkId).className = "highlight";
}

/*	FUNCTIONS TO TURN THE PAGES OR SET PAGE BY ID? */
function previous() {if (getObj('newPosition').value >= 630) {getObj('newPosition').value = parseInt(getObj('newPosition').value) - 630;}}
function next()
{
	var width = parseInt(window.frames[0].document.getElementById('container').style.width);
	if (parseInt(getObj('newPosition').value) < (width-630))
	{
		getObj('newPosition').value = parseInt(getObj('newPosition').value) + 630;
	}
}

function setPage(pageToDisplay)
{
	document.getElementById('contentContainer').src = pageToDisplay.href;
}


/*	FUNCTIONS TO OPEN AND CLOSE THE BOTTOM SLIDER BAR	*/
function openSlider()	// Open the bottom slider window
{
	var slider = getObj('slider');
	if (sliderHeight < 95) {sliderHeight += 1;}
	else
	{
		clearSliderTimers();
		showSliderContent();
	}
	slider.style.height = sliderHeight + 'px';
	openTimer = setTimeout("openSlider()",10);
}

function closeSlider() //	Close the bottom slider window
{
	var slider = getObj('slider');
	if (sliderHeight > 20)
	{
		hideSliderContent();
		sliderHeight -= 1;
	}
	else {clearSliderTimers();}
	slider.style.height = sliderHeight + 'px';
	closeTimer = setTimeout("closeSlider()",10);
}

function clearSliderTimers()	// Clear both the open and close timers
{
	clearTimeout(openTimer);
	clearTimeout(closeTimer);
}

function snapTo(snapX,snapY)
{
	var character = dd.elements["character"];
	character.moveTo(snapX, snapY);
}

function showIcons() {getObj('menuIcons').style.display = "block"; getObj('title').style.display = "none";}
function hideIcons() {getObj('menuIcons').style.display = "none"; getObj('title').style.display = "block";}


function showSliderContent()
{
	getObj('moveLeft').style.display = "block";
	getObj('moveRight').style.display = "block";
	getObj('sliderContent').style.display = "block";
}

function hideSliderContent()
{
	getObj('moveLeft').style.display = "none";
	getObj('moveRight').style.display = "none";
	getObj('sliderContent').style.display = "none";
}

function questionSlide()
{
	clearTimeout(questionSlideTimer);
	var box = document.getElementById("sliderContent");
	box.scrollLeft += questionSpeed;
	questionSlideTimer = setTimeout("questionSlide()",10);
}

function resetQuestionPosition()
{
	var box = document.getElementById("sliderContent");
	box.scrollLeft = 0;
}

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=/";
}



/*	CHANGE FONT SIZE AND SET A COOKIE TO STORE THE SETTING	*/
function fontSizer(size)
{
	createCookie("ebaFontSize", size, 365);
	document.getElementById('contentContainer').contentWindow.location.reload();
}

/*	CHANGE FONT FAMILY AND SET A COOKIE TO STORE THE SETTING	*/
function fontStyler(family)
{
	createCookie("ebaFontFamily", family, 365);
	document.getElementById('contentContainer').contentWindow.location.reload();
}

function hideToolTip()
{
	window.parent.getObj('tipWindow').style.display = "none";
	window.parent.getObj('tipContainer').style.display = "none";
	window.parent.getObj('tipContent').src = "/toolTips.php?tip=reset";
}

//	FUNCTION TO ENABLE/DISABLE ICONS DEPENDING ON PRODUCT SELECTED
function selectIcons(manual, lookInside, samples, video, music, gallery, comments, training, ordering, downloads)
{
	if (manual == 1) {getObj('manual').style.display = "block";}
	else {getObj('manual').style.display = "none";}

	if (lookInside == 1) {getObj('lookInside').style.display = "block";}
	else {getObj('lookInside').style.display = "none";}

	if (samples == 1) {getObj('samples').style.display = "block";}
	else {getObj('samples').style.display = "none";}

	if (video == 1) {getObj('video').style.display = "block";}
	else {getObj('video').style.display = "none";}

	if (music == 1) {getObj('music').style.display = "block";}
	else {getObj('music').style.display = "none";}

	if (gallery == 1) {getObj('gallery').style.display = "block";}
	else {getObj('gallery').style.display = "none";}

	if (comments == 1) {getObj('comments').style.display = "block";}
	else {getObj('comments').style.display = "none";}

	if (training == 1) {getObj('training').style.display = "block";}
	else {getObj('training').style.display = "none";}

	if (ordering == 1) {getObj('ordering').style.display = "block";}
	else {getObj('ordering').style.display = "none";}

	if (downloads == 1) {getObj('downloads').style.display = "block";}
	else {getObj('downloads').style.display = "none";}
}

window.onload = function()
{
	//	Assigns change font size function onclick to font size links
	if (document.getElementById("largest")) {document.getElementById("largest").onclick = function() {fontSizer('Largest'); return false;}}
	if (document.getElementById("larger")) {document.getElementById("larger").onclick = function() {fontSizer('Larger'); return false;}}
	if (document.getElementById("normal")) {document.getElementById("normal").onclick = function() {fontSizer('Normal'); return false;}}

	// Assigns changeContent function onclick to all links in menu bar
	if (document.getElementById("contact")) {document.getElementById("contact").onclick = function() {changeContent(this); return false;}}
	if (document.getElementById("links")) {document.getElementById("links").onclick = function() {changeContent(this); return false;}}
	if (document.getElementById("team")) {document.getElementById("team").onclick = function() {changeContent(this); return false;}}

	var allLinks = document.getElementsByTagName("a");
	for (var count = 0; count < allLinks.length; count++)
	{
		if (allLinks[count].className == "spot")
		{
			allLinks[count].onclick = function() {my_ClickFunc(this); return false;}
		}
	}

	if (document.getElementById("menuBar"))
	{
		var menuBar = document.getElementById("menuBar");
		var sections = menuBar.getElementsByTagName("a");
		for (var count = 0; count < sections.length; count++ )
		{
			sections[count].onclick = function() {changeContent(this); return false;}
		}
	}
	// Next two if statements set which page of content to display in the ifrae and sets off the scrolling animation inside the iframe itself
	if (document.getElementById("previousPage")) {document.getElementById("previousPage").onclick = function() {previous(); return false;}}
	if (document.getElementById("nextPage")) {document.getElementById("nextPage").onclick = function() {next(); return false;}}

	// Next two if statements move the slider content left and right
	if (document.getElementById("moveLeft"))
	{
		document.getElementById("moveLeft").onmouseover = function() {questionSpeed = -1; return false;}
		document.getElementById("moveLeft").onmouseout = function() {questionSpeed = 0; return false;}
	}
	if (document.getElementById("moveRight"))
	{
		document.getElementById("moveRight").onmouseover = function() {questionSpeed = 1; return false;}
		document.getElementById("moveRight").onmouseout = function() {questionSpeed = 0; return false;}
	}

	//	If the sliderContent div exists apply an onclick to all the links inside!
	if (document.getElementById('sliderContent'))
	{
		var sliderBox = document.getElementById('sliderContent');
		faces = sliderBox.getElementsByTagName("a");
		for (var count = 0; count < faces.length; count++)
		{
			faces[count].onclick = function() {setPage(this); return false;}
		}
		var total = count;
		getObj('sizer').style.width = 82*total + "px";
		questionSlide();
	}

	if (document.getElementById("terms")) {document.getElementById("terms").onclick = function() {changeContent(this); return false;}}
}