var texts = new Array();
var imgs = new Array();
var tID = 1;
var otID = 0;
var iID = 1;
var oiID = 0;
var t, i;
var aDiv, bDiv, aImg, bImg, opcIE;
var imgTimeout = 14000;
var textTimeout = 7000;
/*
texts[0] = '<p class="hglarge"><br />3 DAYS TO 30,000 NEW, DEDICATED<br />BRAND CHAMPIONS</p>';
texts[1] = '<p class="hgsmall">&quot;So much has changed in wine sales &amp; marketing…<br />&nbsp;especially in how people shop. No one channel is<br />&nbsp;sufficient. I think we need them all.&quot;</p><p class="sig">JOY STERLING, CEO IRON HORSE VINEYARDS</p>';
texts[2] = '<p class="hglarge"><br />1 DEAL + 1000 3-PACKS + 3 DAYS =<br />QUICK DTC REVENUE</p>';
texts[3] = '<p class="hgsmall">&quot;St. Supery&#39;s recent sale on Rue La La was a<br />&nbsp;whopping success…&quot;</p><p class="sig">LESLEY KEFFER RUSSELL, VP DIRECT MARKETING & SALES<br />ST. SUPERY VINEYARDS & WINERY</p>';
texts[4] = '<p class="hglarge"><br />20 YEARS OF WINERY, LOGISTICS &<br />FULFILLMENT EXPERTISE</p>';
texts[5] = '<p class="hgsmall">&quot;It&#39;s really every winery&#39;s dream – direct sales.<br />&nbsp;No overhead, nothing except someone sitting at a<br />&nbsp;computer. Wine.Woot brought us a 20% increase<br />&nbsp;in direct sales.&quot;</p><p class="sig">JOAN AND RICH LITTLE, LITTLE VINEYARDS</p>';
*/
texts[0] = 'siteImages/aText1.gif';
texts[1] = 'siteImages/aText2.gif';
texts[2] = 'siteImages/aText3.gif';
texts[3] = 'siteImages/aText4.gif';
texts[4] = 'siteImages/aText5.gif';
texts[5] = 'siteImages/aText6.gif';

imgs[0] = 'siteImages/wine-grapes.jpg';
imgs[1] = 'siteImages/wine-ship.jpg';
imgs[2] = 'siteImages/wine-pour.jpg';

function $(theObject) {
	return document.getElementById(theObject);
}

function $S(theStylesheet) {
	return document.styleSheets[theStylesheet];
}

function $O(theObject) {
	return eval(theObject+"."+opcString);
}

function moveXDissolve(transTime, targetX, targetD, xFactor) {
	done = 0;
	transTime = transTime;
	targetX = targetX;
	xFactor = xFactor;
	currX = bDiv.style.left.replace("px","");
	if (opcIE) {
		currAD = aDiv.filters.alpha.opacity;
		currBD = bDiv.filters.alpha.opacity;
	} else {
		currAD = aDiv.style.opacity;
		currBD = bDiv.style.opacity;
	}
	if (targetX != currX && Math.abs(currX - targetX) > 1) {
		if (targetX < currX) {
			currX = targetX + Math.round((currX - targetX)/xFactor) + "px";
		} else if (targetX > currX) {
			currX = targetX - Math.round((targetX - currX)/xFactor) + "px";
		}
		currAD = currAD - (currAD/xFactor);
		currBD = targetD - (targetD - currBD)/xFactor;
		
	} else {
		currX = targetX + "px";
		currAD = 0;
		currBD = 1;
		if (opcIE) currBD = 100;
		done = 1;
	}
	
	bDiv.style.left = currX;
	if (opcIE) {
		aDiv.filters.alpha.opacity = currAD;
		bDiv.filters.alpha.opacity = currBD;
	} else {
		aDiv.style.opacity = currAD;
		bDiv.style.opacity = currBD;
	}

	if (done==1) {
		clearTimeout(t);
	} else {
		delay = function() { moveXDissolve(transTime, targetX, targetD, xFactor); };
		t = setTimeout(delay, transTime);
	}
}

function imgDissolve(dTime, dTarget, dFactor) {
	done = 0;
	dTime = dTime;
	dTarget = dTarget;
	dFactor = dFactor;
	if (opcIE) {
		currAD = aImg.filters.alpha.opacity;
		currBD = bImg.filters.alpha.opacity;
	} else {
		currAD = aImg.style.opacity;
		currBD = bImg.style.opacity;
	}
	
	if ((opcIE && dTarget - currBD > 1) || (!opcIE && dTarget - currBD > .01)) {
		currBD = dTarget - (dTarget - currBD)/dFactor;
		currAD = currAD - (dTarget - (currAD/dFactor));
	} else {
		currAD = 0;
		currBD = 1;
		if (opcIE) currBD = 100;
		done = 1;
	}
	if (opcIE) {
		aImg.filters.alpha.opacity = currAD;
		bImg.filters.alpha.opacity = currBD;
	} else {
		aImg.style.opacity = currAD;
		bImg.style.opacity = currBD;
	}
	
	if (done==1) {
		clearTimeout(i);
	} else {
		delay = function() { imgDissolve(dTime, dTarget, dFactor); };
		i = setTimeout(delay, dTime);
	}
}

function textTimer() {
	if (texts.length - 1 == otID) {
		tID = 0;
	} else if (tID == 1) {
		otID = 0;
	}
	aDiv.style.backgroundImage = "url("+texts[otID]+")";
	bDiv.style.backgroundImage = "url("+texts[tID]+")";
	//aDiv.innerHTML = texts[otID];
	//bDiv.innerHTML = texts[tID];
	if (opcIE) {
		aDiv.filters.alpha.opacity = 100;
		bDiv.filters.alpha.opacity = 0;
		dTarget = 100;
	} else {
		aDiv.style.opacity = 1;
		bDiv.style.opacity = 0;
		dTarget = 1;
	}

	bDiv.style.left = "411px";
	moveXDissolve(100,0,dTarget,2);
	
	otID++;
	tID++;
	m = setTimeout("textTimer()",textTimeout)
}

function imgTimer() {
	if (imgs.length - 1 == oiID) {
		iID = 0;
	} else if (iID == 1) {
		oiID = 0;
	}
	aImg.style.backgroundImage = "url("+imgs[oiID]+")"
	bImg.style.backgroundImage = "url("+imgs[iID]+")"
	if (opcIE) {
		aImg.filters.alpha.opacity = 100;
		bImg.filters.alpha.opacity = 0;
		dTarget = 100;
	} else {
		aImg.style.opacity = 1;
		bImg.style.opacity = 0;
		dTarget = 1;
	}
	imgDissolve(100,dTarget,1.2);
	
	oiID++;
	iID++;
	i = setTimeout("imgTimer()",imgTimeout);
}

function firstTrigger() {
	aDiv = $("hgtext1");
	bDiv = $("hgtext2");
	aImg = $("hgimg1");
	bImg = $("hgimg2");
	try {
		opcTest = aDiv.filters.alpha;
		opcIE = true;
	} catch(e) {
		opcIE = false;
	}
	
	tID = Math.floor(Math.random() * texts.length);
	if (tID == 0) {
		otID = texts.length - 1;
	} else {
		otID = tID - 1;
	}
	aDiv.style.backgroundImage = "url("+texts[otID]+")";
	bDiv.style.backgroundImage = "url("+texts[tID]+")";
	
	mt = setTimeout("textTimer()",textTimeout);
	mi = setTimeout("imgTimer()",imgTimeout);
}


