/**************************************************************************
Begin set the image path by protocol
***************************************************************************/
var imagePath = '';
var protocol = document.location.protocol.toLowerCase();
var host = document.location.host.toLowerCase();
switch (host) {
    case 'getitnow.vzwshop.com':
        imagePath = protocol + (protocol == 'https:' ? '//s-cache.getitnow.vzwshop.com/' : '//cache.getitnow.edgesuite.net/');
        break;
    case 'preprod.getitnow.vzwshop.com':
        imagePath = protocol + '//test-cache.getitnow.vzwshop.com/';
        break;
    default:
        imagePath = '';
        break;
}
/**************************************************************************
End set the image path by protocol
***************************************************************************/

sshContainer = $('ssh');
sshTime = null
sshStep=0
sshTotal=0
sshPause=0
sshCat=0

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}
addLoadEvent(sshInit);

function sshInit() {

	if (navigator.appVersion.indexOf("MSIE")!=-1){
	document.execCommand("BackgroundImageCache",false,true)
	}
	
	var items = getElementsByClass('sshopen',sshContainer,'A');
	for (j=0; j < items.length; j++)
	{
		 items[j].id = 'ssh'+j;
		 items[j].href = "javascript:sshOpen("+j+")";
		 eval("items[j].onfocus = function() {return sshOpen("+j+");}");
		 eval("items[j].onblur = function() {return openOut(this);}");
		 eval("items[j].onmouseout = function() {return openOut(this);}");
		 eval("items[j].onmouseover = function() {return openOver(this);}");
	}

	var nexts = getElementsByClass('sshnext',sshContainer,'A');
	for (j=0; j < nexts.length; j++)
	{
		 nexts[j].href = 'javascript:sshNext()';
		 eval("nexts[j].onmouseout = function() {return nextOut(this);}");
		 eval("nexts[j].onmouseover = function() {return nextOver(this);}");
		 eval("nexts[j].onblur = function() {return nextOut(this);}");
		 eval("nexts[j].onfocus = function() {return nextOver(this);}");
	}

	var previous = getElementsByClass('sshprevious',sshContainer,'A');
	for (j=0; j < previous.length; j++)
	{
		 previous[j].href = 'javascript:sshPrevious()';
		 eval("previous[j].onmouseout = function() {return previousOut(this);}");
		 eval("previous[j].onmouseover = function() {return previousOver(this);}");
		 eval("previous[j].onblur = function() {return previousOut(this);}");
		 eval("previous[j].onfocus = function() {return previousOver(this);}");
	}

	var plays = getElementsByClass('sshpp',sshContainer,'A');
	for (j=0; j < plays.length; j++)
	{
		 plays[j].href = 'javascript:sshPP()';
		 eval("plays[j].onmouseout = function() {return ppOut(this);}");
		 eval("plays[j].onmouseover = function() {return ppOver(this);}");
		 eval("plays[j].onblur = function() {return ppOut(this);}");
		 eval("plays[j].onfocus = function() {return ppOver(this);}");
	}

	var closes = getElementsByClass('sshclose',sshContainer,'A');
	for (j=0; j < closes.length; j++)
	{
		 closes[j].href = 'javascript:sshClose()';
		 eval("closes[j].onblur = function() {return closeOut(this);}");
		 eval("closes[j].onfocus = function() {return sshOpenAlt(this,"+j+");}");
	}

	var headers = getElementsByClass('sshheader',sshContainer,'A');
	for (j=0; j < headers.length; j++)
	{
		 eval("headers[j].onfocus = function() {return sshClose();}");
	}

	var numbers = getElementsByClass('sshnumber',sshContainer,'SPAN');
	for (j=0; j < numbers.length; j++)
	{
		 numbers[j].id = 'sshnumber'+j;
	}

	var backs = getElementsByClass('sshpopback',sshContainer,'DIV');
	for (k=0; k < backs.length; k++)
	{
		 backs[k].id = "ssh"+k+"popback";
		 backs[k].style.left='-1000em';
	}

	var inners = getElementsByClass('sshpop',sshContainer,'DIV');
	for (n=0; n < inners.length; n++)
	{
		inners[n].id = 'ssh'+n+'pop';
		inners[n].style.left='-1000em';

		var ps = inners[n].getElementsByTagName('P');
		for (p = 0; p < ps.length; p++)
		{
			ps[p].id = 'sshtext'+n+p;
		}

		var qs = inners[n].getElementsByTagName('IMG');
		for (q = 0; q < qs.length; q++)
		{
			if (qs[q].className=='sshimage')
			{
			qs[q].id = 'sshimage'+n+q;
			}
		}
	}
}

function openOver(el) {
el.firstChild.src=imagePath+'imgs/nav/i/popup/slideshow_on.gif';
}

function openOut(el) {
el.firstChild.src=imagePath+'imgs/nav/i/popup/slideshow_off.gif';
}

function nextOver(el) {
el.firstChild.src=imagePath+'imgs/nav/i/popup/fwd_on.gif';
}

function nextOut(el) {
el.firstChild.src=imagePath+'imgs/nav/i/popup/fwd_off.gif';
}

function previousOver(el) {
el.firstChild.src=imagePath+'imgs/nav/i/popup/rev_on.gif';
}

function previousOut(el) {
el.firstChild.src=imagePath+'imgs/nav/i/popup/rev_off.gif';
}

function ppOver(el) {
	if (sshPause == '0')
	{
		el.firstChild.src=imagePath+'imgs/nav/i/popup/pas_on.gif';
	}
	else
	{
		el.firstChild.src=imagePath+'imgs/nav/i/popup/play_on.gif';
	}
}

function ppOut(el) {
	if (sshPause == '0')
	{
		el.firstChild.src=imagePath+'imgs/nav/i/popup/pas_off.gif';
	}
	else
	{
		el.firstChild.src=imagePath+'imgs/nav/i/popup/play_off.gif';
	}
}

function closeOver(el) {
el.style.color='#66f';
}

function closeOut(el) {
el.style.color='#339';
}

function sshOpenAlt(el,catIntakeAlt) {
	closeOver(el);
	if ($('ssh'+catIntakeAlt+'pop').style.left != 'auto')
	{
		sshOpen(catIntakeAlt);
	}
}

function sshOpen(catIntake) {
	sshClose();
	sshCat = catIntake
	
	var howmany = $('ssh'+sshCat+'pop').getElementsByTagName('IMG');
	thismany = howmany.length
	sshTotal = thismany - 4;
	sshCurrent();

	$('ssh'+sshCat+'pop').style.left='auto';
	$('ssh'+sshCat+'popback').style.left='auto';
	sshBam();

	$('sshimage'+sshCat+sshStep).style.left='auto';
	$('sshtext'+sshCat+sshStep).style.left='auto';
	sshTime = setTimeout ('sshPlay()', 3000 );
}

function sshClose() {
	$('ssh'+sshCat+'pop').style.left='-1000em';
	$('ssh'+sshCat+'popback').style.left='-1000em';
	sshStep=0
	sshPause=0
	clearTimeout(sshTime);
	var pauses = getElementsByClass('sshpp',sshContainer,'A');
	for (x=0; x < pauses.length; x++)
	{
		 pauses[x].firstChild.src=imagePath+'imgs/nav/i/popup/pas_off.gif';
	}
}

function sshPP() {
	if (sshPause == '0')
	{
		clearTimeout(sshTime);
		var pauses = getElementsByClass('sshpp',sshContainer,'A');
		for (x=0; x < pauses.length; x++)
		{
			 pauses[x].firstChild.src=imagePath+'imgs/nav/i/popup/play_on.gif';
		}
		sshPause=1;
	}
	else
	{	
		var pauses = getElementsByClass('sshpp',sshContainer,'A');
		for (x=0; x < pauses.length; x++)
		{
			 pauses[x].firstChild.src=imagePath+'imgs/nav/i/popup/pas_on.gif';
		}
		sshPlay();
	}
}

function sshPlay() {
	if (sshStep<sshTotal) {
	sshStep++
	}
	else
	{
	sshStep=0
	}
	sshBam();
	$('sshimage'+sshCat+sshStep).style.left='auto';
	$('sshtext'+sshCat+sshStep).style.left='auto';
	sshTime = setTimeout ('sshPlay()', 3000 );
	sshPause=0;
	sshCurrent();
}

function sshNext() {
	if (sshPause == '0')
	{
		clearTimeout(sshTime);
		var pauses = getElementsByClass('sshpp',sshContainer,'A');
		for (x=0; x < pauses.length; x++)
		{
			 pauses[x].firstChild.src=imagePath+'imgs/nav/i/popup/play_off.gif';
		}
		sshPause=1;
	}
	if (sshStep<sshTotal) {
	sshStep++
	}
	else
	{
	sshStep=0
	}
	sshBam();
	$('sshimage'+sshCat+sshStep).style.left='auto';
	$('sshtext'+sshCat+sshStep).style.left='auto';
	sshCurrent();
}

function sshPrevious() {
	if (sshPause == '0')
	{
		clearTimeout(sshTime);
		var pauses = getElementsByClass('sshpp',sshContainer,'A');
		for (x=0; x < pauses.length; x++)
		{
			 pauses[x].firstChild.src=imagePath+'imgs/nav/i/popup/play_off.gif';
		}
		sshPause=1;
	}
	if (sshStep == 0) {
	sshStep=sshTotal
	}
	else
	{
	sshStep--
	}
	sshBam();
	$('sshimage'+sshCat+sshStep).style.left='auto';
	$('sshtext'+sshCat+sshStep).style.left='auto';
	sshCurrent();
}

function sshBam() {
	var imgs = getElementsByClass('sshimage',sshContainer,'IMG');
	for (x=0; x < imgs.length; x++)
	{
		 imgs[x].style.left='-1000em';
	}
	var items = getElementsByClass('sshpop',sshContainer,'DIV');
	for (n=0; n < items.length; n++)
	{
		var pars = items[n].getElementsByTagName('P');
		for (p = 0; p < pars.length; p++)
		{
			pars[p].style.left='-1000em';
		}
	}
}

function sshCurrent() {
	$('sshnumber'+sshCat).innerHTML = (sshStep+1)+' of '+(sshTotal+1);
}

function $() {
	if (arguments.length == 1) return get$(arguments[0]);
	var elements = [];
	$c(arguments).each(function(el){
		elements.push(get$(el));
	});
	return elements;
	function get$(el){
		if (typeof el == 'string') el = document.getElementById(el);
		return el;
	}
}

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}