var curpic="imgs";
var functionref=0;
var content=0;
var contentref=0;
var inc=0;
var winW=0;
var winH=0;
var lpos=0;
var tpos=0;
var picdesc="0";
var ctime="";
var timob="";

function contact(){
	document.getElementById('contact').style.left='25px';
	document.getElementById('contact').innerHTML='tel: '+phone+' <span style=\"margin: 0px 0px 0px 20px\">email : <a href="mailto:'+mail+'">'+mail+'</a></span>';
	document.getElementById('contact').style.display=='block' ? document.getElementById('contact').style.display='none' : document.getElementById('contact').style.display='block';
}

function gallcontact(){
	document.getElementById('contact').style.left='25px';
	document.getElementById('contact').style.top='400px';
	document.getElementById('contact').innerHTML='tel: '+phone+'<br><br>email : <a href="mailto:'+mail+'">'+mail+'</a>';
	document.getElementById('contact').style.display=='block' ? document.getElementById('contact').style.display='none' : document.getElementById('contact').style.display='block';
}

function myemail(){
	document.getElementById('emailbox').innerHTML='<a href="mailto:info@merlinglass.co.uk">info@merlinglass.co.uk</a>';
}

function SetOpacity(elem, opacityAsInt)
{
	var opacityAsDecimal = opacityAsInt;
	
	if (opacityAsInt > 100)
		opacityAsInt = opacityAsDecimal = 100; 
	else if (opacityAsInt < 0)
		opacityAsInt = opacityAsDecimal = 0; 
	
	opacityAsDecimal /= 100;
	if (opacityAsInt < 1)
		opacityAsInt = 1; // IE7 bug, text smoothing cuts out if 0
	
	elem.style.opacity = opacityAsDecimal;
	elem.style.filter  = "alpha(opacity=" + opacityAsInt + ")";
}

function FadeOpacity(elemId, fromOpacity, toOpacity, time, fps)
{
	var steps = Math.ceil(fps * (time / 1000));
	var delta = (toOpacity - fromOpacity) / steps;
	
	FadeOpacityStep(elemId, 0, steps, fromOpacity, delta, (time / steps));
}

function FadeOpacityStep(elemId, stepNum, steps, fromOpacity, delta, timePerStep)
{
    SetOpacity(document.getElementById(elemId), Math.round(parseInt(fromOpacity) + (delta * stepNum)));

    if (stepNum < steps){
        setTimeout("FadeOpacityStep('" + elemId + "', " + (stepNum+1) + ", " + steps + ", " + fromOpacity + ", " + delta + ", " + timePerStep + ");", timePerStep);
    }
    else{
    	switchcontent();
    }
}

function switchcontent(){
	inc==5 ? inc=0 : inc=inc;
	if(functionref==0){
		content=slideimages[inc];
		inc++;
		document.getElementById(curpic).innerHTML=content;
		matrixfadeup();
   }else{
    matrixfade();
   }
}

function matrixfade(){
	functionref=0;
	setTimeout("FadeOpacity(curpic, 100, 0, 1500, 13)",10000);
}

function matrixfadeup(){
	functionref=1;
	setTimeout("FadeOpacity(curpic, 0, 100, 1500, 13)",100);
}

function alertSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return(myHeight+':'+myWidth);
}

function indextableheight(){
	//var dims=alertSize().split(":");
	//var hite=dims[0]-50;
	//var wid=dims[1]-50;
	//document.getElementById('mainbox').style.height=hite+'px';
	//document.getElementById('mainbox').style.width=wid+'px';
	//document.getElementById('titlebar').style.width=wid+'px';
	//alert(wid)
	contact()
}

function aboutableheight(){
	var dims=alertSize().split(":");
	var hite=dims[0]-50;
	var wid=dims[1]-50;
	document.getElementById('mainbox').style.height=hite+'px';
	document.getElementById('mainbox').style.width=wid+'px';
	document.getElementById('titlebar').style.width=wid+'px';
	
	var marg=hite-410;
	document.getElementById('imgs2').style.marginTop=(marg-40)+'px';
	
	var tboxmarg=marg+185;
	document.getElementById('txtbox').style.marginTop=40+'px';
	contact()
}

function gallerytableheight(){
	var dims=alertSize().split(":");
	var hite=dims[0]-50;
	var wid=dims[1]-50;
	//document.getElementById('mainbox').style.height=hite+'px';
	//document.getElementById('mainbox').style.width=1200+'px';
	//document.getElementById('titlebar').style.width=1200+'px';
	//document.getElementById('innerbox').style.width=1200+'px';
	//winsize();
	//findcenter('width=460 height=600');
	//document.getElementById('folderview').style.left=lpos+'px';
	//document.getElementById('folderview').style.top=130+'px';
	contact()
}

function exhibstableheight(){
	var dims=alertSize().split(":");
	var hite=dims[0]-50;
	var wid=dims[1]-50;
	document.getElementById('mainbox').style.height=hite+'px';
	document.getElementById('mainbox').style.width=wid+'px';
	document.getElementById('titlebar').style.width=wid+'px';
	winsize();
	findcenter('width=960 height=600');
	document.getElementById('exhibitionspace').style.left=lpos+'px';
	document.getElementById('exhibitionspace').style.top=160+'px';
	document.getElementById('exhibitionspace').style.display='block';
	contact()
}

function checkcursor(oBj){
	if(oBj.src!="http://www.paulcainsmith.co.uk/images/query2.jpg"){
		oBj.style.cursor='pointer';
		oBj.title='click to see larger image ...';
		oBj.alt='click to see larger image ...';
		}
}

function testform(){
	if(document.trans.uname.value=="" || document.trans.uname.value=="username" || document.trans.pword.value=="" || document.trans.uname.value=="password"){
		alert("Please enter a UserName & Password combination ...")
	}
	else{
		document.trans.submit();
	}
}

function clearbox(oBj){
	oBj.value="";
}

function showme(){
	trans.action="../pages/galleryview.php";
	trans.submit();
}

function relocate(add){
	location=add;
}

function greyup(a){
	a.style.color='#63A2CA';
}

function greydown(a){
	a.style.color='#4C4C4C';
}

function indexover(num){
	if(num==1){
		document.getElementById('index1').src="images/index1a.gif";
	}
	if(num==2){
		document.getElementById('index2').src="images/index2a.gif";
	}
	if(num==3){
		document.getElementById('index3').src="images/index3a.gif";
	}
}

function indexout(num){
	if(num==1){
		document.getElementById('index1').src="images/index1.gif";
	}
		if(num==2){
		document.getElementById('index2').src="images/index2.gif";
	}
		if(num==3){
		document.getElementById('index3').src="images/index3.gif";
	}
}

document.onkeypress=testinput;

function testinput(e){
	if(location.pathname=='/mindex.html'|| location.pathname=='/'){
		var evtobj=window.event? event : e //distinguish between IE's explicit event object (window.event) and Firefox's implicit.
		var unicode=evtobj.charCode? evtobj.charCode : evtobj.keyCode
		var actualkey=String.fromCharCode(unicode)
	
		if(unicode==13){
			testform(document.trans);
		}
	}
}

function tableviewswap(){
	
	document.getElementById('folderview').style.display='none';
	document.getElementById('bigimageview').style.display='block';
}

function divswap(mysrc){
		rExp=/_m\./gi;
		mynewsrc=mysrc.replace(rExp,"_l\.");
		document.getElementById('bigimage').src=mynewsrc;
		document.getElementById('folderview').style.display='none';
		document.getElementById('titlebar').style.display='none';
		document.getElementById('bigimageview').style.display='block';
}


function divswapback(){
	document.getElementById('folderview').style.display='block';
	document.getElementById('titlebar').style.display='block';
	document.getElementById('bigimageview').style.display='none';
	document.getElementById('bigimage').src="";
	document.getElementById('sidemenu').style.display='block';
	document.getElementById('titlebar').style.borderBottom="1px #fff solid";
}

function replacepic(fldr,pic,desc,ind,sum,id,nam,dim,med){
	document.getElementById('titlebar').style.display='none';
	document.getElementById('folderview').style.display='none';
	document.getElementById('sidemenu').style.display='none';
	winsize();
	findcenter('width=1000 height=600');
	document.getElementById('bigimageview').style.left=lpos+'px';
	document.getElementById('bigimageview').style.top=tpos+'px';
	document.getElementById('bigimageview').style.display='block';
	
	document.getElementById('innerbox').style.borderTop="1px #474B54 solid";
	rExp=/_m\./gi;
	if(ind<sum){
		var plusind=(ind+1);
		document.getElementById('bigrarr').innerHTML="<img id=bigrarrim onClick=\"replacepic('"+fldr+"','../imagestore/"+fldr+"/"+imArray[plusind][0]+"_m.jpg','"+imArray[plusind][1]+"',"+plusind+","+sum+","+imArray[plusind][2]+",'"+imArray[plusind][3]+"','"+imArray[plusind][4]+"','"+imArray[plusind][5]+"')\" src=\"../images/next.gif\" width=23px title=\"next image\">";
		document.getElementById('bigrarrim').style.display='block';
	}
	else{
		document.getElementById('bigrarr').innerHTML="";
	}
	
	if(ind>1){
		var minusind=(ind-1);
		document.getElementById('biglarr').innerHTML="<img id=biglarrim onClick=\"replacepic('"+fldr+"','../imagestore/"+fldr+"/"+imArray[minusind][0]+"_m.jpg','"+imArray[minusind][1]+"',"+minusind+","+sum+","+imArray[minusind][2]+",'"+imArray[minusind][3]+"','"+imArray[minusind][4]+"','"+imArray[minusind][5]+"')\" src=\"../images/prev.gif\" width=23px title=\"previous image\">";
		document.getElementById('biglarrim').style.display='block';
	}
	else{
		document.getElementById('biglarr').innerHTML="";
	}
	var cont2='<div class=dims1>'+dim+'</div><div class=nams1>'+nam+'</div><div class=price1>'+med+'</div>';
	
	mynewsrc=pic.replace(rExp,"_l\.");
	document.getElementById('bigimage').src=mynewsrc;
	document.getElementById('bgname').innerHTML=nam;
	document.getElementById('bgdims').innerHTML=dim;
	document.getElementById('bgcost').innerHTML=med;
}

function borderup(oBj){
	oBj.style.borderColor="#3B5AA3";
}

function borderdown(oBj){
	oBj.style.borderColor="#bbbbbb";
}

function borderup1(oBj){
	oBj.style.borderColor="#bbb";
	oBj.style.opacity=.70;
	oBj.style.KhtmlOpacity=.70;
	oBj.style.mozOpacity=.70;
	oBj.style.filter='alpha(opacity=70)';
}

function borderdown1(oBj){
	oBj.style.borderColor="#F0F4F0";
	oBj.style.opacity=1;
	oBj.style.KhtmlOpacity=1;
	oBj.style.mozOpacity=1;
	oBj.style.filter='alpha(opacity=100)';
}

function showimage(){
	winsize();
	findcenter('width=300 height=200');
	document.getElementById('imagediv').style.posLeft=lpos;
	document.getElementById('imagediv').style.posTop=tpos;
	document.getElementById('imagediv').style.display='block';
}

function showcontact(){
	winsize();
	findcenter('width=350 height=480');
	document.getElementById('contactarea').style.left=lpos+'px';
	document.getElementById('contactarea').style.top=tpos+'px';
	document.getElementById('contactarea').style.display='block';
}

function showexhibs(){
	winsize();
	findcenter('width=830 height=350');
	document.getElementById('exhibitions').style.left=lpos+'px';
	document.getElementById('exhibitions').style.top=tpos+'px';
	document.getElementById('exhibitions').style.display='block';
}

function showenter(){
	winsize();
	findcenter('width=250 height=250');
	
	document.getElementById('enterbox').style.left=lpos+'px';
	document.getElementById('enterbox').style.top=50+'px';
	document.getElementById('enterbox').style.display='block';
}

function makefolder(){
	winsize();
	findcenter('width=300 height=100');
	document.getElementById('makefold').style.posLeft=lpos;
	document.getElementById('makefold').style.posTop=tpos;
	document.getElementById('makefold').style.display='block';
}

function delfolder(){
	winsize();
	findcenter('width=300 height=100');
	document.getElementById('delfold').style.posLeft=lpos;
	document.getElementById('delfold').style.posTop=tpos;
	var checkboxstring="";
	var len=dirArray.length;
	
	for(i=0;i<len;i++){
		checkboxstring+="<div class=deldir onMouseOver='radioup(this)' onMouseOut='radiodown(this)' onClick='radiocheck("+i+")'>"+dirArray[i]+"</div>&nbsp;<input class=radiobox id="+i+" type=radio name=emptydir value='"+dirArray[i]+"'><br>";
	}
	
	document.getElementById('emptyfolders').innerHTML=checkboxstring;
	document.getElementById('delfold').style.display='block';
}

function radioup(oBj){
	oBj.style.backgroundColor='#7BB4D6';
}

function radiodown(oBj){
	oBj.style.backgroundColor='#D1D6D9';
}
function radiocheck(rad){
	document.getElementById(rad).checked=true;
}

function deleteimage(){
	winsize();
	findcenter('width=300 height=200');
	document.getElementById('delimagediv').style.posLeft=lpos;
	document.getElementById('delimagediv').style.posTop=tpos;
	document.delimage.delimagefile.value=document.getElementById('imageviewerpic').src;
	document.getElementById('delpichoose').src=document.getElementById('imageviewerpic').src;
	document.getElementById('delimagediv').style.display='block';
}

function divgo(){
	document.getElementById('imagediv').style.display='none';
	document.sendimage.descr.value="";
	document.sendimage.imagefile.value="";
	document.getElementById('pichoose').src="../images/newimage.jpg";
}

function contactgo(){
	document.getElementById('contactarea').style.display='none';
	document.message.mess.value="";
	document.message.m.value="";
	document.message.contact.value="";
	document.message.addr.value="";
	document.message.elem.value="";
}

function exhibsgo(){
	document.getElementById('exhibitions').style.display='none';
}

function foldivgo(){
	document.getElementById('makefold').style.display='none';
	document.createfolder.foldername.value="";
}

function delfoldivgo(){
	document.getElementById('delfold').style.display='none';
}

function editdivgo(){
	document.getElementById('editimg').style.display='none';
}

function deldivgo(){
	document.getElementById('delimagediv').style.display='none';
	document.delimage.delimagefile.value="";
	document.getElementById('pichoose').src="";
}

function winsize(){
	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") {
			winW = window.innerWidth;
			winH = window.innerHeight;
 			}
 		if (navigator.appName.indexOf("Microsoft")!=-1) {
			winW = document.body.offsetWidth;
			winH = document.body.offsetHeight;
			}
	}
}

function findcenter(sizestring){
	var myReg= new RegExp("width=(.*) height=(.*)");
	var results= sizestring.match(myReg);
	lpos=Math.round(parseFloat((winW-results[1])/2));
	tpos=Math.round(parseFloat((winH-results[2])/2));
}

function formsub(oBj){
	if(oBj.imagefile.value==''){
		alert('please select image file');
	}
	else{
		oColl=sendimage.elements;
		num2=oColl.length;
		for(count=0;count<num2;count++){
		cleantext(sendimage.elements(count))
		}
		oBj.submit();
	}
}

function delformsub(oBj){
	if(confirm('Final chance to back out ... are you sure?')){
		oBj.submit();
	}
}

function revealpic(){
	//if(picdesc=="1"){
		if(sendimage.imagefile.value!=""){
			//document.getElementById('pichoose').src=sendimage.imagefile.value;
			document.getElementById('pichoose').src='c:\inetpub/wwwroot/site_files/www.paulcainsmith/html/images/pcslogo.jpg';
			picdesc="0";
			document.getElementById('imagefile').blur();
			alert('hello')
		}
		
	//}
	//else{
	//	picdesc="1";
	//}
}

function viewimg(pic){
	var newcontent=pic;
	var finalcontent=imgtemplate.replace(/content/gi,newcontent);
	
	winsize();
	findcenter('width=300 height=200');
	document.getElementById('medimagediv').style.posLeft=lpos;
	document.getElementById('medimagediv').style.posTop=tpos;
	document.getElementById('medimagediv').innerHTML=finalcontent;
	document.getElementById('medimagediv').style.display='block';
}

function closediv(oBj){
	document.getElementById(oBj).style.display='none';
}

function cleantext(oBj){
	var oldstring=oBj.value;
	rExp1=/'/gi;
	rExp2=/"/gi;
	rExp3=/\\/gi;
	newstring=oldstring.replace(rExp1,"`");
	newstring1=newstring.replace(rExp2,"`");
	newstring2=newstring1.replace(rExp3,"");
	oBj.value=newstring2;
}

var oldlay;
	
function layh(lay)
{
	if(oldlay)
	{
		document.getElementById(oldlay).style.display='none';
	}
	
	document.getElementById(lay).style.display='block';
	document.message.elem.value=lay;
	oldlay=lay;
}

function layest(urlparam)
{
	if(urlparam)
	{
		document.getElementById(urlparam).style.display='block';
		oldlay=urlparam;
	}
}

function unencrypt(){
	var myText="";
	mess=bert.value;
	len=mess.length;
	inc=len/3;
	for(x=0;x<len;x+=3){
		myText=myText+"&#"+eval(mess.substring(x,x+3)-inc)+";";
		}	
	return("<a href='mailto:"+myText+"' id=ema>"+myText+"</a>")
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
	do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	return [curleft,curtop];
	}
}

function showgallery(){
	var pos=findPos(document.getElementById('gallerymenubar'));
	document.getElementById('gallerymenu').style.left=(pos[0])+'px';
	document.getElementById('gallerymenu').style.top=pos[1]+'px';
	document.getElementById('gallerymenu').style.display='block';
}

function hidegallery(){
	document.getElementById('gallerymenu').style.display='none';
}
