	iGW_Class = function(code, data, preUrl)
	{
		var that = this;
		
		var _processData = function(data)
		{
			if(!data.thmb)
				data.thmb = (data.thumbnails && data.thumbnails.ST)?data.thumbnails.ST:that.processing;
			if(!data.VSrc)
				data.VSrc = (data.thumbnails && data.thumbnails.custom)?data.thumbnails.custom:(data.src?data.src:that.processing);
			return data;
		};
		var _hideImage = function()
		{
			if(that.cursrc)
			{
				that.Pimgbox.find("img").appendTo(that.Pbuffer);
				that.cursrc = null;
			}
			if(that.StockDom)
				that.StockDom.html('').remove();
			that.Ploader.css("display", "none");
		};
		var _showStock = function(Data, Num)
		{
			_hideImage();
			if(!that.StockDom)
				that.StockDom = iG$j('<div></div>').css('text-align', 'center');
			if(Data.StockMode == "Picapp")
			{
				var Width = that.Dwidth*1-5;
				var scale = function()
				{
					if(this.width > Width/1.2)
						this.width = Width;
				};
				var Tip = that._sanitize(Data.title) + ' Content &copy; 2008 ' + that._sanitize(Data.StockAdd);
				var Img = iG$j('<img title="' + Tip + '" src="' + Data.src + '"/>').load( scale ).appendTo(that.StockDom);
				var AdsUrl = 'http://zen.picapp.com/ads/psads/default.aspx?AdSize=' + (Width <= 468?1:2) + '&imageId=' + Data.StockParam;
				iG$j('<div>No endorsement implied</div>').css({"text-align": "right", padding: "4px 8px 0 0"}).appendTo(that.StockDom);
				var AdsHtml = '<div style="text-align:center; margin-top:15px;" align="center">';
				AdsHtml+= '<iframe frameborder="0"" width="' + ((Width <= 468?234:468) + 3) + '" height="68" src="' + AdsUrl + '">';
				AdsHtml+= '</iframe></div>';
				var Iframe = iG$j(AdsHtml).appendTo(that.StockDom);
				Data.cr = '&copy; <a href="http://www.picapp.com/" rel="nofollow">PicApp</a>';
			}
			if(Data.StockMode == "Fotoglif")
			{
				that.Ploader.css("display", "block");
				var Width = that.Dwidth*1-5;
				var Size = 'large';
				if(Width <= 468*1.3)
					var Size = 'medium';
				if(Width <= 234*1.3)
					var Size = 'small';
				var Url = path_to_home + '/fotoglif.php?size=' + Size + '&uid=' + Data.StockParam;
				var Iframe = iG$j('<iframe src="' + Url + '" frameborder="0" width="100" height="1"></iframe>');
				Iframe.css("background", "#F7F7F7").appendTo(that.StockDom);
				window.setTimeout( function(){
					var Win = Iframe.get(0).contentWindow;
					var Interval = window.setInterval( function(){
						var W = Win.document.documentElement.scrollWidth?Win.document.documentElement.scrollWidth:Win.document.body.scrollWidth;
						var H = Win.document.documentElement.scrollHeight?Win.document.documentElement.scrollHeight:Win.document.body.scrollHeight;
						Iframe.width(W + 10);
						Iframe.height(H + 10);
						if(Iframe.height() > 10)
							that.Ploader.css("display", "none");
					}, 1000);
					Win.onload = function(){
						Iframe.width(Win.document.body.scrollWidth + 20);
						Iframe.height(Win.document.body.scrollHeight + 20);
						window.clearInterval(Interval);
					};
				}, 300 );
			}
			that.StockDom.appendTo(that.Pimgbox);
			return Data;
		};
		var _showRegular = function(Data, Num)
		{
			_hideImage();
			var src = unescape(Data.VSrc);
			var imgfilename = src.split("/").pop().split(".")[0]
			var srcid = imgfilename.replace("-", "");
			var imgCleanUrl = imgfilename.split("-").pop();
			that.cursrc = src;
			var onimload = function()
			{
				var srcid = this.src.split("/").pop().split(".")[0].replace("-", "");
				that.shownIms[srcid] = iG$j(this).appendTo(that.Pbuffer);
				var TW = (that.Mode.Inline?that.Dwidth-2:600);
				if(this.width>TW || this.height>500)
				{
					var w = this.width;
					var h = this.height;
					var scale = Math.max(w/TW, h/500);
					this.width = Math.ceil(w/scale);
					this.height = Math.ceil(h/scale);
				}
				that.loadingIms[srcid] = false;
				that.Ploader.css("display", "none");
				if(that.cursrc == this.src)
				{
					that.Pimgbox.find("img").appendTo(that.Pbuffer);
					that.shownIms[srcid].appendTo(that.Pimgbox);
				}
			};
			if(!that.shownIms[srcid])
			{
				that.Ploader.css("display", "block");
				if(!that.loadingIms[srcid])
				{
					that.loadingIms[srcid] = true;
					var img = iG$j("<img/>").attr("title", that._sanitize(Data.title));
					img.load(onimload).appendTo(that.Pbuffer).attr("src", src);
				}
			}
			else
				iG$j(that.shownIms[srcid]).appendTo(that.Pimgbox);
			if(that.doNextPreload)
			{
				var ndata = that.data.ims[Num+1];
				if(ndata && !ndata.StockMode)
				{
					var nsrc = unescape(ndata.VSrc);
					var nsrcid = src.split("/").pop().split(".")[0].replace("-", "");
					if(!that.shownIms[nsrcid] && !that.loadingIms[nsrcid])
					{
						that.loadingIms[nsrcid] = true;
						var nimg = iG$j("<img/>").attr("title", that._sanitize(ndata.title));
						nimg.load(onimload).attr("src", nsrc);
					}
				}
			}
			return Data;
		};
		var _positionPopup = function()
		{
			if(!that.Popened)
			{
				var s = iG$j.winSize(true);
				var ps = {x: that.popup.width(), y: that.popup.height()};
		        var wt = (s.sz.y - ps.y)/2+s.scr.y;
		        var wl = (s.sz.x - ps.x)/2+s.scr.x;
				
				that.popup.css({ top: wt, left: wl });
				if(that.showeffects)
					that.popup.fadeIn(100);
				else
					that.popup.css("display", "block");
				var PH = that.Pimgbox.height();
				if(PH<50)
					that.popup.css({ top: wt-300 });
				that.Popened = true;
				iGW_GlobalCover.show();
			}			
		};
		
		this.init = function()
		{
			if(this.emptycoded)
				var content = "No Gallery code provided. Gallery creation aborted.";
			else
			{
				var Prim = "Blog Gallery";
				var Sec = "<a class='snap_nopreview' href='http://www.picturesurf.org'>Picturesurf</a></div>";
				var domain = top.location.href.replace('http://', '').split('/')[0];
				if(domain.search("techcrunch.com") != -1 || domain.search("crunchgear.com") != -1 || domain.search("mobilecrunch.com") != -1)
				{
					Prim = "Photo Gallery";
					Sec =  "Picturesurf";
				}
				var atitle = "Click here to get your own image gallery! (free)";
				var content = "<div class='ig-header'><h1 class='ig-title'></h1>";
				content += "<div class='ig-pager'>";
				content += "<a href='#' class='ig-clink'>Previous</a><a href='#' class='ig-clink'>Next</a>";
				content += "</div></div>";
				content += "<div class='ig-display'><div class='ig-list'></div></div>";
				if(typeof(G_GalSpecialV) == 'undefined')
				{
					content += "<div class='ig-footer'>";
					content += "<div class='ig-powered-by'>";
					content += "<a class='snap_nopreview' href='http://www.picturesurf.org/gallery' title='"+atitle+"'>" + Prim + "</a> by ";
					content += Sec;
					content += "</div>";
				}
				this.attemptCreate(); //start contineus create attempts
				iG$j(document).ready( function()
				{
					that.create();
					that.IsReady = true;
				}); //place ready event just in case attemptCreate will fail
			}
			this.loadCustomCSS();
			document.write("<div id='Gallery_"+this.code+"' class='gallery-widget'>"+content+"</div>");
		};
		
		this.attemptCreate = function()
		{
			if(this.isloaded)
				return;
			try
			{
				this.create();
			}
			catch(e)
			{
				window.setTimeout( function(){ that.attemptCreate() }, 350);
			}
		};
		
		this.create = function()
		{
			if(this.isloaded)
				return;
			this.main = iG$j("#Gallery_"+this.code);
			if(this.main.length === 0)
				throw("DOM is not ready");
			this.initDisplay();
			this.isloaded = true;
		};

		this.initDisplay = function()
		{
			if(!this.main.find(".ig-display").length)
				return;
			if(this.display && this.lister)
			{
				this.redrawDisplay();
				return;
			}
			this.display = this.main.find(".ig-display");
			this.lister = this.main.find(".ig-list");
			this.header = this.main.find(".ig-header");
			this.title = this.main.find(".ig-title");
			this.pager = this.main.find(".ig-pager");
			this.nextP = this.pager.find(":last-child");
			this.prevP = this.pager.find(":first-child");
			this.nextP.click(function(){ if(!iG$j.hasCls(this, "disabled")) { that.showPage(that.nowOnPage+1) } return false; });
			this.prevP.click(function(){ if(!iG$j.hasCls(this, "disabled")) { that.showPage(that.nowOnPage-1) } return false; });
			this.list = this.main.find(".ig-list");
			this.footer = this.main.find(".ig-footer");
			if (this.data.title)
			{
				this.title.html(this._sanitize(this.data.title));
				this.title.css("display", "");
			}
			else 
				this.title.css("display", "none");
			this.applyCustomization(this.data.data);
			//update sizes
			this.Dwidth = this.cols*84;
			this.Dheight = this.rows*88-3;
			this.display.width(this.Dwidth).height(this.Dheight);
			var mainwidth = this.Dwidth;
			this.main.width(mainwidth);
			if(!this.data.ims)
				this.list.html(this.msgs.noimages);
			else
			{
				this.totalpages = Math.ceil(this.data.ims.length/this.perpage);
				this.lister.width((this.Dwidth+2)*this.totalpages).height(this.Dheight);
				if(window.G_PSGallerySelectImageNum > 0)
					var page = Math.ceil((G_PSGallerySelectImageNum*1+1)/this.perpage)-1;
				else
					var page = 0;
				this.showPage(page);
			}
			if(this.data.title)
				this.ellipseTitle();
			this.preloadInterfaceImages();
			if(this.Mode.Inline)
				this.Iopen(0);
		};

		this.ellipseTitle = function()
		{
			var that = this;
			var W = this.main.width();
			if(W<2 || this.title.width() == this.header.width()) //if unable to get width (probably gallery is not displayed yet)
			{
				var that = this;
				this.delay = window.setTimeout( function(){ that.ellipseTitle() }, 300); 
				return;				
			}
			var delta = this.title.width() - (this.header.width() - this.pager.width() - 10);
			if(delta > 0)
			{
				var text = this.title.text().replace(/\.\.\.$/, "");
				var del = Math.round( (3/4)*( delta/this.title.width() )*(text.length) );
				del = del<1?1:del;
				this.title.text( text.substr(0, text.length-del)+"..." );
				this.delay = window.setTimeout( function(){ that.ellipseTitle() }, 50);
			}
		};

		this.redrawDisplay = function(cssdata)
		{
			if(this.data.title)
			{
				this.title.html(this._sanitize(this.data.title));
				this.title.css("display", "");
			}
			else
				this.title.css("display","none");
			if(this.data.data)
				this.applyCustomization(this.data.data, cssdata);
			this.Dwidth = this.cols*84;
			this.PreDheight = this.Dheight;
			this.Dheight = this.rows*88-3;
			this.display.width(this.Dwidth).height(this.Dheight);
			this.main.width(this.Dwidth);
			iG$j.each(this.pages, function(i, pg){ pg.remove(); });
			this.pages = [];
			var num = this.nowOnPage;
//TODO find out why preview crashes when we add image and redrawDisplay gets called 2 with short delay
			if(!parseInt(num))
				num = 0;
			this.nowOnPage = "no";
			if(!this.data.ims)
				this.list.html(this.msgs.noimages);
			else
			{
				this.totalpages = Math.ceil(this.data.ims.length/this.perpage);
				this.lister.width((this.Dwidth+2)*this.totalpages).height(this.Dheight);
				this.showPage(num);
			}
			if(this.PreDheight && this.PreDheight != this.Dheight && typeof(this.onRowsUp)=="function")
				this.onRowsUp();
			this.ellipseTitle();
		};
		
		this.preloadInterfaceImages = function()
		{
			this.spriteVer = new Image();
			this.spriteVer.src = path_to_home+"/gallery-spr-ver.png";
			this.spriteHor = new Image();
			this.spriteHor.src = path_to_home+"/gallery-spr-hor.png";
		};
		
		this.applyCustomization = function(data, cssdata)
		{
			if(data.thar)
			{
				var parse = data.thar.split("x");
				this.rows = parse[0];
				if(window.G_PS_GallerySettings && window.G_PS_GallerySettings['Height']) //override the height
					this.rows = window.G_PS_GallerySettings['Height'];
				this.cols = parse[1];
				//Do not expand one page gallery with empty rows
				if(this.data.ims.length < this.rows*this.cols)
					this.rows = Math.ceil(this.data.ims.length/this.cols);
				this.perpage = this.rows*this.cols;
			}
			//if(cssdata)
				//this.custcss.href = path_to_home+'/gallery_css.php?gallery='+this.galid+'&divid='+this.code+'&data='+cssdata;
		};
		
		this.loadCustomCSS = function()
		{
			this.custcss = document.createElement('link');
			this.topcust = document.createElement('link');
			this.topcust.type = this.custcss.type = 'text/css';
			this.topcust.rel = this.custcss.rel = 'stylesheet';
			this.topcust.href = this.custcss.href = path_to_home+'/gallery_css.php?gallery='+this.galid+'&divid='+this.code+'&path='+escape(this.DataPath);
			this.topcust.media = this.custcss.media = 'screen';
			document.getElementsByTagName("head")[0].appendChild(this.custcss);
		};
		
		this.showPage = function(num)
		{
			num = parseInt(num);
			if(!this.pages[num])
				this.buildPage(num);
			if(this.nowOnPage == num)
				return;
			if(this.showeffects && iG$j.chk(this.nowOnPage))
				this._slidePages(num, this.nowOnPage);
			else
				this.lister.css("left", -num*(this.Dwidth+(iG$j.browser.msie && iG$j.browser.version == '6.0'?2:1)));
			this.nowOnPage = num;
			if(num == this.totalpages-1 || this.totalpages==0)
				this.nextP.addClass("disabled");
			else
				this.nextP.removeClass("disabled");
			if(num == 0)
				this.prevP.addClass("disabled");
			else
				this.prevP.removeClass("disabled");
			if(this.prevP.hasClass("disabled") && this.nextP.hasClass("disabled"))
				this.pager.css("display", "none");
			else
				this.pager.css("display", "block");
		};
		
		this.buildPage = function(num)
		{
			var subnum = num-1;
			if(subnum >=0 && !this.pages[subnum])
				this.buildPage(subnum);
			var st = num*this.perpage;
			var end = st+this.perpage;

			if(end > this.data.ims.length)
				end = this.data.ims.length;
			var page = iG$j('<ul class="ig-page"></ul>').appendTo(this.list).width(this.Dwidth+1);
			this.pages.push(page);
			for(var i=st; i<end; i++)
			{
				var img = this.data.ims[i];
				this.imgs.push(img);
				this.drawThumb(img, page, i);
			}
		};
		
		this.drawThumb = function(img, page, num)
		{
			if(window.G_PSGallerySelectImageNum == num)
				var isact = " ig-thumb-active";
			else
				var isact = "";
			img.Othmb = iG$j("<li class='ig-thumb"+isact+"'/>").appendTo(page);
			var href = this.ImgPreUrl?this.ImgPreUrl+(num+1):'#';
			var a = iG$j("<a rel='nofollow' title='" + this._sanitize(img.title) + "' href='" + href + "'/>").appendTo(img.Othmb);
			var s = iG$j("<span/>").appendTo(a);
			var i = iG$j("<img/>").appendTo(s);
			a.data = img;
			img = _processData(img);
			if(img.thmb.search("addimage")==-1)
				a.click(function(){ that.open(num); return false; });
			if(iG$j.inArray(img.thmb, this.loadedThmbs)==-1)
			{
				var loadico = iG$j("<div class='ig-thumb-loadico'>").appendTo(img.Othmb);
				i.load(function(){ loadico.remove(); that.loadedThmbs.push(this.src) });
			}
			i.attr("src", img.thmb);
		};
		
		this._slidePages = function(to, from)
		{
			this.lister.animate({left: -to*(this.Dwidth+(iG$j.browser.msie && iG$j.browser.version == '6.0'?2:1))}, {duration: 400, easing: "swing"} );
		};
		
		this._sanitize = function(value)
		{
			return unescape(value+"").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&rdquo;")
		}
		
		/*
		 * Pop-up section starts here
		*/
		this._constrPopUp = function()
		{
	        this.popup = iG$j('<div class="gallery-widget-popup" id="Gallery_'+this.code+'-popup"></div>').width(this.PDefW);
			var atitle = "Click here to get your own image gallery! (free)";
			var html = '<h2 class="ig-pp-title"></h2>';
			html+= '<div class="ig-pp-headctrls">';
			html+= '<span class="ig-pp-imsinfo">Image <span class="ig-pp-simgcur"></span> of <span class="ig-pp-simgall"></span></span>';
			html+= '<div class="ig-pager">';
			html+= '<a href="#" class="ig-clink">Previous</a><a href="#" class="ig-clink">Next</a>';
			html+= '</div></div>';
			html+= '<div class="ig-pp-greypart">';
			html+= '<table width="100%" cellpadding=0 cellspacing=0><tr><td valign="middle" align="center" class="ig-pp-imagebox"></td></tr></table>';
			html+= '<div class="ig-pp-copyright"></div><div class="ig-pp-descr"></div><div class="ig-pp-footer">';
			html+= '<div class="ig-powered-by">';
			html += "<a class='snap_nopreview' href='http://www.picturesurf.org/gallery' title='"+atitle+"'>Blog Gallery</a> by ";
			html += "<a class='snap_nopreview' href='http://www.picturesurf.org'>Picturesurf</a></div>";
			html+= '<a href="mailto:" class="ig-pp-email">Email</a><span class="ig-pp-dash">&nbsp; &nbsp; </span><a href="#" class="ig-pp-facebook">Facebook</a>';
			html+= '<span style="display:none"> | &nbsp;<label class="ig-pp-emblab" for="ig_'+this.code+'_embedinput">Embed:</label>';
			html+= '<input class="ig-pp-embinp" id="ig_'+this.code+'_embedinput" /></span></div>';
			html+= '</div>';
			if(!this.Mode.Inline)
			{
				html+= '<div class="ig-pp-sdw-t"></div><div class="ig-pp-sdw-r"></div><div class="ig-pp-sdw-b"></div><div class="ig-pp-sdw-l"></div>';
				html+= '<div class="ig-pp-sdw-tl"></div><div class="ig-pp-sdw-bl"></div><div class="ig-pp-sdw-br"></div>';
			}
			html+= '<div style="position:absolute;width:1px;height:1px">';
			html+= '<form class="ig-shareform" action="http://www.addthis.com/bookmark.php" target="_blank">';
			html+= '<input class="ig-shrmys" name="s" value="" type="hidden"/>';
			html+= '<input name="pub" value="Picturesurf" type="hidden"/>';
			html+= '<input name="url" value="'+unescape(this.data.link)+'" type="hidden"/>';
			html+= '<input class="ig-shrtitle" name="title" type="hidden"/>';
			html+= '<input name="lng" value="" type="hidden"/>';
			html+= '<input name="winname" value="Gallery" type="hidden"/>';
			html+= '<input name="content" value="Gallery" type="hidden"/>';
			html+= '</form></div><div class="ig-pp-bufer"></div>';
			if(!this.Mode.Inline)
				html+= '<a class="ig-pp-close" href="#close" tile="close"></a>';
	        try{this.popup.html(html).appendTo(iG$j(top.document.body));}
			catch(e){this.popup.html(html).appendTo(iG$j(document.body));}
			if(!this.Mode.Inline)
			{
		        var clb = this.popup.find(".ig-pp-close");
		        clb.click(function(){ that.Pclose(); return false; });
			}
			this.Ptitle = this.popup.find(".ig-pp-title");
			this.Pimnum = this.popup.find(".ig-pp-simgcur");
			this.Pimall = this.popup.find(".ig-pp-simgall");
			this.Pimgbox = this.popup.find(".ig-pp-imagebox");
			this.Pimg = this.Pimgbox.find("img");
			this.Pbuffer = this.popup.find(".ig-pp-bufer");
			this.Pcopyright = this.popup.find(".ig-pp-copyright");
			this.Pdescr = this.popup.find(".ig-pp-descr");
			this.Pemail = this.popup.find(".ig-pp-email");
			this.Pemail.attr("href", "mailto:?subject="+this.data.title+"&body="+this.data.link);
			this.Pfacebook = this.popup.find(".ig-pp-facebook").click(function(){ that._share("facebook") });
			this.Pembinp = this.popup.find(".ig-pp-embinp").val(unescape(this.data.embed));
			this.Ploader = iG$j('<div class="ig-pp-loader"/>').appendTo(this.Pimgbox);
			var pager = this.popup.find(".ig-pager");
			this.Pnext = pager.find(":last-child");
			this.Pprev = pager.find(":first-child");
			this.PshrForm = this.popup.find(".ig-shareform");
			this.PshrMode = this.PshrForm.find(".ig-shrmys");
			this.PshrTitle = unescape(this.PshrForm.find(".ig-shrtitle").val(this.data.title));
			this.Pnext.click(function(){ if(!iG$j.hasCls(this, "disabled")){that.open(that.picnum+1);} return false });
			this.Pprev.click(function(){ if(!iG$j.hasCls(this, "disabled")){that.open(that.picnum-1);} return false });
			this.Pimgbox.click(function()
			{
				var num = that.picnum+1;
				if(num > that.data.ims.length-1)
					num = 0;
				that.open(num);
			});
			if(!this.IsEmail)
				this.Pemail.css('display', 'none');
			if(!this.IsFB)
				this.Pfacebook.css('display', 'none');
			if(!this.IsEmail || !this.IsFB)
				this.popup.find('.ig-pp-dash').css('display', 'none');
			this.popup.click(function(e){ e.stopPropagation() });
//TO-DO check document in multiple toolkits
			if(!this.Mode.Inline)
			{
				try{var doc = top.document.documentElement;}catch(e){var doc = document.documentElement;}; 
				iG$j(doc).click(function(e){ that.Pclose() }).keyup(function(e)
				{
					if(!that.Popened)
						return;
					var num = null;
					if(e.keyCode == 37)
						var num = that.picnum-1;
					if(e.keyCode == 39)
						var num = that.picnum+1;
					if(e.keyCode == 13 || e.keyCode == 27)
						that.Pclose();
					if(num == null)
						return;
					if(num > that.data.ims.length-1)
						num = 0;
					if(num < 0)
						num = that.data.ims.length-1;
					that.open(num);
				});
			}
		};
		this._share = function(mode)
		{
			this.PshrMode.val(mode);
			this.PshrForm.submit();			
		}
		this.open = function(num)
		{
			if(this.Mode.Pages)
			{
				window.location.href = this.ImgPreUrl+(num+1);
				return;
			}
			if(this.Mode.Inline)
			{
				this.Iopen(num);
				return;
			}
			if(this.Mode.Ajax)
			{
				this.Popen(num);
				return;
			}
		};
		this.Iopen = function(num)
		{
			if(!this.popup)
			{
				this._constrPopUp();
				this.popup.find('.ig-pp-greypart').css({'padding-left': 0, 'padding-right': 0});
				this.popup.insertBefore(this.main).css({display: 'block', position: 'relative', 'width': this.Dwidth});
				this.Popened = true;
			}
			this.Popen(num);
		};
		this.Pclose = function()
		{
			if(this.showeffects)
				this.popup.fadeOut(100);
			else
				this.popup.css("display", "none");
			this.Popened = false;
			iGW_GlobalCover.hide();
		};
		this.Popen = function(num)
		{
			var Data = this.data.ims[num];
			if(!Data)
				return;
			if(this.Mode.Ajax && !this.IsReady)
			{
				iG$j(document).ready(function()
				{
					that.Popen(num);
				});
				return;
			}
			Data = _processData(Data);
			if(!this.popup)
				this._constrPopUp();
			if(Data.StockMode)
				Data = _showStock(Data, num);
			else
				Data = _showRegular(Data, num);
			if(this.Mode.Inline)
			{
				if(this.ActiveThumb)
					this.ActiveThumb.removeClass("ig-thumb-active");
				Data.Othmb.addClass("ig-thumb-active");
				this.ActiveThumb = Data.Othmb;
			}
			//fill in popup info
			this.Ptitle.html(this._sanitize(Data.title));
			this.Pimnum.html(num+1);
			this.Pimall.html(this.data.ims.length);
			this.Pdescr.html(this._sanitize(Data.descr));
			if(Data.cr)
				this.Pcopyright.html(Data.cr);
			else
				this.Pcopyright.html('&nbsp;');
			this.picnum = num;
			if(num == this.data.ims.length-1)
				this.Pnext.addClass('disabled');
			else
				this.Pnext.removeClass('disabled');
			if(num == 0)
				this.Pprev.addClass('disabled');
			else
				this.Pprev.removeClass('disabled');
			//position popup
			_positionPopup();
		};

		if(!code)
		{
			code = "";
			this.emptycoded = true;
		}
		this.galid = code;
		code+= window.iGW_list.length + '' + Math.round(Math.random()*100);
		var Gallery = null;
//TO-DO upgrade silent die to some messages
		try{ eval(data) }catch(e){ return; }
		if(!Gallery)
			return;
		this.ImgPreUrl = preUrl;
		this.DataPath = G_GalleryDataPath;
		this.data = Gallery;
		this.data.link = this.ImgPreUrl?this.ImgPreUrl.replace('image-page/', ''):top.location.href;
		this.isplugin = true;
		this.IsEmail = true;
		this.IsFB = true;
		if(window.G_PS_GallerySettings)
		{
			this.Mode = {Pages: G_PS_GallerySettings["IsPages"], Inline: G_PS_GallerySettings["IsInline"], Ajax: G_PS_GallerySettings["IsAjax"]};
			this.IsEmail = G_PS_GallerySettings["IsShowEmail"];
			this.IsFB = G_PS_GallerySettings["IsShowFB"];
			this.IsPL = G_PS_GallerySettings["IsShowPL"];
		}
		if(this.Mode.Pages && !preUrl)
			this.Mode = {Pages: false, Inline:false, Ajax: true}; //switch pages off if they are not available
		if(window.G_PS_IsPreview)
			this.Mode = {Pages: false, Inline:false, Ajax: true}; //switch to ajax when as create preview
		this.showeffects = true;
		this.doNextPreload = true;
		this.perpage = 16;
		this.rows = 4;
		this.cols = 4;
		this.code = code;
		this.PDefH = 550;
		this.PDefW = 640;
		this.maxTitleW = 600;
		this.pages = [];
		this.imgs = [];
		this.loadedThmbs = [];
		this.shownIms = [];
		this.loadingIms = [];
		this.msgs = {
			noimages: "This gallery has no images."
		}
		this.processing = "http://www.picturesurf.org/img/ST_processing.gif";
		this.init();
	};
/*
 * Utility
 */
	iGW_AllBodyCover = function()
	{
		var that = this;
		this.create = function()
		{
			var par = window;
			if(this.useBody)
				par = document.body;
	        this.par = par;
	        this.s = iG$j.winSize(true);
	        try
			{
				this.setsCov = iG$j('<iframe frameborder="0" class="'+this.frameClass+'"/>').appendTo(top.document.body);
				this.setsCovD = iG$j('<div id="setpopup_div_cov_div" class="'+this.divClass+'">').appendTo(top.document.body);
			} catch(e)
			{
				this.setsCov = iG$j('<iframe frameborder="0" class="'+this.frameClass+'"/>').appendTo(document.body);
				this.setsCovD = iG$j('<div id="setpopup_div_cov_div" class="'+this.divClass+'">').appendTo(document.body);
			}
			this.setsCov.css({opacity: 0.1, height: this.s.bsz.y, width: this.s.bsz.x, display: "none"});
			this.setsCovD.css({opacity: 0.7, height: this.s.bsz.y, width: this.s.bsz.x});
			if(this.zindex)
				this.setsCovD.css("z-index", this.zindex)
			iG$j(window).resize(function()
				{
	                if(!that.ishown)
	                    return;
	                var s = iG$j.winSize();
	                if(that.s.bsz.y ==  s.bsz.y && that.s.bsz.x ==  s.bsz.x)
	                    return;
					that.s = s;
	                that.setsCov.css('display', 'none');
	                that.setsCovD.height(s.bsz.y).width(s.bsz.x);
	                var recall = function()
	                {
	                    var s = iG$j.winSize();
	                    that.setsCov.height(s.bsz.y).width(s.bsz.x);
	                    that.setsCovD.height(s.bsz.y).width(s.bsz.x);
	                    that.setsCov.css('display', 'block');
	                    that.isset = false;
	                };
	                if(window.ie)
	                {
		                if(!that.isset)
		                {
		                	window.setTimeout(recall, 200);
	                        that.isset = true;
	               		}
	                    return;
	               	}
	                recall();
	            });
		};
		this.show = function()
		{
	        this.ishown = true;
			if(!this.setsCov)
				this.create();
				//return;
	        var s = iG$j.winSize();
	        this.setsCov.height(s.bsz.y).width(s.bsz.x);
	        this.setsCovD.height(s.bsz.y).width(s.bsz.x);
			var s = iG$j.winSize();
	        if(s.bsz.y != this.s.bsz.y || s.bsz.x != this.s.bsz.x)
	        {
	            this.setsCov.height(s.bsz.y).width(s.bsz.x);
	            this.setsCovD.height(s.bsz.y).width(s.bsz.x);
	        }
			this.setsCovD.fadeIn(100);
	        this.setsCov.css('display', 'block');
		};
		this.hide = function()
		{
			if(!this.setsCov)
				return;
			this.setsCovD.fadeOut(100);
	        this.setsCov.css('display', 'none');
	        this.ishown = false;
		};

		this.frameClass = "gallery-widget-cover-frm";
		this.divClass = "gallery-widget-cover";
		this.useBody = false;
		iG$j(window).load(function()
		{
			//that.create();
			//if(that.ishown)
				//that.show();
		});
	};
	
	
	var iG$j = jQuery.noConflict( true );
	iG$j.extend({ 
		chk: function(el) { return (el === 0 || el?true:false); },
		hasCls: function(el, cls)
		{
			if(!el.className)
				if(el[0])
					return this.hasCls(el[0]);
				else
					return false;
			else
			{
				var clss = el.className.split(" ");
				return this.inArray(cls, clss)!=-1; 
			}
		},
		winSize: function(topmost)
		{
			var s = {};
			var win = null
			try	{var test = top.location.href.toString(); win = top} catch(e){win = window};
			if (win.innerWidth)
				s.sz = {x: win.innerWidth, y: win.innerHeight};
			else if (win.document.documentElement && win.document.documentElement.clientWidth)
				s.sz = {x: win.document.documentElement.clientWidth, y: win.document.documentElement.clientHeight};
			else if (document.body)
				s.sz = {x: win.document.body.clientWidth, y: win.document.body.clientHeight};
			var srcx = win.document.documentElement.scrollWidth==win.document.documentElement.offsetWidth?s.sz.x:win.document.documentElement.scrollWidth;
			s.scrsz = {x: srcx, y: win.document.documentElement.scrollHeight};
			if( typeof( win.pageYOffset ) == 'number' ) //Safari/Netscape compliant
				s.scr = {x: win.pageXOffset, y: win.pageYOffset};
			else //FF/IE and rest
				s.scr = {x: win.document.documentElement.scrollLeft, y: win.document.documentElement.scrollTop};
			s.bsz = {x: Math.max(s.scrsz.x, s.sz.x), y: Math.max(s.scrsz.y, s.sz.y)}
			return s;
		}
	});
	iGW_GlobalCover = new iGW_AllBodyCover();
	iGW_list.push( new iGW_Class(iG_galid, iG_data, G_PS_GalleryPagePreurl) );
	
	/*
	var pageTracker = _gat._getTracker("UA-4907573-1");
	pageTracker._initData();
	pageTracker._trackPageview();
	*/
