
function SetupFeatureImage()
{
	var im,feat;
	if(!$('featureimage'))
		return;

	im=$('featureimage').down('img');
	feat=$('featureimage');
	feat.style.width=im.width+'px';
	feat.style.height=im.height+'px';
	feat.style.backgroundImage='url('+im.src+')';
//	$('frmAddEdit_topcoord').up('tr').hide();
//	$('frmAddEdit_leftcoord').up('tr').hide();
//	$('frmAddEdit_width').up('tr').hide();
//	$('frmAddEdit_height').up('tr').hide();
 	var blockers;
	blockers=$$('div.blocker');
	blockers.each(
		function (blocker) {
			offset=$('featureimage').positionedOffset();
			blockeroffset=blocker.positionedOffset();
			blocker.setAttribute('top',parseInt(blockeroffset.top));
			blocker.setAttribute('left',parseInt(blockeroffset.left));
			dimensions=blocker.getDimensions();

			blocker.setAttribute('width',parseInt(dimensions.width));
			blocker.setAttribute('height',parseInt(dimensions.height));

			blocker.setOpacity(0.5);
			blocker.style.top=(parseInt(blockeroffset.top)+parseInt(offset.top))+'px';
			blocker.style.left=(parseInt(blockeroffset.left)+parseInt(offset.left))+'px';
			blocker.zIndex='50';
		}
	);
	im.hide();
	SetupDiv();
	feat.observe('mousedown',StartBoxSet);
	$('featureim_overlay').observe('mousedown',StartBoxSet);
	feat.observe('mouseup',StopBoxSet);

	feat.onmouseover=function() {
		document.onselectstart=function() {return false;};
		document.onmousedown=function () { return false; }
	}
	feat.onmouseout=function() {

	document.onselectstart=function() {return true;}
	document.onmousedown=function () { return true; }
	}
	return false;
}
function StopBoxSet(event)
{
	var im=$('featureimage');
	im.stopObserving('mousemove',UpdateWidthHeight);
	$('featureim_overlay').stopObserving('mousemove',UpdateWidthHeight);
	document.onselectstart=function() {return true;};
	return false;
}
function StartBoxSet(event) 
{
	var im,x,y,top,left,width,height;
	im=$('featureimage');
	top=$('frmAddEdit_topcoord');
	left=$('frmAddEdit_leftcoord');
	width=$('frmAddEdit_width');
	height=$('frmAddEdit_height');

		document.onselectstart=function() {return false;};
	offset=im.positionedOffset();
	x=Event.pointerX(event)-offset.left;
	y=Event.pointerY(event)-offset.top;
	if(CollisionDetect(x,y,x+20,y+20))
	{
		return false;
	}
	top.value=y;
	left.value=x;
	width.value='20';
	height.value='20';
	UpdateDiv(offset.top,offset.left,top.value,left.value,width.value,height.value);

	im.observe('mousemove',UpdateWidthHeight);
	$('featureim_overlay').observe('mousemove',UpdateWidthHeight);
	width.value='';
	height.value='';
	$('featureim_overlay').show();
	return false;
}
function CollisionDetect(cleft,ctop,cright,cbottom)
{
	var blockers, bCollision;
	bCollision=false;
	blockers=$$('div#blockers div');
	cleft=parseInt(cleft);
	ctop=parseInt(ctop);
	cright=parseInt(cright);
	cbottom=parseInt(cbottom);
	blockers.each(
		function(blocker) {
		var top,left,right,bottom;
			top=parseInt(blocker.getAttribute('top'));
			left=parseInt(blocker.getAttribute('left'));
			right=parseInt(blocker.getAttribute('width'))+left;
			bottom=parseInt(blocker.getAttribute('height'))+top;
			if(
				   (ctop>=top && cbottom<=bottom && cleft<=left && cright>=right)
				|| (top>=ctop && bottom<=cbottom && left<=cleft && right>=cright)
				|| (ctop>=top && ctop<=bottom && cleft<=left && cright>=left)	
				|| (cleft>=left && cleft<=right && cbottom>=top && ctop<=bottom)
				|| (cbottom>=top && cbottom<=bottom && cleft<=left && cright>=left)
				|| (top>=ctop && top<=cbottom && left>=cleft && left<=cright)
				)
			{
				bCollision=true
			}
			
			
		}
	);
	return bCollision;
}
function UpdateWidthHeight(event)
{
	var im,top,left,width,height,offset,bOK;
	im=$('featureimage');
	top=$('frmAddEdit_topcoord');
	left=$('frmAddEdit_leftcoord');
	width=$('frmAddEdit_width');
	height=$('frmAddEdit_height');
	offset=im.positionedOffset();
	bOK=CollisionDetect(left.value,top.value,Event.pointerX(event)-offset.left,Event.pointerY(event)-offset.top);
	if(bOK)
	{
		return false;
	}
	if(Event.pointerX(event)>offset.left+im.width || Event.pointerY(event)>offset.top+im.height)
	{
		return false;
	}

	width.value=Math.max(20,Event.pointerX(event)-offset.left-left.value);
	height.value=Math.max(20,Event.pointerY(event)-offset.top-top.value);
	UpdateDiv(offset.top,offset.left,top.value,left.value,width.value,height.value);
	return false;
}
function SetupDiv()
{
	div =document.createElement('div');
	div.id='featureim_overlay';
	div.style.position='absolute';
	div.style.zIndex='20';
	div.style.textAlign="left";
	$('body').appendChild(div);
	var top,left,width,height;
	top=$('frmAddEdit_topcoord');
	left=$('frmAddEdit_leftcoord');
	width=$('frmAddEdit_width');
	height=$('frmAddEdit_height');

	if(
		left.value &&
		top.value &&
		width.value &&
		height.value)
	{
		offset=$('featureimage').positionedOffset();
		UpdateDiv(offset.top,offset.left,top.value,left.value,width.value,height.value);
	}
	else
	{
		$('featureim_overlay').hide();
	}
	$('featureim_overlay').setOpacity(0.7);
	$('featureim_overlay').observe('mouseup',StopBoxSet);

}
function UpdateDiv(offtop,offleft,top,left,width,height)
{
	var overlay;
	overlay=$('featureim_overlay');
	if(top && left && width && height)
	{
		overlay.style.left=(parseInt(offleft)+parseInt(left))+'px';
		overlay.style.top=(parseInt(offtop)+parseInt(top))+'px';
		overlay.style.width=width+'px';
		overlay.style.height=height+'px';
	}
	return false;
}


function SetupList()
{
	var items=$$('span.showsubs');
	items.each(
		function(i) {
			var r=i.up('tr').next('tr.sub');
			i.onclick=function () {
				Effect.toggle(r,'appear', { duration: 0.5 });	
				if(i.innerHTML=='Show Detailed Images')
				{
					i.innerHTML='Hide Detailed Images';
				}
				else
				{
					i.innerHTML='Show Detailed Images';
				}

			}
			r.hide();
		}
	);
}

function SetupDisplayFeatureIm()
{
	var featureimages;
	featureimages=$$('div.featureimage');
	featureimages.each(function (div) {
		var ul=div.down('ul');
		var lis=ul.childElements();
		var img=div.down('img');
		lis.each( function (li) {
			var span, rect;
			span=li.down('span');
			rect=li.down('div.surroundcover');
			rect.className='surrounddisplay';
			rect.style.left=(rect.offsetLeft+img.offsetLeft)+'px';
			rect.className='surround';
			rect.setOpacity(0.05);
			span.onmouseover=function()
			{
				var target;
				target=this.up('li').down('div.surround');
				target.className='surrounddisplay';
				target.setOpacity(0.25);
			}
			span.onmouseout=function()
			{
				var target;
				target=this.up('li').down('div.surrounddisplay');
				target.innerHTML='&nbsp;';
				target.className='surround';
				target.setOpacity(0.05);
			}
			span.onclick=function() {
				DisplayLargeVesion(this.up('li').down('div.ficontent').innerHTML);
			}
			rect.onclick= function() {
				DisplayLargeVesion(this.up('li').down('div.ficontent').innerHTML);
			}
			rect.style.zIndex=40;
			rect.onmouseover=function()
			{
				this.className='surrounddisplay';
				this.setOpacity(0.25);
			}
			rect.onmouseout=function()
			{
				this.className='surround';
				this.setOpacity(0.05);
			}
		});
	});

}
function DisplayLargeVesion(m)
{
	SetupFeatureImageDiv();
	var featureimagewindow=$('featureimagewindow');
	$('featureimagewindow').down('div.content').innerHTML=m;
	var a;
	if(!$('fffooterclear'))
	{
		var clear;
		clear=document.createElement('div');
		clear.id='fffooterclear';
		featureimagewindow.down('div.featureimagefooter').appendChild(clear);
		clear=$('fffooterclear');
		clear.setStyle({clear: 'both'});
	}
	a=document.viewport.getScrollOffsets();
	featureimagewindow.style.top=(((document.viewport.getHeight()-542)/2)+a['top']).toString()+'px';
	featureimagewindow.style.left=(((document.viewport.getWidth()-420)/2)+a['left']).toString()+'px';
	new Effect.BlindDown(featureimagewindow,{duration: '1.0'});
	HideBG();

}
function CloseFIWindow(e)
{
	var featureimagewindow=$('featureimagewindow');
	if(e.responseText)
	{
		featureimagewindow.down('div.content').innerHTML='<p>'+e.responseText+'</p>';
	}
	new Effect.BlindUp(featureimagewindow,{duration: '0.3'});
	ShowBG();
}

function SetupFeatureImageDiv()
{
	var featureimagewindow=$('featureimagewindow');
	if(!featureimagewindow)
	{
		var content;
		featureimagewindow=document.createElement('div');
		featureimagewindow.id='featureimagewindow';
		$('body').appendChild(featureimagewindow);

		content=document.createElement('div');
//		content.innerHTML='<img src="/images/fff_r1_c1.jpg" />';
		content.className="featureimageheader";
		featureimagewindow.appendChild(content);

		content=document.createElement('div');
		content.className='content';
		featureimagewindow.appendChild(content);

		content=document.createElement('div');
		var img=new Image();
		img.src='/primo/pimg/closelabel.gif';
		img.onclick=function() { CloseFIWindow(1) ; }
		content.appendChild(img);
		content.className="featureimagefooter";
		featureimagewindow.appendChild(content);
		featureimagewindow=$('featureimagewindow');
		featureimagewindow.className='featureimagewindow';
		featureimagewindow.hide();

		if(!$('overlaylwd'))
		{
			var objOverlay = document.createElement("div");
			objOverlay.setAttribute('id','overlaylwd');
			objOverlay.style.display = 'none';
			objOverlay.onclick = function() { CloseFIWindow(1); return false; }
			$('body').appendChild(objOverlay);
		}
	}
}



