function popupSimple(url,w,h)
{
	var hori= w;
	var verti= h;
	var l = (screen.availWidth-hori)/2;
	var t = (screen.availHeight-verti)/2;
	
	if (window.screen)
	{
		window.open(url,'popup'+w+'x'+h, 'width='+hori+', height='+verti+', resize=no, toolbar=no, status=no, menubar=no, scrollbars=yes, left='+(l)+', top='+(t));
		
		//location.href=strPage;
	}
}

function newWindow(strPage,h,w)
{
	if (window.screen)
	{
		window.open(strPage,'newWin', 'resize=yes, toolbar=no, status=no, menubar=yes, scrollbars=no, height='+(h)+', width='+(w));
		
		//location.href=strPage;
	}
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function switch_d(div_id) {
		if (document.getElementById(div_id).style.display=="block")
		{
			document.getElementById(div_id).style.display="none";
		}
		else 
		{
			document.getElementById(div_id).style.display="block";
		}
}

function flip(div_id) {
	if (document.getElementById(div_id)) 
	{
		if (document.getElementById(div_id).style.display=="inline")
		{
				document.getElementById(div_id).style.display="none";
		}
		else 
		{
			document.getElementById(div_id).style.display="inline";
		}
	}
}

function previewPopup(template,pg_id)
{
	window.open('../'+template+'?pg_id='+pg_id,'page_preview');
}

function page_w() {return window.innerWidth != null? window.innerWidth: document.body != null? document.body.clientWidth:null;}

function page_h() {return window.innerHeight != null? window.innerHeight: document.body != null? document.body.clientHeight:null;}

function getHeight(id)
{
	h = Number.NaN;
	if (document.getElementById) {
		var ele = document.getElementById(id);
		if (ele && typeof ele.offsetHeight != 'undefined') {
			h = ele.offsetHeight;
		}
	}
	return h;
}

function getWidth(id)
{
	w = Number.NaN;
	if (document.getElementById) {
		var ele = document.getElementById(id);
		if (ele && typeof ele.offsetWidth != 'undefined') {
			w = ele.offsetWidth;
		}
	}
	return w;
}

function page_max() {
	top.window.moveTo(0,0);
	if (document.all) {
		top.window.resizeTo(screen.availWidth,screen.availHeight);
	}
	else if (document.layers||document.getElementById) {
		if (top.window.outerHeight<screen.availHeight||top.window.outerWidth<screen.availWidth){
			top.window.outerHeight = screen.availHeight;
			top.window.outerWidth = screen.availWidth;
		}
	}
	alert('w:'+page_w()); alert('h:'+page_h());
}

var colours=new Array ('ff0099','0099ff','ff6600','ffff00');

function random_colour() {
	return (colours[Math.ceil(Math.random()*colours.length)-1]);
}

function cell_focus(cell_i) {
	cell_blurb_id='cell_blurb'+cell_i;
	cell_header_id='cell_header'+cell_i;
	cell_bg_id='cell_bg'+cell_i;
	cell_container_id='cell_container'+cell_i;
	if (document.getElementById(cell_container_id)) {
		document.getElementById(cell_container_id).className='cell_container_over';
	}
	if (document.getElementById(cell_blurb_id)) {
		document.getElementById(cell_blurb_id).style.display='block';
	}
	if (document.getElementById(cell_header_id)) {
		document.getElementById(cell_header_id).style.display='block';
	}
}

function cell_blur(cell_i) {
	cell_blurb_id='cell_blurb'+cell_i;
	cell_header_id='cell_header'+cell_i;
	cell_bg_id='cell_bg'+cell_i;
	cell_container_id='cell_container'+cell_i;
	if (document.getElementById(cell_container_id)) {
		document.getElementById(cell_container_id).className='cell_container';
	}
	if (document.getElementById(cell_blurb_id)) {
		document.getElementById(cell_blurb_id).style.display='none';
	}
	if (document.getElementById(cell_header_id)) {
		document.getElementById(cell_header_id).style.display='none';
	}
}

function blurb_focus(cell_i) {
	document.getElementById('cell_blurb'+cell_i).className='cell_blurb_over';
}

function blurb_blur(cell_i) {
	if (document.getElementById('cell_blurb'+cell_i)) {
		document.getElementById('cell_blurb'+cell_i).className='cell_blurb';
	}
}

function header_focus(cell_i) {
	document.getElementById('cell_header'+cell_i).className='cell_header_over';
}

function header_blur(cell_i) {
	if (document.getElementById('cell_header'+cell_i)) {
		document.getElementById('cell_header'+cell_i).className='cell_header';
	}
}

function set_detail(thing_id,cell_i,show_id) {
	document.location.href='index.php?thing_id='+thing_id+'&show_id='+show_id;
}

function show_detail() {
	parent.document.getElementById('detail_container').style.display='block';
	parent.document.getElementById('detail_iframe').style.borderColor=random_colour();
}

function show_grid() {
	new Effect.toggle(parent.document.getElementById('detail_container'), 'appear', {duration: 0.3, queue: {position: 'end', scope: 'view_switch'} });
	parent.document.focuser.focus_puller.focus();
}

function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}

function set_img(src,caption,img_i,img_n) {
	document.getElementById('box_top').style.backgroundImage='url('+src+')';
	i=0;
	while (i<img_n) { i++;
		document.getElementById('image_link'+i).className='image';
	}
	document.getElementById('image_link'+img_i).className='image_current';
	if (caption!="") {
		document.getElementById('caption_text').style.display='block';
		document.getElementById('caption_text').innerHTML=caption;
	} else {
		document.getElementById('caption_text').style.display='none';
	}
}
	
function menu_focus() {
	if (document.getElementById('menu_container')) {
		queue = Effect.Queues.get('menu');
		queue.each(function(effect) { effect.cancel(); });
		new Effect.Opacity('menu_container', { to: 0.99, duration: 0.1, queue: { position: 'end', scope: 'menu' }  });
	}
}

function menu_blur() {
	if (document.getElementById('menu_container')) {
		queue = Effect.Queues.get('menu');
		queue.each(function(effect) { effect.cancel(); });
		new Effect.Opacity('menu_container', { to: 0.4, duration: 0, queue: { position: 'end', scope: 'menu' } });
	}
}

function show_notes() {
	document.getElementById('box_btm').style.display='none';
	document.getElementById('notes_container').style.display='block';
}

function clr_notes() {
	document.getElementById('box_btm').style.display='block';
	document.getElementById('notes_container').style.display='none';
}

var chickenpopup;

function set_Viewer(set,w,h) {
	chickenpopup=window.open ('viewer.php?set='+set,'chickenbox','directories=no, status=no, toolbar=no, location=no, menubar=0, scrollbars=no, width='+(w+60)+', height='+(h+50));
	chickenpopup.focus();
	
}

