/*Mitsubishi customized javascripts*/

var closeWrapperTiming;

	function closeLightbox() {
		$("#lightboxpopup").fadeOut("fast", function() {
			$("#darkbg").fadeOut("fast", function() {
				$("#preview").html("");
			});
		});
	}

	function displayLightbox(imageLocation,imageURL,imageTitle,imageW,imageH) {

		   var intH = 0, intW = 0;


		    if(self.innerHeight) {
		       intH = window.innerHeight;
		       intW = window.innerWidth;
		    }
		    else {
			if(document.documentElement && document.documentElement.clientHeight) {
			    intH = document.documentElement.clientHeight;
			    intW = document.documentElement.clientWidth;
			}
			else {
			    if(document.body) {
				intH = document.body.clientHeight;
				intW = document.body.clientWidth;
			    }
			}
		    }
		var theUserAgent = navigator.userAgent;
		var wholeH = 0;
		if(theUserAgent.search("AppleWebKit")!=-1) {
			wholeH = window.innerHeight;
		}
		else {
			wholeH = document.body.clientHeight;
		}
		var wholeW = document.body.clientWidth;
		var darkH = 0;
		if(theUserAgent.search("AppleWebKit")!=-1) {
			darkH =  window.innerHeight;
		}
		else if(theUserAgent.search("MSIE")!=-1) {
			darkH =  document.documentElement.clientHeight;
		}
		else {
			darkH = window.innerHeight;
		}
		var yScroll = document.documentElement.scrollTop;


		var xCenter = (intW/2)-(imageW/2);
		xCenter = parseInt(xCenter);
		var yCenter = (intH/2)-(imageH/2)+yScroll;
		yCenter = parseInt(yCenter);


		$("#lightboxpopup").css("top",yCenter+"px");
		if(imageURL=="#") {
			$("#lightboxpopup").css("top","0");
		}

		if((imageH+20)>document.documentElement.clientHeight) {
			$("#lightboxpopup").css("top","0");
		}
		if(imageW > intW) {
			$("#lightboxpopup").css("left","0px");
		}
		else{
			$("#lightboxpopup").css("left",xCenter+"px");
		}
		$("#lightboxpopup").css("width",imageW+"px");
		$("#lightboxpopup").css("height",imageH+20+"px");
		$("#darkbg").css("width",wholeW+"px");
		$("#darkbg").css("height",darkH+"px");

		if(imageURL=="#") {
			imageURL="javascript:closeLightbox()";
		}

		$("#darkbg").fadeIn("fast", function() {
			if(imageURL=="flash-movie") {
				$("#lightboxpopup").fadeIn(2500, function() {
							if(imageURL=="flash-movie") {
								$("#preview").html(generateTheFlash(imageLocation, imageW, imageH));
								closeWrapperTiming = setTimeout("showTheCloseWrapper()",9000);
							}
							else {
									$("#lightboxCloseWrapper").css("display","block");
									$("#lightboxTitle").html(imageTitle);
									$("#preview").html('<a href="'+imageURL+'"><img src="'+imageLocation+'"\/><\/a>');
							}
				});
			}
			else{
				$("#lightboxpopup").fadeIn("slow", function() {
									$("#lightboxCloseWrapper").css("display","block");
									$("#lightboxTitle").html(imageTitle);
									$("#preview").html('<a href="'+imageURL+'"><img src="'+imageLocation+'"\/><\/a>');
				});
			}
		});
		return false;

	}

	function showTheCloseWrapper() {
		$("#lightboxCloseWrapper").fadeIn("fast");
	}

	function generateTheFlash(movieURL, movieWidth, movieHeight) {

	var theFlashMovie = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http:\/\/download.macromedia.com\/pub\/shockwave\/cabs\/flash\/swflash.cab#version=9,0,0,0" ';
	theFlashMovie +=  'width="'+ movieWidth +'" height="'+ movieHeight +'" ';
	theFlashMovie+=  ' id="lightboxFlash" align="middle">       <param name="allowScriptAccess" value="sameDomain" \/>       <param name="allowFullScreen" value="false" \/>      ';
	theFlashMovie += ' <param name="movie" value="' + movieURL + '" \/>       <param name="quality" value="high" \/>       <param name="bgcolor" value="#000000" \/>       <embed src="' + movieURL + '" quality="high" bgcolor="#000000" width="' + movieWidth + '" height="' + movieHeight + '" name="lightboxFlash" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application\/x-shockwave-flash" pluginspage="http:\/\/www.macromedia.com/go/getflashplayer" \/><\/object>';

	return theFlashMovie;
	}
