function positionArrow(){
	var arrow = $("list-arrow-container");
	var list = $("list");
	
	var paramValue = returnRequestParameter("listIdx");
	var validID = paramValue || paramValue>=0;

	var count = -1;
	if (list && list.childNodes){
		for (var i=0; i<list.childNodes.length; i++){
			var element = list.childNodes[i];
			if (element.className){
				count++;
				if (validID && count+1 == paramValue){
					element.className = "list-selected-element"+(count==0?" first":"");
					arrow.style.top = (element.offsetTop + (count==0?3:9))+"px";
					return;
				}
			}
		}
	}
}
function positionArrowdiv(listid){
	var arrow = $("list-arrow-container");
	var list = $("list");
	
	var paramValue = listid;
	var validID = paramValue || paramValue>=0;

	var count = -1;
	if (list && list.childNodes){
			for (var i=0; i<list.childNodes.length; i++){
			var element = list.childNodes[i];
			if (element.className){
			count++;
				if(count==0)
				{
					element.className ="list-element first";
				}
				else
				{
					element.className ="list-element";
				}
				if (validID && count+1 == paramValue){
					element.className = "list-selected-element"+(count==0?" first":"");
					arrow.style.top = (element.offsetTop + (count==0?3:9))+"px";
				}
			}
		}
	}
}

function initScroll(){
	if ($("content-scrollable").offsetHeight > $("slider-tray").offsetHeight){
			$("slider-tray").style.visibility = "visible";
		new Control.Slider('slider-handle','slider-tray',{axis:'vertical',
	//		range:$R(0,100),
			onSlide:function(v){
				var height = $("content-scrollable").offsetHeight - $("slider-tray").offsetHeight;
				$("content-scrollable").style.top = "-"+(Math.round((height)*v))+"px";
			},
			onChange:function(v){
				var height = $("content-scrollable").offsetHeight - $("slider-tray").offsetHeight;
				$("content-scrollable").style.top = "-"+(Math.round((height)*v))+"px";
			}
		});
	}
	else
	{
	$("slider-tray").style.visibility = "hidden";
	}
}

var VMNavLeft;
var VMNavTop;

function align(){

	wh = parseInt(getWindowHeight());
	divH = parseInt(getHeight('container'));
	
	newMargin = (wh - divH)/2;
	newMargin = (newMargin<0 ? 0 : newMargin);
	
	$("container").style.margin = newMargin + "px auto 0px auto";
	
	VMNavTop = parseInt(getAbsY(document.getElementById('navPlaceHolder'))) + 'px';
	VMNavLeft = parseInt(getAbsX(document.getElementById('navPlaceHolder'))) + 'px';
	
	document.getElementById('nav').style.top = VMNavTop;
	document.getElementById('nav').style.left = VMNavLeft;
	
	
}


var navId = "VitaminWaterNav";
function openNav() {
	//alert('open')
	var navObj = (document.getElementById(navId)) ? document.getElementById(navId) : document[navId];
	//document.getElementById('nav').style.height = 400;
	navObj.height = 400;
}

function closeNav() {
	//alert('close')
	var navObj = (document.getElementById(navId)) ? document.getElementById(navId) : document[navId];
	//document.getElementById('nav').style.height = 20;
	navObj.height = 24;
}	
var digitalGoodiesArray=[''];
function launchGallery1()
{

digitalGoodiesArray[0]=goodieFlashURL;
//alert('digitalGoodiesArray launchGallery1() is : '+digitalGoodiesArray);
launchGallery();
}

function launchGallery(){
dcsMultiTrack("DCS.dcsuri",dcsURI+"/launchgallery.dhtml", "WT.ti",title+" launch gallery ","WT.cg_n",contentGroup,"WT.cg_s",contentSubGroup, "DCSext.w_locale", locale);
	if(goodieIndex < digitalGoodiesArray.length){
	//alert('digitalGoodiesArray is : '+digitalGoodiesArray );
		digitalGoodieCollectionRequestInit();
	}else{
		//alert('calling loadGalleryAlt');
		loadGalleryAlt();	
	}
}


function writeGallery(){
	var hasRightVersion = (parseInt(GetSwfVer())>=9 ? true : false);
	if(hasRightVersion){
		$('playerContainer').style.display = 'none';
		$('galleryControl').style.visibility = 'hidden';
		$('playerContainer').style.position="absolute";
		$('playerContainer').style.left= (parseInt(getAbsX($('content')))) + "px";
		$('playerContainer').style.top=  (parseInt(getAbsY($('content')))) + "px";
		$('playerContainer').style.width = '504px';
		$('playerContainer').style.height = '290px';
		
		
		
		$('playerContainer').innerHTML =(AC_FL_RunContent(
			'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
			'width', '504',
			'height', '290',
			'src', 'GalleryMain',
			'quality', 'high',
			'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
			'align', 'middle',
			'play', 'true',
			'loop', 'true',
			'scale', 'showall',
			'wmode', 'transparent',
			'devicefont', 'false',
			'id', 'GalleryMain',
			'bgcolor', '#ffffff',
			'name', 'GalleryMain',
			'menu', 'true',
			'allowFullScreen', 'false',
			'allowScriptAccess','sameDomain',
			'movie', goodieFlashAssetLocation,
			'salign', '',
			'flashVars','xmlPath=' + digitalGoodiesArray[0]
			));
		$('playerContainer').style.display = 'block';
	}
}

function closeGallery() {
	  //alert("closeGallery");
	  //$('playerContainer').style.position="relative";
		//$('playerContainer').style.width = '1px';
		//$('playerContainer').style.height = '1px';
		//$('playerContainer').innerHTML = '';
		$('playerContainer').style.display="none";
		$('galleryControl').style.visibility = 'visible';
		goodieIndex=0;
}

//var digitalGoodiesArray=['../../pages/events_detail/vw_with_flash_digital_goodies_collection_en_AU.xml'];
var digitalGoodiesDesc = new Array;

var goodieIndex = 0;
function digitalGoodieCollectionRequestInit(){
	
		if (xml_request != null){
			xml_request.abort();
			xml_request = null;
		}
	
		if (window.XMLHttpRequest) { // Mozilla, Safari, ...
    		xml_request = new XMLHttpRequest();
		} else if (window.ActiveXObject) { // IE
			
   		 	xml_request = new ActiveXObject("Microsoft.XMLHTTP");
   		 	
		}
		
		xml_request.onreadystatechange = function(e) {digitalGoodiexml_loaded(e, xml_request);}

		xml_request.open("GET", digitalGoodiesArray[goodieIndex]);
		
		xml_request.send(null);
	
	}


function digitalGoodiexml_loaded (e, request){	
		//alert(request.readyState)
		
		if(request.readyState == 4){
			
			respText=request.responseText;
			
			if(respText.indexOf('412')>=0){
				
				digitalGoodieCollectionRequestInit();	
				return;
			}
			
			
			if(goodieIndex==0){
				//alert(request.responseXML)
				goodies = request.responseXML.getElementsByTagName('instanceItem');
				
				for(x=0; x<goodies.length; x++){
					// Jeremy's code to remove file path
					var file_name2 = "";
					var full_path2 = "";
					var xmlPath = "";

					var new_prefix2 = "";

					//store the full path in a variable
					
					full_path2 = goodies[x].firstChild.nodeValue;	

          full_path2=full_path2.substring((full_path2.lastIndexOf('/')+1));

					
					//crawl backwards through the path, stop at the first "/" and extract the file name
					/*for(y=full_path2.length - 1; y >= 0; y--){	
						if (full_path2.charAt(y) == "/") {
							file_name2 = full_path2.substr(y+1, full_path2.length - y);

							xmlPath =  new_prefix2 + file_name2;

						}
					}*/
					// End Jeremy's code
					//alert('full_path2 is : ' +full_path2);
       
					//JG - Not sure how to make this call:
					digitalGoodiesArray.push(full_path2);
					//
					//digitalGoodiesArray.push(xmlPath);

				}
					//alert('in if  goodies index is : '+goodieIndex);
				goodieIndex++;
				launchGallery();
			
			}else{
			//alert('in else goodies index is : '+goodieIndex);
				digitalGoodiesDesc.push(request.responseXML.getElementsByTagName('description')[0].firstChild.nodeValue);	
				goodieIndex++;
				launchGallery();
			}
		}
}


function loadGalleryAlt(){
	altlist = document.createElement('ul');	
	for(x=0; x<digitalGoodiesDesc.length; x++){
		descLI = document.createElement('li');
		descLI.innerHTML = digitalGoodiesDesc[x];
		altlist.appendChild(descLI);
	}
	//alert('altlist '+altlist);
	document.getElementById('galleryAltContent').appendChild(altlist);
	writeGallery();
	document.location ="#galleryAnchor";
}
