function preview_images(areaId, imageId, images, sizes, p) {
	var wrapper = DOM.get('sbSiteWrapper');
	var bh = DHTML.getHeight(document.body), bs = document.body.scrollTop||document.documentElement.scrollTop;
	var ele, img;
	var cW = DHTML.clientWidth()-40, cH = DHTML.clientHeight()-80;
	var pub=(p)?'/publish':'';
	
	ipImg=null;
	wrapper.scrollEle = (document.body.scrollTop)?'body':'documentElement';
	images = images.split(',');
	sizes = sizes.split(',');
	for (var i=0,s,e,c=images.length;i<c;i++) {
		s = sizes[i].split('x');
		images[i] = e = { index: i, id: images[i], w: parseInt(s[0], 10), h: parseInt(s[1], 10), r: s[2] }
		e.img = new Image();
		e.img.src = '/_familyCustom/0/areas/'+areaId+pub+'/thumbnails/rev_'+e.r+'/'+e.id+'.'+e.w+'x'+e.h+'._in_orig.jpg';
		if (e.w>cW) { e.h=Math.round(e.h*cW/e.w); e.w = cW; }
		if (e.h>cH) { e.w=Math.round(e.w*cH/e.h); e.h = cH; }
		if (!ipImg&&(e.id==imageId)) { ipImg=e; }
	}
	ipImgList = images;
	
	var overlay = DOM.structure({ id:'ipOverlay', c: DHTML.Anim, s: [{ t: 'iframe', _action: 'close' }, { cn: 'ipOverlay1', _action: 'close' }], _onclick: ipClickFN, _action: 'close' });
	var mainEle = DOM.structure({ cn: 'ipOuter', id: 'ipOuter', _onclick: ipClickFN, _onmouseover: ipMouseFN, _onmouseout: ipMouseFN, s: [
									{ id: 'ipMainH', c: DHTML.Anim, r: 'main', s: [
										{ id: 'ipImageH', r: 'imgH', c: DHTML.Anim,  s: [ { t: 'img', r: 'img', _width: ipImg.w, _height: ipImg.h, _src: ipImg.img.src }]},
										{ id: 'ipCloseB', cn: 'ipb_normal', _action: 'close' },
										{ id: 'ipHLeft', cn: 'ipLeft', _action: 'previous' },{ id: 'ipHRight',cn: 'ipRight', _action: 'next' },
										{ id: 'ipButtonBar', s: [{ id: 'ipReport' }, { id: 'ipNextB', cn: 'ipb_normal', _action: 'next'},{ id: 'ipPrevB', cn: 'ipb_normal', _action: 'previous'}] }
									] }
								] })

	overlay.O(0);
	mainEle.imgH.O(0);
	if (DHTML.ie) {
		document.documentElement.className+=' ipBody';
		document.body.className+=' ipBody';
		wrapper.scrollTop=bs;
	} else {
		overlay.style.position=mainEle.style.position='fixed';
	}
	document.body.appendChild(overlay);
	document.body.appendChild(mainEle);
	
	overlay.animate({ O: 70}, 200, 0, ipResizeMain);
}

function preview_images_new(areaId, thumbId, imageId, images, sizes, p, m) {
	var wrapper = DOM.get('sbSiteWrapper');
	var bh = DHTML.getHeight(document.body), bs = document.body.scrollTop||document.documentElement.scrollTop;
	var ele, img;
	var cW = Math.min(m, DHTML.clientWidth()-40), cH = Math.min(m, DHTML.clientHeight()-80);
	var pub=(p)?'/publish':'';
	
	ipImg=null;
	wrapper.scrollEle = (document.body.scrollTop)?'body':'documentElement';
	images = images.split(',');
	sizes = sizes.split(',');
	for (var i=0,s,e,c=images.length;i<c;i++) {
		s = sizes[i].split('x');
		images[i] = e = { index: i, id: images[i], w: parseInt(s[0], 10), h: parseInt(s[1], 10), r: s[2] }
		e.img = new Image();
		e.img.src = '/_familyCustom/0/areas/'+areaId+pub+'/thumbnails/rev_'+e.r+'/main/'+e.id+'.'+thumbId+'.jpg';
		if (e.w>cW) { e.h=Math.round(e.h*cW/e.w); e.w = cW; }
		if (e.h>cH) { e.w=Math.round(e.w*cH/e.h); e.h = cH; }
		if (!ipImg&&(e.id==imageId)) { ipImg=e; }
	}
	ipImgList = images;
	
	var overlay = DOM.structure({ id:'ipOverlay', c: DHTML.Anim, s: [{ t: 'iframe', _action: 'close' }, { cn: 'ipOverlay1', _action: 'close' }], _onclick: ipClickFN, _action: 'close' });
	var mainEle = DOM.structure({ cn: 'ipOuter', id: 'ipOuter', _onclick: ipClickFN, _onmouseover: ipMouseFN, _onmouseout: ipMouseFN, s: [
									{ id: 'ipMainH', c: DHTML.Anim, r: 'main', s: [
										{ id: 'ipImageH', r: 'imgH', c: DHTML.Anim,  s: [ { t: 'img', r: 'img', _width: ipImg.w, _height: ipImg.h, _src: ipImg.img.src }]},
										{ id: 'ipCloseB', cn: 'ipb_normal', _action: 'close' },
										{ id: 'ipHLeft', cn: 'ipLeft', _action: 'previous' },{ id: 'ipHRight',cn: 'ipRight', _action: 'next' },
										{ id: 'ipButtonBar', s: [{ id: 'ipReport' }, { id: 'ipNextB', cn: 'ipb_normal', _action: 'next'},{ id: 'ipPrevB', cn: 'ipb_normal', _action: 'previous'}] }
									] }
								] })

	overlay.O(0);
	mainEle.imgH.O(0);
	if (DHTML.ie) {
		document.documentElement.className+=' ipBody';
		document.body.className+=' ipBody';
		wrapper.scrollTop=bs;
	} else {
		overlay.style.position=mainEle.style.position='fixed';
	}
	document.body.appendChild(overlay);
	document.body.appendChild(mainEle);
	
	overlay.animate({ O: 70}, 200, 0, ipResizeMain);
}

function ipResizeMain()

{
	var w = Math.round(Math.max(150, ipImg.w));
	var h = Math.round(Math.max(150, ipImg.h)+25);
	var x = -Math.round(w/2);
	var y = -Math.round(h/2);
	var index = ipImg.index+1;
	var ele = DOM.get('ipImageH');
	
	ele.W(ipImg.w); ele.H(ipImg.h);
	ele.X(Math.round((w-ipImg.w)/2));ele.Y(Math.round((h-ipImg.h-25)/2));
	ele.O(0);
	
	if (ipImgList.length > 1)
		DOM.get('ipReport').innerHTML = index+' of '+ipImgList.length;
	else{
		DOM.get('ipNextB').style.background='none';
		DOM.get('ipPrevB').style.background='none';
		DOM.get('ipHLeft').style.cursor='default';
		DOM.get('ipHRight').style.cursor='default';
	}
	
	ele = DOM.get('ipMainH');
	DOM.get('ipOuter').img.src = ipImg.img.src;
	DOM.get('ipOuter').img.width = ipImg.w;
	DOM.get('ipOuter').img.height = ipImg.h;
	ele.show();
	ele._d = { x: x, y: y, w: w, h: h };
	
	ele.animate({ X: x, Y: y, W: w, H: h}, 150, 10, ipFadeInMain);
}

function ipFadeInMain()

{
	var ele = DOM.get('ipImageH');
	var e2 = DOM.get('ipMainH');
	
	e2.W(e2._d.w); e2.H(e2._d.h); e2.X(e2._d.x); e2.Y(e2._d.y);
	ele.animate({ O: 100}, 200, 10);
}


function ipClose(stage)

{
	switch (stage) {
		case 1	: return DOM.get('ipMainH').animate({ O: 0 }, 200, 0, function() { ipClose(2); } );
		case 2	: return DOM.get('ipOverlay').animate({ O: 0 }, 200, 0, ipClose );
	}
	
	var wrapper = DOM.get('sbSiteWrapper');
	var bs = wrapper.scrollTop;
	
	document.body.removeChild(DOM.get('ipOverlay'));
	document.body.removeChild(DOM.get('ipOuter'));
	if (DHTML.ie) {
		wrapper.className='';
		document.body.className=document.body.className.replace(/ ipBody/g, '');
		document.documentElement.className='';
		document[wrapper.scrollEle].scrollTop = bs;
	}
}

function ipGo(d, stage) 

{
	var i = ipImg.index+d;
	
	if (i<0) i=ipImgList.length-1;
	if (i>=ipImgList.length) i=0;
	
	if (i==ipImg.index) return;
	ipImg = ipImgList[i];
	if (stage) return DOM.get('ipImageH').animate({ O: 0 }, 200, 0, ipResizeMain );

}

function ipClickFN(e)

{
	if (!(e=e||window.event)) return;
	var t=e.target||e.srcElement;
	switch (t.action) {
		case 'close'	:	ipClose(1); break;
		case 'next'		:	ipGo(1, 1); break;
		case 'previous'	:	ipGo(-1, 1); break;
	}
}

function ipMouseFN(e)

{
	if (!(e=e||window.event)) return;
	var t=e.target||e.srcElement;
	var id,ele;
	
	switch (t.action) {
		case 'next'		:	id='ipNextB'; break;
		case 'previous'	:	id='ipPrevB'; break;
	}
	if (id) {
		ele = DOM.get(id);
		ele.className=ele.className.replace(/normal|hover/, (e.type=='mouseover')?'hover':'normal')
	}
}

