var choice=Math.min(Math.floor(Math.random()*pics.length),pics.length-1)
var imgs=new Array('images/16_feed_orange.gif','images/buttons/nextC.png','images/buttons/prevC.png','images/buttons/playC.png','images/buttons/stopG.png','images/buttons/slowG.png','images/buttons/fastG.png','images/buttons/stopC.png','images/buttons/slowC.png','images/buttons/fastC.png','images/speed/speed0.gif','images/speed/speed1.gif','images/speed/speed2.gif','images/speed/speed3.gif','images/speed/speed4.gif','images/speed/speed5.gif','images/speed/speed6.gif','images/speed/speed7.gif','images/speed/speed8.gif','images/speed/speed9.gif','images/h_lt/h_lt_sold.gif','images/signature.gif','images/pointR.gif','images/pointL.gif')
document.imgsLoaded=new Array()
document.picsLoaded=new Array()
document.dtlsLoaded=new Array()
var di=document.imgsLoaded,dp=document.picsLoaded,dd=document.dtlsLoaded
var mIE56,mIE567
var navUA=navigator.userAgent
if(navUA.indexOf("MSIE")!=-1&&navUA.indexOf("Opera")==-1){
	if(navUA.indexOf("MSIE 5")+navUA.indexOf("MSIE 6")>1)mIE56=1
	if(navUA.indexOf("MSIE 5")+navUA.indexOf("MSIE 6")+navUA.indexOf("MSIE 7")+navUA.indexOf("MSIE 8")>1)mIE567=1
}
var interval=3500,increment=1.3,speedDots=6,maxDots=9,minDots=0,count,timeout,message=""
var toggleS="off"
var largeSize,smallSize,mainDiv,footerDiv,detailSize,workWi,workHi,picWi,picHi,picDiv,menuDiv,spielTopPad,sideOffset,extraOffset,visibleD,dtls
var d=new Date()
var dT=d.getTime()
var details=new Array(236,563,569,575,589,599,579)
var domain="karen-gilbert.com"
var contactK="<a href=\"mailto:karen@"+domain+"\">Karen Gilbert</a>"
var contactK2="<a class=\"txtLink\" href=\"mailto:karen@"+domain+"\">[email Karen Gilbert]</a>"
var contactW="<a href=\"mailto:webmaster@"+domain+"\">website issues</a>"
function first(){
	if(screen.availWidth>1029&&screen.availHeight>869){
		largeSize=650
		smallSize=75
	}
	else if(screen.availWidth>799&&screen.availHeight>699){
		largeSize=500
		smallSize=57
	}
	else if(screen.availWidth>669&&screen.availHeight>599){
		largeSize=350
		smallSize=40
	}
	else{
		largeSize=168
	}
	mainDiv=document.getElementById("mainD")
	footerDiv=document.getElementById("footerD")
	detailSize=Math.max(largeSize-150,168)
}
function size(){
	workWi=document.body.clientWidth
	workHi=document.body.clientHeight
	if(!smallSize)workHi=198
	if(mIE56){
		var menuHi=workHi+"px"
		document.getElementById("leftMenuD").style.height=menuHi
		document.getElementById("rightMenuD").style.height=menuHi
		document.getElementById("soldLink").style.cursor="text"
	}
	spielTopPad=Math.max((Math.pow(workHi*workHi*workWi,0.33)-700)*0.1,0)
	sideOffset=Math.max((Math.pow(workHi*Math.pow(workWi,3),0.25)-100)*0.28,0)
	extraOffset=Math.max((workWi-700)*0.25,0)
}
function produceMenu(){
	if(smallSize){
		var i,thumbWi,thumbHi,theMenu=new Array()
		for(i=0;i<pics.length;i++){
			thumbWi=eval("pics[i].width"+smallSize)
			thumbHi=eval("pics[i].height"+smallSize)
			theMenu.push("<div class=\"rightMenuD\" id=\"picDiv"+i+"\" onmouseover=\"bright(\'pic"+i+"\')\" onmouseout=\"dim(\'pic"+i+"\')\" onclick=\"stopShow();selectPic("+i+")\"><img id=\"pic"+i+"\" width=\""+thumbWi+"\" height=\""+thumbHi+"\" src=\"pics"+smallSize+"/"+pics[i].filename+"\"/><div class=\"h_ltD\" id=\"h_lt"+i+"\"></div></div>")
			document.getElementById("rightMenuD").innerHTML = theMenu.join("")
			if(mIE567)document.getElementById("pic"+i).style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=83)"
		}
	}
}
function makeLink(id){
	var info,menuD=document.getElementById(id+"MenuD").style
	menuD.color="#FFF"
	menuD.textDecoration="underline"
	switch(id){
		case"exhibit":
			info="Exhibitions"
			break
		case"statement":
			info="Artist Statement"
			break
		case"detail":
			info="Close-up detail of various paintings"
			break
		case"contact":
			info="Contact by email + Other related links"
			break
		case"sell":
			info="Artwork For Sale"
			break
	}
	window.status=info
}
function unmakeLink(id){
	window.status=""
	var menuD=document.getElementById(id+"MenuD").style
	menuD.color="#DDD"
	menuD.textDecoration="none"
}
function cyanify(id){
	var cyan="images/buttons/"+id+"C.png"
	var theDiv=document.getElementById(id)
	function change(){
		theDiv.style.cursor="pointer"
		theDiv.src=cyan
	}
	switch(id){
		case"prev":
			change()
			message="Previous painting"
			break
		case"next":
			change()
			message="Next painting"
			break
		case"play":
			change()
			message="Slideshow of all paintings"
			break
		case"stop":
			change()
			message="Stop slideshow"
			break
		case"slow":
			if(speedDots>minDots){
				change()
				message="Slow down slideshow"
			}
			break
		case"fast":
			if(speedDots<maxDots){
				change()
				message="Speed up slideshow"
			}
			break
		case"recBtn":
			change()
			message="Paintings most recently added"
			break
		case"sldBtn":
			change()
			message="Paintings sold"
			break
	}
	window.status=message
	message=""
}
function uncyanify(id){
	window.status=""
	var grey="images/buttons/"+id+"G.png"
	var theDiv=document.getElementById(id)
	theDiv.style.cursor="default"
	theDiv.src=grey
}
function adjacentPic(way){
	if(way=="p")choice==0?choice=pics.length-1:choice--
	else choice==pics.length-1?choice=0:choice++
	selectPic()
}
function playShow(){
	document.getElementById("playD").style.display="none"
	document.getElementById("prevD").style.display="none"
	document.getElementById("nextD").style.display="none"
	document.getElementById("stopD").style.display="block"
	document.getElementById("slowD").style.display="block"
	document.getElementById("fastD").style.display="block"
	document.getElementById("speedI").style.visibility="visible"
	count=0
	timer()
}
function timer(){
	count++
	adjacentPic("n")
	count<pics.length?timeout=setTimeout("timer()",interval):stopShow()
}
function stopShow(){
	document.getElementById("stopD").style.display="none"
	document.getElementById("slowD").style.display="none"
	document.getElementById("fastD").style.display="none"
	document.getElementById("playD").style.display="block"
	document.getElementById("prevD").style.display="block"
	document.getElementById("nextD").style.display="block"
	document.getElementById("speedI").style.visibility="hidden"
	clearTimeout(timeout)
}
function speed(spd){
	if(spd=="up"&&speedDots<maxDots){
		interval/=increment
		speedDots+=1
		dots()
		if(speedDots==maxDots){
			with(document.getElementById("fast")){
				style.cursor="default"
				src="images/buttons/fastG.png"
			}
			window.status=""
		}
	}
	else if(spd=="down"&&speedDots>minDots){
		interval*=increment
		speedDots-=1
		dots()
		if(speedDots==minDots){
			with(document.getElementById("slow")){
				style.cursor="default"
				src="images/buttons/slowG.png"
			}
			window.status=""
		}
	}
}
function dots(){
	var dotty="images/speed/speed"+speedDots+".gif"
	document.getElementById("speedI").src=dotty
}
function bright(id){
	var thmb=document.getElementById(id).style
	thmb.opacity="1"
	thmb.MozBoxShadow="2px 5px 30px 0 #000"
	thmb.WebkitBoxShadow="2px 5px 60px #000"
	if(mIE567)document.getElementById(id).style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity=100)"
	}
function dim(id){
	var thmb=document.getElementById(id).style
	thmb.opacity=".9"
	thmb.MozBoxShadow="0 1px 3px 0 #111"
	thmb.WebkitBoxShadow="0 1px 6px #111"
	if(mIE567)document.getElementById(id).style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity=83)"
	}
function positionContent(){
	document.getElementById("mainPic")?positionPic():positionSpiel()
}
function selectPic(pic){
	if(pic>=0)choice=(pic)
	picWi=eval("pics[choice].width"+largeSize)
	picHi=eval("pics[choice].height"+largeSize)
	if(visibleD)document.getElementById(visibleD).style.display="none"
	mainDiv.innerHTML="<img id=\"mainPic\" width=\""+picWi+"\" height=\""+picHi+"\" src=\"pics"+largeSize+"/"+pics[choice].filename+"\" onload=\"bin()\"/>"
	positionPic()
	mainDiv.style.display="block"
	setFooter()
	document.getElementById("mainPic").style.visibility="visible"
	if(smallSize){
		if(menuDiv)document.getElementById(menuDiv).style.backgroundImage="none"
		if(picDiv)document.getElementById(picDiv).style.backgroundImage="none"
		picDiv="picDiv"+choice
		document.getElementById(picDiv).style.backgroundImage="url(images/pointR.gif)"
	}
}
function positionPic(){
	document.getElementById("mainPic").style.top=Math.max((workHi-picHi)/2-10,0)+"px"
	if(mIE56){
		mainDiv.style.width=workWi-10+"px"
		mainDiv.style.height="100%"
		footerDiv.style.width=workWi-10+"px"
	}
}
function setFooter(){
	var w=pics[choice].width
	var h=pics[choice].height
	var c=pics[choice].canvases
	var intro=(c>1&&w!=undefined?"each canvas is ":"")
	var size=(w!=undefined?w+" x "+h+" cm":"")
	footerDiv.innerHTML="<span>"+(choice+1)+".</span><span>"+intro+size+"</span><span>acrylic on canvas</span>"
	footerDiv.style.display="block"
}
function loadPics(){
	setTimeout("loadNow()",1000)
}
function loadNow(){
	var i
	for(i=0;i<pics.length;i++){
		var n=new Image
		n.src="pics"+largeSize+"/"+pics[i].filename
		dp.push(n)
	}
}
function loadImages(){
	var i
	for(i=0;i<imgs.length;i++){
		var n=new Image
		n.src=imgs[i]
		di.push(n)
	}
}
function bin(){
	document.getElementById("loadingD").style.display="none"		//						new position
	document.getElementById("buttonsD").style.display="block"
}
function setSpiel(newD){
	if(visibleD)document.getElementById(visibleD).style.display="none"
	visibleD=newD+"D"
	if(visibleD=="detailD")loadDetails()
	positionSpiel()
	document.getElementById(visibleD).style.display="block"
	if(picDiv)document.getElementById(picDiv).style.backgroundImage="none"
	if(menuDiv)document.getElementById(menuDiv).style.backgroundImage="none"
	menuDiv=newD+"MenuD"
	if(menuDiv)document.getElementById(menuDiv).style.backgroundImage="url(images/pointL.gif)"
}
function positionSpiel(){
	var wide
	if(visibleD!="statementD"&&visibleD!="contactD")wide=1
	var theSpiel=document.getElementById(visibleD).style
	theSpiel.left=(wide?sideOffset:sideOffset+extraOffset)+"px"
	theSpiel.right=(wide?sideOffset:sideOffset+extraOffset)+10+"px"
	theSpiel.padding=spielTopPad+"px 5px 0px"
}
function styleDate(start,end){
	var spanClass="date"
	var s=new Date(start)
	var e=new Date(end)
	if(dT<e.getTime()+86400000){
		start=start!=end?start.slice(0,start.length-4)+start.slice(start.length-2)+" - ":""
		end=end.slice(0,end.length-4)+end.slice(end.length-2)
		spanClass+=(dT<s.getTime())?" future":" now"
	}
	else if(d.getFullYear()==e.getFullYear()&&d.getMonth()==e.getMonth()){
		start=start!=end?start.slice(0,start.length-4)+start.slice(start.length-2)+" - ":""
		end=end.slice(0,end.length-4)+end.slice(end.length-2)
	}
	else if(start.slice(start.length-2)!=end.slice(end.length-2)){
		start=start.slice(start.length-8)+" - "
		end=end.slice(end.length-8)
	}
	else if(start.slice(start.length-8)!=end.slice(end.length-8)){
		start=start.slice(start.length-8,start.length-5)+" - "
		end=end.slice(end.length-8)
	}
	else{
		start=""
		end=end.slice(end.length-8)
	}
	document.write("<span class='"+spanClass+"'>"+start+end+"</span>")
}
function sld(){
	toggleS=(toggleS=="off"?"on":"off")
	var i
	for(i=0;i<pics.length;i++){
		if(toggleS=="off")document.getElementById("h_lt"+i).style.backgroundImage="none"
		else if(pics[i].sold=="s")document.getElementById("h_lt"+i).style.backgroundImage="url(images/h_lt/h_lt_sold.gif)"
	}
}
function clearPicAndFoot(){
	mainDiv.style.display="none"
	mainDiv.innerHTML=""
	footerDiv.style.display="none"
}
function loadDetails(){
	var i
	for(i=0;i<details.length;i++){
		var n=new Image
		n.src="detail"+detailSize+"/IMG_0"+details[i]+".jpg"
		dd.push(n)
	}
}
function showDetail(x){
	document.getElementById("selectD").style.display="none"
	if(dd.length<1)loadDetails()
	var detail=document.getElementById("detail")
	detail.src=dd[x].src
	detail.height=detailSize
	detail.width=detailSize
	document.getElementById("detailPic").style.display="block"
}

