jQuery(document).ready(function()
{
	$("body").append('<div id="galleryHolder"></div>');
	$("#galleryStarter").click(function(){
		getSizes();	
		$("#galleryHolder").show();
		$("#galleryHolder").css("top",windowH/2);
		$("#galleryHolder").css("left",windowW/2);
		$("#galleryHolder").animate({ 
			width: "100%",
			height: "100%",
			top:0,
			left:0
		}, 400, generateGallery());
	});
});


function generateGallery()
{
	getSizes();
	var content = $("#galleryHolder").html();

	if (content == "")
	{
		if (typeof(tourType) !== 'undefined')
			thisType = tourType;
		else
			thisType = tourtype;
		
		if (thisType == "f" || thisType == "fs")
			thisType = "vt";
		else
			thisType = "ss";
		
			
		$.ajax({
		type: "get",
		url: 'http://www.myvisuallistings.com/' + thisType + '/'+tourID+'/photos/'+ screen.width,
		dataType: "html",
		success: function(feedResult)
			{	
				
				$("#galleryHolder").append('<div id="linkHolder"><a href="#" onclick="closeGallery();" class="closeButton">Close</a></div>' + feedResult);
				$("#galleryHolder").css("background-image","none");
			}
		});	
	}
	else
	{
		$(".highslide-container").show();
		$("#linkHolder").show();
	}
}
function openGallery()
{
	getSizes();	
	$("#galleryHolder").show();
	$("#galleryHolder").css("top",windowH/2);
	$("#galleryHolder").css("left",windowW/2);
	$("#galleryHolder").animate(
		{ 
			width: "100%",
			height: "100%",
			top:0,
			left:0
		},
	400,
	generateGallery());
}

function closeGallery()
{
	$(".highslide-container").hide();
	$("#linkHolder").hide();
	
	getSizes();
	 	toSizeH = windowH/2;
		 toSizeW = windowW/2;
		//$("#galleryHolder").empty();
		$("#galleryHolder").animate({ 
			width: 1,
			height: 1,
			top:toSizeH,
			left:toSizeW
		}, {
			duration: 400,
			oncomplete: function(){
				$("#galleryHolder").hide();
			}
		});
	
}

function getSizes()
{
	
	if (parseInt(navigator.appVersion)>3)
	{
		if (navigator.appName=="Netscape")
		{
			windowW = window.innerWidth;
			windowH = window.innerHeight;
		}
		if (navigator.appName.indexOf("Microsoft")!=-1)
		{
			windowW = document.documentElement.clientWidth;
			windowH = document.documentElement.clientHeight;
		}
	}
}
