var lastTarget = "";
function getInitialURL(){
	return(window.location);
}
function getReferrer(){
	if(lastTarget == "")
	{
		lastTarget = getInitialURL();  // handles initial logic
	}
	return(lastTarget);
}
function reportWebTrendsEvent(wtSKU, pageName, locationOfLink, linkName, pageHit, fileName, target)

{
	var truncTarget = target.substr(27,target.length);
    var referrer = getReferrer();  // get's the referring page, which is the lastTarget
    lastTarget = target; // resets lastTarget for next ttime
    if(fileName != 'null') {
    	dcsMultiTrackTop('DCS.dcsuri',truncTarget,'DCS.dcsref',referrer,'DCSext.wtNoHit',pageHit,'DCSext.wtPN',pageName,'WT.pn_sku',wtSKU,'DCSext.wtLinkLoc',locationOfLink,'DCSext.wtLinkName',linkName,'DCSext.wtFileName',fileName);
    } else {
   	    dcsMultiTrackTop('DCS.dcsuri',truncTarget,'DCS.dcsref',referrer,'DCSext.wtNoHit',pageHit,'DCSext.wtPN',pageName,'WT.pn_sku',wtSKU,'DCSext.wtLinkLoc',locationOfLink,'DCSext.wtLinkName',linkName);
    }
// do whatever needs to be done to hit the webtrends server
    var s = "wtSKU=" + wtSKU + "\r\n";
    s += "pageName=" + pageName + "\r\n";
    s += "locationOfLink=" + locationOfLink + "\r\n";
    s += "linkName=" + linkName + "\r\n";
    s += "pageHit=" + pageHit + "\r\n";
    s += "fileName=" + fileName + "\r\n";
    s += "target=" + truncTarget + "\r\n";
    s += "referrer=" + referrer + "\r\n";
    //alert(s);

}

function setImageGalleryURL(xmlURL, imageDirectory)
{
	// alert("setImageGalleryURL\r\nxmlURL = " + xmlURL + "\r\nimageDirectory = " + imageDirectory);
	/*
	 * xmlURL                = URL of the 'XML file to load. Must be a relative path.
	 * imageDirectory        = The directory containing images. This will be prepended to the image name
	 *                         contained in the XML document.
	 */

	var xhr = new Ajax.Request(xmlURL, {
		method: 'get',
		onSuccess: function(transport) {
			var image_tags = transport.responseXML.getElementsByTagName('image');
			var lightbox_container = $('lightbox_image_container');  /* a div element in the document that is display:none */
			for (var i=0; i<image_tags.length; i++)
				lightbox_container.innerHTML += '<a id="image_' + i + '" href="' + imageDirectory + image_tags[i].getAttribute('path') + image_tags[i].getAttribute('suffix') + '" title="' + image_tags[i].getAttribute('title') + '" rel="lightbox[image]" width="' + image_tags[i].getAttribute('width') + '" height="' + image_tags[i].getAttribute('height') + '"></a>';
		}
	});
	try { xhr.transport.send(null); } catch(e){}
}
function setMediaGalleryURL(xmlURL)
{
	var xhr = new Ajax.Request(xmlURL, {
		method: 'get',
		onSuccess: function(transport) {
			var movie_tags = transport.responseXML.getElementsByTagName('movie');
			var lightbox_container = $('lightbox_movie_container'); /* a div element in the document that is display:none */
			for (var i=0; i<movie_tags.length; i++)
				lightbox_container.innerHTML += '<a id="movie_' + i + '" href="/media/en_US/360s/assets/swf/videoPlayer.swf" title="' + movie_tags[i].getAttribute('title') + '" rel="lightbox[movie]" width="' + movie_tags[i].getAttribute('width') + '" height="' + movie_tags[i].getAttribute('height') + '">' + movie_tags[i].getAttribute('flvURL') + '</a>';
		}
	});
	try { xhr.transport.send(null); } catch(e){}
}
function launchImage(index)
{
	var objLink = document.getElementById('image_' + index);
	Lightbox.prototype.start(objLink);
}
function launchMedia(index)
{
	var objLink = document.getElementById('movie_' + index);
	Lightbox.prototype.start(objLink);
}
function onSubMenuClick(linkID)
{
	showTab( linkID );
}
function GroupDelegate(id)
{
	var objLink = document.getElementById(id);
	Lightbox.prototype.start(objLink);
}
function thisMovie(movieName)
{
	var pMovie = document.getElementById(movieName);
	return pMovie;
}
function changeColor(sku)
{
	var movie = thisMovie("phone");
	movie.setColorSKU(sku);
}
function setCompare(index)
{
	var movie = thisMovie("phone");
	movie.setCompareObject(index);
}

function updateImageGalleryIndex(index)
{
	var movie = thisMovie("phone");
	movie.updateImageGalleryIndex(index);
	
}

function updateMediaGalleryIndex(index)
{
	var movie = thisMovie("phone");
	movie.updateMediaGalleryIndex(index);
	
}

