function showDefaultHorizon()
{
	// First stop movie if it's playing
	if (document.getElementById('movieHorizon').style.visibility=="visible") stopMovie('brandMoviePlayer');
	
	showHideLayer('defaultHorizon', true);
	showHideLayer('movieHorizon', false);
	showHideLayer('photoViewerHorizon', false);
	if ( imageShown && typeof typeof document.getElementById("bodyStyleDisclaimer") != null){
		document.getElementById("bodyStyleDisclaimer").style.display='block';
	}
}
	
var photoThumbnails=null;
var photoIndex=-1;
var photoMaxIndex=1;
var imageShown = false;

function showPhotoViewerHorizon(thumbnail,index)
{
	showHideLayer('defaultHorizon', false);
	showHideLayer('movieHorizon', false);
	showHideLayer('photoViewerHorizon', true);
	if ( typeof document.getElementById("bodyStyleDisclaimer") != null){
		document.getElementById("bodyStyleDisclaimer").style.display='none';
		imageShown = true;
	}	
	photoThumbnails=thumbnail.parentNode;
	photoIndex=index;
	
	viewPreviewPhoto();

    google_analytics_log("/explorepage/" + modelName + "/photos_films/photos_no" + index);
}
	
function previousPreviewPhoto()
{
	if (photoIndex>0)
	{
		photoIndex=photoIndex-1;
	}
	else
	{
		photoIndex=photoMaxIndex-1;
	}
	viewPreviewPhoto();
}
	
function nextPreviewPhoto()
{
	if (photoIndex<photoMaxIndex-1)
	{
		photoIndex=photoIndex+1;
	}
	else
	{
		photoIndex=0;
	}
	viewPreviewPhoto();
}
	
function viewPreviewPhoto()
{
	var imgs = getElementsByClassName(photoThumbnails, "img", "thumbnailImageURL");
	photoMaxIndex=imgs.length;
	for(var i=0; i<imgs.length; i++)
	{
		if (i==photoIndex)
		{
			var previewImagePath=imgs[i].src;
			previewImagePath=previewImagePath.replace(/thumbs/g,"preview");
			document.getElementById("previewPhoto").src=previewImagePath;
			document.getElementById("photoCaption").innerHTML=imgs[i].alt;
			document.getElementById("controls").style.display='block';
			document.getElementById("title").style.display='block';
			var downloadImagePath=imgs[i].src;
			downloadImagePath=downloadImagePath.replace(/thumbs/g,"download");
			document.getElementById("photoDownloadLink").href=downloadImagePath;
			break;
		}
	}
}
	
function showHideLayer(layer, show)
{
	var div=document.getElementById(layer);
	
	if(div == null) 
		return;
	
	if(show)
	{
		div.style.display="inline";
		div.style.visibility="visible";
	}
	else
	{
		div.style.display="none";
		div.style.visibility="hidden";
	}
}

function loadHtmlContent(url, div, async, useCache)
{
	var http_request;
	if(window.XMLHttpRequest && !blnIsInternetExplorer7)
	{
		http_request = new XMLHttpRequest();
		//http_request.overrideMimeType("text/html; charset=UTF8");
	}	
	else if(window.ActiveXObject)
	{
		http_request = new ActiveXObject("Microsoft.XMLHTTP");
	}
		
	var contentToReturn="";
	http_request.onreadystatechange = function ()
	{
    	if (http_request.readyState == 4)
    	{
        	if (http_request.status == 200)
        	{
        		//alert(http_request.responseText+" div="+div);
        		if (div!=null)
        		{
        			//set loaded flag
	        		div.rel="loaded";
		        		
					//update the content in the div
					//var text=Utf8.decode(http_request.responseText)
					div.innerHTML=http_request.responseText;

					//run any javascript that might be in the html response
			        var jsStart='<script type="text\/javascript">';
			        var jsEnd='<\/script>';
			        var jsStartIndex=http_request.responseText.indexOf(jsStart);
			        var jsEndIndex=http_request.responseText.lastIndexOf(jsEnd);
					if(jsStartIndex!=-1 && jsEndIndex!=-1)
					{	
						javascript=http_request.responseText.substring(jsStartIndex+jsStart.length,jsEndIndex);
				        eval(javascript);
					}
				}
				else
				{
					//the return content 
					contentToReturn=http_request.responseText;
				}
        	}
        	else
        	{
        		var errorMessage='There was a problem retrieving content from the server (Error code '+http_request.status+'). Please try again...'
				window.status=errorMessage;

	        	if (div!=null)
        		{
        			//set loaded flag
	        		div.rel="loaded";
					div.innerHTML='<label>'+errorMessage+'</label>';
				}
        	}
       		http_request = null;
    	}
	};
	
	//use cache?
	if (useCache!=null && !useCache)
	{
		if (url.indexOf('?')>-1)
		{
			url=url +'&GUINum=' + new Date().getTime();
		}
		else
		{
			url=url +'?GUINum=' + new Date().getTime();
		}
	}
		
	//begin the download!!
	if (async==null)
	{
		http_request.open("POST", url, true);
	}
	else
	{
		http_request.open("POST", url, async);
	}
	http_request.send("");

	return contentToReturn;
}
