function QueryString(item){
 var sValue=location.search.match(new RegExp("[\?\&]"+item+"=([^\&]*)(\&?)","i"))
 return sValue?sValue[1]:sValue
}

function $(name){return document.getElementById(name);}


var count = faces.length;
var perpage = 1;
var currentpage = QueryString("page");
if (currentpage==null){
 currentpage = 1;
}else{
 currentpage = parseInt(currentpage);
}
var pagecount = Math.floor(count/perpage);

function paging(num, perpage, curpage, mpurl) {
	var multipage = '';	
	if(num > perpage) {
		var page = 5;
		var offset = 2;
		var realpages = Math.floor(num/perpage);
		var form = 0;
		var to =0;
		var pages = realpages;
		var back = '';
		var next = '';

		if(page > pages) {
			from = 1;
			to = pages;
		} else {
			from = curpage - offset;
			to = from + page - 1;
			if(from < 1) {
				to = curpage + 1 - from;
				from = 1;
				if(to - from < page) {
					to = page;
				}
			} else if(to > pages) {
				from = pages - page + 1;
				to = pages;
			}
		}
	
		multipage += (curpage - offset > 1 && pages > page ? '<td>&nbsp;<a href="'+mpurl+'page=1"><b>|&lt;</b>&nbsp;</td>' : '<td>&nbsp;<b>|&lt;</b>&nbsp;</td>')+
			(curpage > 1 ? '<td>&nbsp;<a href="'+mpurl+'page='+(curpage - 1)+'">&lt;</a>&nbsp;</td>' : '<td>&nbsp;<b>&lt;</b>&nbsp;</td>');
		
		back=(curpage > 1 ? ' <a href="'+mpurl+'page='+(curpage - 1)+'"><img src="/images/back.gif" border="0" align="absmiddle"></a> ' : '<img src="/images/back.gif" border="0" align="absmiddle"> ');



		for(i = from; i <= to; i++) {
			multipage += i == curpage ? '<td bgcolor="#000000" id="pnow">'+chekface(i)+'</td>' :
				'<td id="picon"><a href="'+mpurl+'page='+i+'">'+chekface(i)+'</a></td>';
		}
		var addnum = page-(to - from);
		if (addnum > 0)
		{
			for (o=1;o<addnum;o++){
			multipage +='<td bgcolor="#000000" width="130">&nbsp;</td>';
			}
		}


			multipage += (curpage < pages ? '<td>&nbsp;<a href="'+mpurl+'page='+(curpage + 1)+'">&gt;</a>&nbsp;</td>' : '<td>&nbsp;&gt;&nbsp;</td>')+
			(to < pages ? '<td>&nbsp;<a href="'+mpurl+'page='+pages+'"><b>&gt;|</b></a>&nbsp;</td>' : '<td>&nbsp;<b>&gt;|</b>&nbsp;</td>');
		
	
		next = curpage < pages ? ' <a href="'+mpurl+'page='+(curpage + 1)+'"><img src="/images/nextone.gif" border="0" align="absmiddle"></a>' : ' <img src="/images/nextone.gif" border="0" align="absmiddle"> ';


		multipage = multipage ? '<table cellspacing="3" cellpadding="6" border="0" align="center"><tr><td>'+
			'<table cellspacing="1" cellpadding="2" class="tableborder"><tr bgcolor="#000000" class="smalltxt">'+multipage+'</tr></table>'+
			'</td></tr><tr><td height="30" align="center">'+back+' ('+curpage+'/'+realpages+') '+next+'</td></tr></table>' : '';
	}
	return multipage;
}

function chekface(num){
	return faces[num] ? '<img src="'+faces[num]+'" border="0" height="98" width="130">' : '<img src="/images/nopic.gif" border="0">';
}

function showbigimg(num){
	$('showbigimg').innerHTML = pics[num] ? '<img src="'+pics[num]+'" border="0">' : '<img src="/images/nopic.gif" border="0">';
}

function attachimg(thispic, action) {

		if(thispic.width>900) thispic.width=900;	
}

function bbimg(o)
{
  var zoom=parseInt(o.style.zoom, 10)||100;
  zoom+=event.wheelDelta/12;
  if (zoom>0) o.style.zoom=zoom+'%';
  return false;
}