// Gallery Script
function ShowMainImg(ImgUrl, ImgCaption) {
	var ResizeScript = "thumbimg.aspx";
	var GalleryMain = document.getElementById("GalleryMain");
	GalleryMain.style.background="url('" + ResizeScript + "?FileName=" + ImgUrl + "&height=310') no-repeat center top";
	

	
	var nnp=/\\/g 
    var img1 
    img1 = new Image()
    val =ImgUrl;
    img1.src=val
    //alert(img1.src) 
    //alert(img1.height); 
    //alert(img1.width); 
	
	
	self.setTimeout(function () {
		//alert(img1.width);
		var GallerMainWidth = GalleryMain.offsetWidth;
		var ImgWidth = Math.round((img1.width / img1.height) * 400);
		
		//var EnlargeMargin = ((400 * AspectRatio) * 2) - GallerMainWidth;
		var EnlargeMargin = ((GallerMainWidth - ImgWidth) / 2) -0.5;
		
		if (EnlargeMargin < 0) {
			EnlargeMargin = 0;
		}
		
		//alert(EnlargeMargin);
		
		GalleryMain.innerHTML = '<div id="enlarge" class="enlarge" style="display:none;">Enlarge Photo</div>';
		document.getElementById("enlarge").onclick = function () {EnlargePhoto(ImgUrl,img1.width, ImgCaption);}
		new Effect.Appear("enlarge");
		
		new Effect.Morph("enlarge", 
       		{
			style:'background:#FFF; color:#000;'+
            'border: 0px; font-size:11px; margin-left:' + EnlargeMargin + 'px;',
         	duration:0.8
			});

	},500);
	
}

function EnlargePhoto(ImgUrl, ImgWidth ,ImgCaption){ 
	var Ajax = null;
	var LargeImg = null;
	var Transparent = null;
	var test = document.getElementById("Ajax");
	
	if(test==null) {
		//Creates Main Ajax Holder
		Ajax = document.createElement('div');
		Ajax.setAttribute('id','Ajax');
		
		//Creates Transparent Background
		Transparent = document.createElement('div');
		Transparent.setAttribute('id','Transparent');
		Transparent.setAttribute('style','display:block;');
		Transparent.onclick = function() {
			ClosePopup();
		};
		
		var opacity = 70;
		if (navigator.appName.indexOf("Netscape")!=-1 && parseInt(navigator.appVersion)>=5)
			Transparent.style.MozOpacity=opacity/100;
		 else if (navigator.appName.indexOf("Microsoft")!= -1 && parseInt(navigator.appVersion)>=4)
			Transparent.style.filter="alpha(opacity=" + opacity + ")";
			//filter:alpha(opacity=70);

		
		//Creates Prod Ajax Div
		LargeImg = document.createElement('div');
		LargeImg.setAttribute('id','LargeImg');
		LargeImg.setAttribute('style','height:150px; width:150px;');

		Ajax.appendChild(Transparent);
		Ajax.appendChild(LargeImg);
		
		document.body.appendChild(Ajax); 
		
	} else {
		LargeImg = document.getElementById("LargeImg");
		test.style.display="block";
		LargeImg.innerHTML="";
		LargeImg.style.display="block";
		LargeImg.style.background="url('images/ajax-loader.gif') no-repeat center center #FFF";
		$('LargeImg').morph('height:150px; width:150px; margin-left:-75px; top:300px;');
	}
	
	LargeImg = document.getElementById("LargeImg");
	Transparent = document.getElementById("Transparent");
	Transparent.style.display="block";
	LargeImg.style.display="block";
	
	self.setTimeout(function() {
		var x = false;
		var MarginLeft = (ImgWidth / 2);
		while (x == false) {
			if (LargeImg.offsetWidth=='150') {
				$('LargeImg').morph('height:auto; width:auto; margin-left:-' + MarginLeft + 'px; left:50%; top:30px;');
				LargeImg.style.background="#FFF";
				x = true;
				
				//AjaxCommand("includes/functions.aspx", "LargeImg", "LargeImg", "", "sAction=LoadProduct&ProdID=" + ProductID, "POST");
			} 
			
		}
	}, 2000);
	
	self.setTimeout(function() {
		var CloseDiv = '<div id="ClosePopup" onclick="ClosePopup();"></div>';					 
		LargeImg.innerHTML = CloseDiv + '<img src="' + ImgUrl + '" class="LargeImg" />';
		
		if (ImgCaption != "") {
			LargeImg.innerHTML = LargeImg.innerHTML + '<div id="caption" style="width:' + (ImgWidth - 26) + 'px;">' + ImgCaption + '</div>';
		}
		
	}, 3000);
} 


function ClosePopup() {
	$('LargeImg').morph('height:150px; width:150px; margin-left:-75px; top:300px;');
	document.getElementById("Transparent").style.display="none";
	$('LargeImg').fade({ duration: 0.5 });
}
