//<script type='text/javascript'>

function MMWindowClass(jsInstance,MMW01,MMW02,MMW03,MMW04,MMW05,MMW06,MMW07,MMW08,MMW09,MMW10)
{
	var _instance = jsInstance;		this.GetInstance = function(){ return _instance;};
	var me = this;
	/* ELEMENTS */	
	var _bodyElement = document.documentElement?document.documentElement:document.body;
	this.GetBodyElement = function() { return _bodyElement };
	var _backLayer = document.getElementById(MMW01);			this.GetBackLayer = function(){ return _backLayer;};
	var _headLayer = document.getElementById(MMW02);			this.GetHeadLayer = function(){ return _headLayer;};
	var _frontLayer = document.getElementById(MMW03);			this.GetFrontLayer = function(){ return _frontLayer;};
	var _tdCaption = document.getElementById(MMW04);			this.Caption = function(){ if(arguments.length == 0) return _tdCaption.innerHTML; _tdCaption.innerHTML = arguments[0]; };
	var _tdGalleryScroll = document.getElementById(MMW05);		this.GetGalleryScrollHolder = function() { return _tdGalleryScroll;};
	var _tdGalleryPosition = document.getElementById(MMW06);	this.GetGalleryPositionHolder = function() { return _tdGalleryPosition;};
	var _btnClose = document.getElementById(MMW07);				this.GetCloseButton = function(){ return _btnClose;};
	var _iframe = document.getElementById(MMW08);				this.GetIframe = function(){ return _iframe;};
	var _zoomTable = document.getElementById(MMW10);			this.GetZoomTable = function(){ return _zoomTable;};
	this.GetIframeBody = function()
	{
		var rv; 
		if (_iframe.contentDocument)
		{ 
			rv = _iframe.contentDocument;
		}
		else
		{ 
			/* IE */rv = document.frames[_iframe.id].document;
		}
		var bodies = rv.getElementsByTagName('body');
		var body = bodies[0];
		body.style.marginTop = 0;
		body.style.marginLeft = 0;
		body.style.marginBottom = 0;
		body.style.marginRight = 0;
		return body;
	}
	
	/* FADE EFFECT VARIABLES */
	var _fadeDelay;			this.FadeDelay = function () {if(arguments.length == 0) return _fadeDelay; _fadeDelay = parseInt(arguments[0]);};
	var _fadeFrameRate;		this.FadeFrameRate = function () {if(arguments.length == 0) return _fadeFrameRate; _fadeFrameRate = parseInt(arguments[0]);};
	var _startOpacity;		this.StartOpacity = function () {if(arguments.length == 0) return _startOpacity; _startOpacity = parseInt(arguments[0]);};
	var _finishOpacity;		this.FinishOpacity = function () {if(arguments.length == 0) return _finishOpacity; _finishOpacity = parseInt(arguments[0]);};
	var _isFading = false;	this.IsFading = function() {if(arguments.length == 0) return _isFading; _isFading = arguments[0];};
	
	var _backLayerOpacity;			this.BackLayerOpacity = function() { if(arguments.length == 0) return _backLayerOpacity; _backLayerOpacity = parseInt(arguments[0]); };
	var _frontLayerOpacity;			this.FrontLayerOpacity = function() { if(arguments.length == 0) return _frontLayerOpacity; _frontLayerOpacity = parseInt(arguments[0]); };
	var _unhandledContentLoadDelay;	this.UnhandledContentLoadDelay = function() { if(arguments.length == 0) return _unhandledContentLoadDelay; _unhandledContentLoadDelay = parseInt(arguments[0]); };
	
	var _activeGallery;			this.ActiveGallery = function() {if(arguments.length == 0) return _activeGallery; _activeGallery = arguments[0];};
	var _activeGalleryIndex;	this.ActiveGalleryIndex = function() {if(arguments.length == 0) return _activeGalleryIndex; _activeGalleryIndex = arguments[0];};
	
	var _orgWidth;				this.OrgWidth = function() {if(arguments.length == 0) return _orgWidth; _orgWidth = arguments[0];};
	var _offTop;				this.HeaderOffsetTop = function() {if(arguments.length == 0) return _offTop; _offTop = arguments[0];};
	var _scrollTop;				this.PageOffsetTop = function() {if(arguments.length == 0) return _scrollTop; _scrollTop = arguments[0];};
	var _scrollHandler;			this.ScrollHandler = function() {if(arguments.length == 0) return _scrollHandler; _scrollHandler = arguments[0];};
	
	/* DEFAULT INITIALIZING */
	_backLayer.style.top = '0px';
	_backLayer.style.left = '0px';
	
	this.FadeOpacity = function(elem, closeElement)
	{
 	this.IsFading(true);
 	if((closeElement && (_finishOpacity > _startOpacity)) || (!closeElement && (_finishOpacity < _startOpacity)))
 	{
 		var tmp = _startOpacity; 
 		_startOpacity = _finishOpacity; 
 		_finishOpacity = tmp;
 	}
 	var steps = Math.ceil(_fadeFrameRate * (_fadeDelay / 1000)); 
 	var delta = (_finishOpacity - _startOpacity) / steps;
 	if(!closeElement && elem.style.display == 'none')
 	{
 		this.SetOpacity(elem,_startOpacity);
 		elem.style.display = 'block';
 	}
 	this.FadeOpacityStep(elem, 0, steps, delta, (_fadeDelay / steps), closeElement, _finishOpacity == 100);
	};// FadeOpacity
	this.FadeOpacityStep = function(elem, stepNum, steps, delta, timePerStep, closeElement, eliminateFilter)
	{
		this.SetOpacity(elem, Math.round(parseInt(_startOpacity) + (delta * stepNum)));
		if (stepNum < steps)
		{
			var me = this;
			setTimeout(function() { me.FadeOpacityStep(elem,stepNum+1,steps,delta,timePerStep,closeElement, eliminateFilter); }, timePerStep);
		}
		else
		{
			if (eliminateFilter)
				elem.style.filter = null;
			this.IsFading(false);
			if(closeElement)
			{
				elem.style.display='none';
			}
		}
	};// FadeOpacityStep
	this.SetOpacity = function(elem, opacityAsInt){var opacityAsDecimal = opacityAsInt;if (opacityAsInt > 100) opacityAsInt = opacityAsDecimal = 100; else if (opacityAsInt < 0) opacityAsInt = opacityAsDecimal = 0; opacityAsDecimal /= 100; if (opacityAsInt < 1) opacityAsInt = 1; /* IE7 bug, text smoothing cuts out if 0 */elem.style.opacity = opacityAsDecimal;elem.style.MozOpacity = opacityAsDecimal;elem.style.filter  = 'alpha(opacity=' + opacityAsInt + ')';};// SetOpacity
	this.AppendChild = function (Obj,Child){if(Child.outerHTML) {Obj.innerHTML = Child.outerHTML;} else {Obj.appendChild(Child);}};
	this.Resize = function(width, height, caption, value, isURL, isClosable, isFetchedOut)
	{
		var bodyheight = window.innerHeight?window.innerHeight:this.GetBodyElement().clientHeight; 
		bodyheight = bodyheight > this.GetBodyElement().offsetHeight?bodyheight:this.GetBodyElement().offsetHeight; 
		/* kills safari bug */
		this.GetBackLayer().style.width = this.GetBodyElement().clientWidth + 'px';
		this.GetBackLayer().style.height = (this.GetBodyElement().scrollTop + bodyheight) + 'px';
		try
		{
			this.GetFrontLayer().style.left = (this.GetBodyElement().clientWidth - eval(this.GetFrontLayer().style.width.replace('px',''))) / 2 + 'px';
			this.GetFrontLayer().style.top = '0px'; // (this.GetBodyElement().scrollTop + (bodyheight - eval(this.GetFrontLayer().style.height.replace('px',''))) / 2) + 'px';
		}catch(err){}
	};
	this.PreventScroll = function() 
	{ 
		if(me.PageOffsetTop() != me.GetBodyElement().scrollTop)
		{
			if(typeof(me.PageOffsetTop()) != 'undefined')
				window.scrollTo(0,me.PageOffsetTop());
		}
		return false; 
	};
	this.ShowBackLayer = function()
	{
		if(this.IsFading())
		{
			var me = this;
			setTimeout(function(){ me.ShowBackLayer(); },10);
			return;
		}
		/*this.GetBodyElement().style.overflowX=this.GetBodyElement().style.overflowY=this.GetBodyElement().style.overflow='hidden';*/
		this.GetBackLayer().style.width = this.GetBodyElement().clientWidth + 'px';
		var bodyheight = window.innerHeight?window.innerHeight:this.GetBodyElement().clientHeight; 
		bodyheight = bodyheight > this.GetBodyElement().offsetHeight?bodyheight:this.GetBodyElement().offsetHeight;
		/* kills safari bug */
		this.GetBackLayer().style.height = (this.GetBodyElement().scrollTop + bodyheight) + 'px';
		this.FinishOpacity(this.BackLayerOpacity());
		this.StartOpacity(0);
		this.FadeOpacity(this.GetBackLayer(), false);
	};
	this.HideBackLayer = function(){/*if(this.IsFading()){var me = this;setTimeout(function(){ me.HideBackLayer(); },10);return;}*/this.FinishOpacity (0);this.StartOpacity(this.BackLayerOpacity());this.FadeOpacity(this.GetBackLayer(), true);/*this.GetBodyElement().style.overflowX=this.GetBodyElement().style.overflowY=this.GetBodyElement().style.overflow='auto';*/};
	this.ShowHeadLayer = function()
	{
		if(this.IsFading())
		{
			var me = this;
			setTimeout(function(){ me.ShowHeadLayer(); },10);
			return;
		}
		var hl = this.GetHeadLayer();
		hl.style.display = 'block';
		var scrOfY = 0;
		if( typeof( window.pageYOffset ) == 'number' ) scrOfY = window.pageYOffset;
		else if( document.body && document.body.scrollTop ) scrOfY = document.body.scrollTop;
		else if( document.documentElement && document.documentElement.scrollTop ) scrOfY = document.documentElement.scrollTop;
		hl.style.top = (this.HeaderOffsetTop() + scrOfY) + 'px';
	};
	this.HideHeadLayer = function(){/*if(this.IsFading()){var me = this;setTimeout(function(){ me.HideHeadLayer(); },10);return;}*/this.GetHeadLayer().style.display = 'none';};
	this.ShowFrontLayer = function(width, height, caption, value, isURL, isClosable, isFetchedOut)
	{
		//wait while fading is finished
		if(this.IsFading())
		{
			var me = this;
			setTimeout(function(){ me.ShowFrontLayer(width, height, caption, value, isURL, isClosable, isFetchedOut); },10);
			return; // if fading is in progress then exit function
		}
		/////////////////////////////////////
		//small screen solution
		var bodyElement = this.GetBodyElement();
		var bodyheight = window.innerHeight?window.innerHeight:bodyElement.clientHeight; /* kills safari bug */
		var elHeight = eval(this.GetHeadLayer().style.height.replace('px',''));
		if(elHeight == null)
		{
			if(this.GetHeadLayer().currentStyle)
				elHeight = this.GetHeadLayer().currentStyle.height
			else
				if ( document.defaultView.getComputedStyle ) 
				{
					elHeight = document.defaultView.getComputedStyle(this.GetHeadLayer(),'') .height
				}
		}
		elHeight = eval(elHeight.replace('px',''));
		var availHeight = bodyheight - this.HeaderOffsetTop() - elHeight;
		availHeight	= availHeight - (bodyheight - availHeight) - elHeight;
		if(height > availHeight)
		{
			var delta = (availHeight*100/height);
			width = (width * delta / 100);
			height = availHeight;
		}
		/////////////////////////////////////
		this.DisplayFronLayer(width,height,this.GetFrontLayer().style.width == '');
		
		var ifrPopUp = this.GetIframe();
		//ifrPopUp.src = '';
		var ifrPopUpBody = this.GetIframeBody();
		this.Caption(caption);
		// these event handlers only work if value is url
		var me = this;
		//if(ifrPopUp.addEventListener)
		//	ifrPopUp.addEventListener('load',function(){ me.ShowContent(eval(me.GetInstance()), width, height); },false)
		//else
		//	if(ifrPopUp.attachEvent)
		//	{
		//		ifrPopUp.attachEvent('onload',function(){ me.ShowContent(eval(me.GetInstance()), width, height); });
		//	}
		this.OrgWidth(width);
		this.SetOpacity(ifrPopUp,0);
		if(isURL)
		{
			ifrPopUp.src = value;
		}
		else
		{
		
			ifrPopUpBody.style.overflow = 'hidden';
			ifrPopUpBody.style.marginTop = '0px';
			ifrPopUpBody.style.marginRight = '0px';
			ifrPopUpBody.style.marginBottom = '0px';
			ifrPopUpBody.style.marginLeft = '0px';
		
			var div = document.createElement('div');
			div.style.width = '100%';
			var re = /^.+\.((jpg)|(gif)|(jpeg)|(bmp)|(gfif)|(tiff)|(tif))$/i;
			var m = re.exec(value);
			if(m!=null)
			{
				value = '<img alt=\'\' src=\'' + value + '\' style=\'width:' + width + 'px; height:' + height + 'px;\' />';
			}
			div.innerHTML = value;
		
			ifrPopUpBody.innerHTML = '';
			this.AppendChild(ifrPopUpBody,div);
		
		
		}
		setTimeout(function(){ me.ShowContent(eval(me.GetInstance()), width, height); },this.UnhandledContentLoadDelay());
	}

	this.HideFrontLayer = function(){this.GetFrontLayer().style.display = 'none';};//{this.FinishOpacity (0);this.StartOpacity(this.BackLayerOpacity());this.FadeOpacity(this.GetFrontLayer(), true);this.GetIframe().src = '';}
	this.ShowContent = function(sender, width, height)
	{
		sender.DisplayFronLayer(width, height, true);
		var ifrPopUp = sender.GetIframe();
		ifrPopUp.width = width + 'px';
		ifrPopUp.height = height + 'px';
		
		sender.FinishOpacity (sender.FrontLayerOpacity());
		sender.StartOpacity (0);
		sender.FadeOpacity(sender.GetIframe(),false);
	};
	this.DisplayFronLayer = function(width,height,enableResize)
	{
		var divFront = this.GetFrontLayer();
		if(enableResize)
		{
			this.GetIframe().style.width = width + 'px';
			this.GetIframe().style.height = height + 'px';
			divFront.style.width = width + 'px';
			divFront.style.height = height + 'px';
			this.PositionFrontLayer();
		}
		divFront.style.display = 'block';
		this.SetOpacity(divFront, this.FrontLayerOpacity());
	};
	this.PositionFrontLayer = function()
	{
		var bodyElement = this.GetBodyElement();
		var width = parseInt(this.GetFrontLayer().style.width.replace('px',''));
		var height = parseInt(this.GetFrontLayer().style.height.replace('px',''));
		this.GetFrontLayer().style.left = (bodyElement.clientWidth - width) / 2 + 'px';
		var bodyhight = window.innerHeight?window.innerHeight:bodyElement.clientHeight; /* kills safari bug */
		this.GetFrontLayer().style.top =  (bodyElement.scrollTop + (bodyhight - height) / 2) + 'px';
	};
	this.ShowGalleryItem = function()
	{
		this.ClearHFloat();
		var galItem = this.ActiveGallery()[this.ActiveGalleryIndex()];
		/* var regex = /'/g; .replace(regex,'\'') */
		this.GetGalleryPositionHolder().innerHTML = (this.ActiveGalleryIndex() + 1)+ ' / ' + this.ActiveGallery().length;
		this.ShowFrontLayer(galItem.Width(), galItem.Height(), galItem.Caption(), galItem.Content(), galItem.IsURL(), true, true);
	};
	var _oldOnResize = null;		this.OldOnResize = function(){ if(arguments.length == 0) return _oldOnResize; _oldOnResize = arguments[0]; };
	this.PropagateZoom = function (sender, factor)
	{
		var hFactor = 0;
		var w = 0;
		var h = 0;
		if(sender.style.width)
		{
			if(sender.style.width.indexOf('px') != -1)
			{
				w = parseInt(sender.style.width.replace('px',''));
			}
		}
		if(sender.style.height)
		{
			if(sender.style.height.indexOf('px') != -1)
			{
				h = sender.getAttribute('hFloat');
				if (h==null || h=='NaN' || h=='' || h=='undefined') h = parseInt(sender.style.height.replace('px',''));
				else h = parseFloat(h);
			}
		}
		if((w + factor)>30 && (h + factor) > 30)
		{
			try
			{
				hFactor = factor * 100/ w;
				sender.style.width = (w + factor) + 'px';
				hFactor = h * hFactor / 100;
				sender.setAttribute('hFloat',(h + hFactor) + '');
				sender.style.height = (h + hFactor) + 'px';
			}
			catch(err)
			{
			}
		}
		var me = this;
		for(var i = 0; i < sender.childNodes.length; i++)
		{
			me.PropagateZoom(sender.childNodes[i],factor);
		}
	};
	this.UnZoom = function()
	{
		this.Zoom(this.OrgWidth() - parseInt(this.GetFrontLayer().style.width.replace('px','')), false);
	};
	this.StopZoom = function()
	{
		clearTimeout(this.loopzoomID);
	};
	this.ClearHFloat = function()
	{
		this.GetFrontLayer().setAttribute('hFloat',null);
		this.GetIframe().setAttribute('hFloat',null);
	};
}// FINISH MMWindowClass
MMWindowClass.prototype.PopUp = function(width, height, caption, value, isURL, isClosable, isFetchedOut, isZoomable, galleryItems, galleryIndex)
{
	var me = this;
	this.ClearHFloat();
	if(!me.OldOnResize(window.onresize)) 
		window.onresize = function() 
		{
			me.Resize(width, height, isClosable);
		};
	else
		window.onresize = function()
		{
			me.OldOnResize();
			me.Resize();
		};
	me.PageOffsetTop(this.GetBodyElement().scrollTop);
	this.ScrollHandler(setInterval(me.PreventScroll,10));
	if(typeof(width) == 'undefined') width = 640;
	if(typeof(height) == 'undefined') height = 480;
	if(typeof(value) == 'undefined' && typeof(galleryItems) == 'undefined')
	{
			value = '<h1 style=\'font-size:36; color:red; font-weight:bold;\'>Suck my dick!</h1>';
			isURL = false; 
			isClosable = false; 
			isFetchedOut = true;
			width = 640;
			height = 480;
	}
	if(typeof(isURL) == 'undefined') isURL = false;
	if(typeof(isClosable) == 'undefined') isClosable = true;
	if(typeof(isFetchedOut) == 'undefined') isFetchedOut = true;
	if(typeof(isZoomable) == 'undefined') isZoomable = true;
	if(typeof(galleryItems) == 'undefined') galleryItems = null;
	if(typeof(galleryIndex) == 'undefined') galleryIndex = 0;
	this.ShowBackLayer();
	if(galleryItems == null || galleryItems.length == 0)
	{
		this.GetGalleryScrollHolder().style.visibility = 'hidden';
		this.ShowFrontLayer(width, height, caption, value, isURL, isClosable, isFetchedOut);
	}
	else
	{
		this.GetGalleryScrollHolder().style.visibility = 'visible';
		this.ActiveGallery(galleryItems);
		this.ActiveGalleryIndex(galleryIndex);
		this.ShowGalleryItem();
	}
	this.GetZoomTable().style.display = isZoomable?(window.pageYOffset?'table':'block'):'none';
	this.ShowHeadLayer();
};
MMWindowClass.prototype.ClosePopUp = function()
{
	this.HideBackLayer();
	this.HideFrontLayer();
	this.HideHeadLayer();
	window.onresize = this.OldOnResize();
	clearInterval(this.ScrollHandler());
};
MMWindowClass.prototype.ScrollGallery = function (factor)
{
	if((this.ActiveGalleryIndex() + factor) < 0)
	{
		this.ActiveGalleryIndex(this.ActiveGallery().length);
	}
	if((this.ActiveGalleryIndex() + factor) >= this.ActiveGallery().length)
	{
		this.ActiveGalleryIndex(-1);
	}
	
	this.GetIframe().src = '';
	
	this.ActiveGalleryIndex(this.ActiveGalleryIndex() + factor);
	var me = this;
	setTimeout(function(){me.ShowGalleryItem();},50);
};
MMWindowClass.prototype.Zoom = function (factor, loop)
{
	try
	{
		var ibody = this.GetIframeBody();
		this.PropagateZoom(ibody, factor);
	}
	catch(err)
	{
	}
	this.PropagateZoom(this.GetFrontLayer(),factor);
	this.PositionFrontLayer();
	if(loop)
	{
		var me = this;
		this.loopzoomID = setTimeout(function(){me.Zoom(factor, loop);}, 50);
	}
};
function MMWindowGalleryItemClass (width, height, caption, content, isUrl)
{var _height = height;	this.Height = function() { return _height;};
var _caption = caption;	this.Caption = function() { return _caption;};
var _content = content;	this.Content = function() { return _content;};
var _width = width;		this.Width = function() { return _width;};
var _isUrl = isUrl;		this.IsURL = function() { return _isUrl;};};

