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 popup(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function rand(n_min,n_max) {
	return(n_min+Math.floor(Math.random()*(n_max-n_min+1)));
}

var src_i=0;
function scraps(div_id,type,scraps_min,scraps_max,x_skew,y_skew) {
	if (document.getElementById(div_id)) {
		div=document.getElementById(div_id);
		div_w=div.offsetWidth;
		div_h=div.offsetHeight;
//		alert ('div_w:'+div_w+' div_h:'+div_h);
		scraps_n=rand(scraps_min,scraps_max);
		src_n=scraps_src[type].length;
		html='';
		i=0;
		while (i<scraps_n) {
			//determine position ranges
			top_min=0;top_max=div_h-scraps_h[type][src_i];
			left_min=0;left_max=div_w-scraps_w[type][src_i];
			//x skew
			if (x_skew<0) {
				left_max=left_max-Math.round(left_max*(-x_skew));
			}
			if (x_skew>0) {
				left_min=left_min+Math.round((left_max-left_min)*(x_skew));
			}
			//y skew
			if (y_skew<0) {
				top_max=top_max-Math.round(top_max*(-y_skew));
			}
			if (y_skew>0) {
				top_min=top_min+Math.round((top_max-top_min)*(y_skew));
			}
			//bring back within limits
			if (scraps_h[type][src_i]>=div_h) {
				top_min=Math.round(div_h/2);
				top_max=top_min;
			}
			if (scraps_w[type][src_i]>=div_w) {
				left_min=Math.round(div_w/2);
				left_max=left_min;
			}

//determine position
			top=rand(top_min,top_max);
			left=rand(left_min,left_max);
			//draw scrap
			html=html+'<div id="'+type+'_'+i+'" class="scrap" style="top:'+top+'px; left:'+left+'px;">';
			html=html+'<img src="'+scraps_src[type][src_i]+'">';
			html=html+'</div>';
//			alert ('src_i:'+src_i+' scraps_h:'+scraps_h[type][src_i]+' scraps_w:'+scraps_w[type][src_i]+' top_min:'+top_min+' top_max:'+top_max+' left_min:'+left_min+' left_max:'+left_max);
			i++;
			src_i++;
			if (src_i==src_n) {
				src_i=0;
			}	
		}
		document.getElementById(div_id).innerHTML=html;
	}
}

function counter(div_id,digits,src,w,h,gap) {
	if (document.getElementById(div_id)) {
		html='';
		digits=digits+'';
		n=digits.length;
		w=w/10;
		i=0;
		while (i<n) {
			figure=parseInt(digits.substring(i,i));
			html=html+'<span style="width:'+w+'px; height:'+h+'px; background-position: '+((figure+0.5)*w)-(w/2)+'px; background-image:url('+src+');"></span>';
			i++;
		}
		document.getElementById(div_id).innerHTML=html;
	}
}

var current_pin=-1;

function show_pin(pin_id) {
	document.getElementById('pin_info_'+pin_id).style.display='block';
	current_pin=pin_id;
}

function clr_pin() {
	if (document.getElementById('pin_info_'+current_pin).style.display=='block') {
		document.getElementById('pin_info_'+current_pin).style.display='none';
	}
}

function set_detail(sub_id,sub_prev,sub_next) {
	document.getElementById('gallery_iframe').src='detail.php?sub_id='+sub_id+'&sub_prev='+sub_prev+'&sub_next='+sub_next;
	document.getElementById('gallery_container').style.display='none';
	document.getElementById('gallery_detail').style.display='block';
	
}

function show_image() {
	$("#gallery_detail_image").fadeIn("medium");
//	$("#thumbnails_container",window.parent.document).fadeOut("fast");
}

var prev_url='';
var next_url='';

function prev_click() {
	location.href=prev_url;
}

function next_click() {
	location.href=next_url;
}

function show_buttons() {
	if (prev_url!='') {
		document.getElementById('btn_prev').style.display='block';
	} else {
		document.getElementById('btn_prev').style.display='none';
	}
	if (next_url!='') {
		document.getElementById('btn_next').style.display='block';
	} else {
		document.getElementById('btn_next').style.display='none';
	}
}
