﻿var globalX = 425;		            //for the starting position of the slider
var globalInOut = 0;                //zero means slider is out
var globalCurrentTab = "Pages";     //keeps track of previously clicked tab
var globalShowHide = 0;             //0 means shopping list is visible
var globalActive = 1;				//current page highlighted (already defined in header)
var globalPrintPics = 0;            //pictures will not be printed by default
var globalBrandPrint = 0;           //print size is normal by default
var globalPreview = 0;				//In custom print preview mode?
var globalAfterInitialLoad = false;	//for displaying the "loading..." message

var globalMagTimeout;				//for clearing the timeout on the mag tab on mouse out


/***************  MAGNIFY TAB  *****************************************/
function showMagTab(hoverName, sender)
{
	if (document.getElementById('OptionsTab') != null) //does it exist?
	{
		TabClick('Magnify');
		document.getElementById("MagnifyTab").innerHTML = hoverName.innerHTML;
		//alert(sender);
		
		Fader(sender, 300, 0, .6, 25);
		document.getElementById(sender).style.border = "2px solid black";
		Fader("MagnifyTab", 175, 0, .99999, 25);
		//Fader("MagnifyTab", 175, 0, 1, 25);	//this was the original, but FireFox flickers
	}
}


/***************  TAB CLICK FUNCTIONS  **********************************/
function TabClick(tab ,sentByMagnify)
{
	//setting the name of the "clicked" tab
	tabtitle = tab;
	if (tab != 'Magnify') globalCurrentTab = tab; //magnify can't be the global tab
	else tabtitle = "Magnification";
	document.getElementById("TabTitle").innerHTML = tabtitle;
    
if (((document.getElementById(tab + "Tab").style.display == "block") || (globalInOut != 0)) && (tab != 'Magnify') && (sentByMagnify != 1))
		TabSlider();
    
	// Making the Content invisible
	document.getElementById("ProductsTab").style.display = "none";
	document.getElementById("PagesTab").style.display = "none";
	document.getElementById("MagnifyTab").style.display = "none";
	document.getElementById("OptionsTab").style.display = "none";
    
	// Changing Tab Focus
	document.getElementById("PagesTabFocused").style.zIndex = "35";
	document.getElementById("ProductsTabFocused").style.zIndex = "35";
	document.getElementById("OptionsTabFocused").style.zIndex = "35";
    
	//all settings for the CURRENT tab
	document.getElementById(tab + "Tab").style.display = "block";
	if (document.getElementById(tab + "TabFocused") != null)
		document.getElementById(tab + "TabFocused").style.zIndex = "55";
}

function TabOver(tab)
{
	document.getElementById(tab + "TabFocused").style.zIndex = "45";
}

function TabOut(tab)
{
	if (document.getElementById(tab + "Tab").style.display != "block")
		document.getElementById(tab + "TabFocused").style.zIndex = "35";
}

function MagTabUnfocus(sender)
{
	TabClick(globalCurrentTab, 1);
	
	Fader(sender, 300, .6, 0, 25);
	document.getElementById(sender).style.border = "none";
}



/***************  TAB SLIDER  *****************************LAS***/
function TabSlider()
{
	var timer = 1;
    
	if (globalInOut == 0)
	{
		while (globalInOut < 32)
		{   
			setTimeout("SliderHelper('1')", timer * 25);
			globalInOut++;
			timer++;
		}
	}
	else
	{
		while (globalInOut > 0)
		{ 
			setTimeout("SliderHelper('2')", timer * 25);
			globalInOut--;
			timer++;
		}
	}
}

function SliderHelper(LeftRight)
{
		if (LeftRight == 1) globalX = globalX - 8;
		else globalX = globalX + 8;
            
		document.getElementById('TabHolder').style.left = globalX + "px";
}



/***************  HEADER PAGE LINKS  **********************************/
function LinkDown(link)
{
	link = document.getElementById('page' + link).className = "Active";
}
function LinkOver(link)
{
	//if the link is not the current page, change the class to hover
	link = document.getElementById('page' + link);    //makes link an object
        
	if(link.className == "Normal")
		link.className = "Hover";
}
function LinkOut(link)
{
	//if hovering change class to normal
	link = document.getElementById('page' + link);    //makes link an object
        
	if(link.className == "Hover")
		link.className = "Normal";
}

function LinkUp(link)
{
	HighlightProperLink();
	
	//document.getElementById('AdPageDisplay').scrollTop = 0;   //for longer documents ("AdPageDisplay" is not currently in this project)
	document.getElementById('ProductsTab').scrollTop = 0;
	
	document.getElementById("divAdLoading").style.display = "block";
	Fader('divAdLoading', 300, 0, 1, 25);
}

function HighlightProperLink()
{
	var counter = 0;
	while (document.getElementById('page' + counter) != null)
	{
		document.getElementById('page' + counter).className = "Normal";
		counter++;
	}
	document.getElementById('page999').className = "Normal";
	document.getElementById('page' + document.getElementById('hfCurrentPage').value).className = "Active";
}

/***************  MISC  *****************************/

function Fader(objectID, duration, startingOpacity, endingOpacity, frequency)
{
	SetOpacity(document.getElementById(objectID), startingOpacity);
	var counter = 0;
	var differenceOpacity = endingOpacity - startingOpacity;
	while (frequency * counter < duration)
	{
		counter++;
		setTimeout('SetOpacity(document.getElementById("' + objectID + '"), "' + eval(startingOpacity + ((frequency*counter/duration) / (1/differenceOpacity))) + '");', counter * frequency);
	}
}

function SetOpacity(object, value) {
	object.style.opacity = value;
	object.style.filter = 'alpha(opacity=' + value*100 + ')';
}

function Preview()
{
	if (globalPreview == 0)
	{
		document.getElementById('divDisplay').className = 'hideme noPrint';
		document.getElementById('divPrint').className = 'showme doPrint';
		globalPreview = 1;
	}
	else
	{
		document.getElementById('divDisplay').className = 'showme noPrint';
		document.getElementById('divPrint').className = 'hideme doPrint';
		globalPreview = 0;
	}
}

function UpdateEmail()
{
	//document.getElementById('hfEmail').value = document.getElementById('PrintoutDiv').innerHTML;
	alert(document.getElementById('PrintoutDiv').innerHTML);
}

function ButtonOver(object)
{
	object.className = "PrintListLink BtnPrintHover";
}
function ButtonOut(object)
{
	object.className = "PrintListLink BtnPrintUnHover";
}

/***************  ON UDP LOADS  *****************************/

function ListUpdate()
{
	PrintoutPictures();
	PrintoutFontSize();
	ShowHideList();
}

function PageFlip()
{
	Fader('pnlAd', 1000, 0, 1, 25);
	HighlightProperLink();
	
	if (globalAfterInitialLoad)
	{
		delay = 375;
		document.getElementById('divAdLoading').style.display = 'block';
		Fader('divAdLoading', delay, 1, 0, 25);
		window.setTimeout("document.getElementById('divAdLoading').style.display = 'none';", delay);
	}
	else
	{
		globalAfterInitialLoad = true;
	}
}

/***************  SHOPPING LIST OPTIONS  *****************************/
function ShowHideList(fade)
{
	var delay = 300;
	if (globalShowHide == 0)
	{
		if (fade != null && fade == true)
			Fader("SListPanel", delay, 0, 1, 25);

		document.getElementById("SListPanel").style.visibility = "visible";
		document.getElementById("ShowHideListA").style.display = "block";
		document.getElementById("ShowHideListB").style.display = "none";
	}
	else
	{
		if (fade != null && fade == true) {
			Fader("SListPanel", delay, 1, 0, 25);
			//window.setTimeout('document.getElementById("SListPanel").style.visibility = "hidden";', delay);
		}
		
		//document.getElementById("SListPanel").style.visibility = "hidden";
		document.getElementById("ShowHideListA").style.display = "none";
		document.getElementById("ShowHideListB").style.display = "block";
	}
}

function PrintoutFontSize()
{
	if (globalBrandPrint == 1)
	{
		document.getElementById("PrintoutDiv").className = 'Printoutlg';
		document.getElementById("PrintoutFontSizeA").style.display = "none";
		document.getElementById("PrintoutFontSizeB").style.display = "block";
	}
	else
	{
		document.getElementById("PrintoutDiv").className = 'Printout';
		document.getElementById("PrintoutFontSizeA").style.display = "block";
		document.getElementById("PrintoutFontSizeB").style.display = "none";
	}
}

function PrintoutPictures()
{
	if (globalPrintPics == 1)
	{   
		PrintoutPicturesHelper('PrintPic PrintShow');
		document.getElementById("PrintoutPicturesA").style.display = "none";
		document.getElementById("PrintoutPicturesB").style.display = "block";
	}
	else
	{
		PrintoutPicturesHelper('PrintPic noPrintNoShow');
		document.getElementById("PrintoutPicturesA").style.display = "block";
		document.getElementById("PrintoutPicturesB").style.display = "none";
	}
}
function PrintoutPicturesHelper(newclass)
{
	counter = 1;
	while (document.getElementById('printout' + counter) != null)
	{
		document.getElementById('printout' + counter).className = newclass;
		counter++;
	}
}