g_fPlayMode = 0;
g_fsoundmode = 0;
g_ffademode = 0;
g_iimg = -1;
g_imax = 0;
g_iimg_re = -1;
rego = 0;
g_ImageTable = new Array();
var separator = "\n------------------------------------\n" ;
var artist ="Wassily Kandinsky \n";


function sound()
{
g_fsoundmode = !g_fsoundmode;
if (g_fsoundmode)
{
document.images["soundbutton"].src="images/cpsound_active.gif";
}
else
{
document.images["soundbutton"].src="images/cpsound.gif";
}
}

function fade()
{
g_ffademode = !g_ffademode;
if (g_ffademode)
{
document.images["fadebutton"].src="images/cpfade_active.gif";
}
else
{
document.images["fadebutton"].src="images/cpfade.gif";
}
}


function ChangeImage(fFwd)
{
if (fFwd)
{
if (++g_iimg==g_end){
g_iimg=0;
window.clearTimeout(window.tt);
}
}
else
{
if (g_iimg==0)
g_iimg=g_imax;
g_iimg--;
}
Update();
}

function getobject(obj){
if (document.getElementById)
return document.getElementById(obj)
else if (document.all)
return document.all[obj]
}

var iebrowser=document.all; 
function Update(){
   if(iebrowser && g_ffademode){
     document.getElementById('placeholder').style.filter="blendTrans(duration=1)";
     document.getElementById('placeholder').filters.blendTrans.apply();
     getobject("placeholder").src = "images/" + p_array["files"][g_iimg] + ".jpg";
     document.getElementById('placeholder').filters.blendTrans.play();
	 
     getobject("desc").innerHTML =  p_array["desc"][g_iimg] +  " - " + p_array["dates"][g_iimg]; 
	 getobject("ititle").innerHTML =  p_array["titles"][g_iimg]; 
	 
 	 getobject("pix").innerHTML = p_array["price"][g_iimg]; 
	 getobject("buyimage").src = "images/" + p_array["files"][g_iimg] + "_sm.jpg";
	 getobject("buydesc").innerHTML = p_array["desc"][g_iimg] + " - " + p_array["dates"][g_iimg]; 
	 getobject("buytitle").innerHTML = p_array["titles"][g_iimg]; 
	 getobject("descimage").src = "images/" + p_array["files"][g_iimg] + "_sm.jpg";
	 getobject("desctitle").innerHTML =  p_array["titles"][g_iimg]; 
	 getobject("descdesc").innerHTML =  p_array["desc"][g_iimg] + " - " + p_array["dates"][g_iimg]; 
     getobject("inquiretitle").innerHTML = p_array["titles"][g_iimg]; 
     getobject("inquiredesc").innerHTML=  p_array["desc"][g_iimg];  
     // getobject("inquiredim").innerHTML=  p_array["dims"][g_iimg]; 
     getobject("inquiredate").innerHTML=  p_array["dates"][g_iimg];  
     getobject("inquireimage").innerHTML = "images/" + p_array["files"][g_iimg] + "_sm.jpg";
     document.cForm.fm_message.value  = artist + p_array["titles"][g_iimg] + " - " + p_array["dates"][g_iimg] + separator; 

	// getobject("longdesc").innerHTML =  p_array["longdesc"][g_iimg]; 
    }
  else
    {   // fix redundancy
     getobject("placeholder").src = "images/" + p_array["files"][g_iimg] + ".jpg";
	 getobject("desc").innerHTML = p_array["desc"][g_iimg] + " - " + p_array["dates"][g_iimg]; 
 	 getobject("ititle").innerHTML =  p_array["titles"][g_iimg];  
	 getobject("pix").innerHTML = p_array["price"][g_iimg]; 
	 getobject("buyimage").src = "images/" + p_array["files"][g_iimg] + "_sm.jpg";
	 getobject("buydesc").innerHTML = p_array["desc"][g_iimg] + " - " + p_array["dates"][g_iimg]; 
	 getobject("buytitle").innerHTML = p_array["titles"][g_iimg]; 
	 getobject("descimage").src = "images/" + p_array["files"][g_iimg] + "_sm.jpg";
	 getobject("desctitle").innerHTML=  p_array["titles"][g_iimg]; 
	 getobject("descdesc").innerHTML=  p_array["desc"][g_iimg] + " - " + p_array["dates"][g_iimg]; 
     getobject("inquiretitle").innerHTML = p_array["titles"][g_iimg]; 
     getobject("inquiredesc").innerHTML=  p_array["desc"][g_iimg];  
   // getobject("inquiredim").innerHTML=  p_array["dims"][g_iimg]; 
     getobject("inquiredate").innerHTML=  p_array["dates"][g_iimg];     
     getobject("inquireimage").src = "images/" + p_array["files"][g_iimg] + "_sm.jpg";
     document.cForm.fm_message.value  = artist + p_array["titles"][g_iimg] + " - " + p_array["dates"][g_iimg] + separator; 
	// getobject("longdesc").innerHTML =  p_array["longdesc"][g_iimg]; 
	}
}


function updo(vx)
{
g_dwTimeOutSec = vx; 
}


function Play()
{
txz =document.getElementById('display1').value;
updo(txz);
g_fPlayMode = !g_fPlayMode;
if (g_fPlayMode)
{
Next();
document.images["jsbutton"].src="images/slidebutton_on.gif";
}
else
{
g_iimg=g_iimg;
window.clearTimeout(window.tt);
document.images["jsbutton"].src="images/slidebutton_off.gif";
}
}


function onimgload(ix)
{
g_end=ix;
if (g_fPlayMode)
  {
 
  tt=window.setTimeout("Tick()", g_dwTimeOutSec*1000);
  }
}

function Tick() 
{
if (g_fPlayMode)
Next();

}

function backto() 
{
;
}

function Prev()
{
ChangeImage(false);
}
function Next()
{
ChangeImage(true);
}

var iebrowser=document.all; 
function showPic (whichpic) { 
if (g_fPlayMode)
{
;
}
else
  {
   	 var str= whichpic.id;
    var pxid= str.substr(1,2);
	if (document.getElementById) { 
	  if(iebrowser && g_ffademode){
        document.getElementById('placeholder').style.filter="blendTrans(duration=1)";
		document.getElementById('placeholder').filters.blendTrans.apply();
	 	document.getElementById('placeholder').src = "images/" + p_array["files"][pxid] + ".jpg"; 
        document.getElementById('placeholder').filters.blendTrans.play();
        }
	 else {	document.getElementById('placeholder').src = "images/" + p_array["files"][pxid] + ".jpg";   }	

  	if (whichpic.title) { 
	 var str= whichpic.id;
     var pxid= str.substr(1,2);
	document.getElementById('desc').childNodes[0].nodeValue  = p_array["desc"][pxid] + " - " + p_array["dates"][pxid];   
	document.getElementById('ititle').childNodes[0].nodeValue = p_array["titles"][pxid];  
    document.getElementById('pix').childNodes[0].nodeValue = p_array["price"][pxid]; 
    document.getElementById('buyimage').src = "images/" + p_array["files"][pxid] + "_sm.jpg";
    document.getElementById('buytitle').childNodes[0].nodeValue = p_array["titles"][pxid]; 
    document.getElementById('buydesc').childNodes[0].nodeValue  = p_array["desc"][pxid] + " - " + p_array["dates"][pxid];  
    document.getElementById('descimage').src = "images/" + p_array["files"][pxid] + "_sm.jpg";
	document.getElementById('desctitle').childNodes[0].nodeValue = p_array["titles"][pxid]; 
    document.getElementById('descdesc').childNodes[0].nodeValue = p_array["desc"][pxid] + " - " + p_array["dates"][pxid]; 
    document.getElementById('inquireimage').src = "images/" + p_array["files"][pxid] + "_sm.jpg";
    document.getElementById('inquiretitle').childNodes[0].nodeValue = p_array["titles"][pxid]; 
    document.getElementById('inquiredesc').childNodes[0].nodeValue =  p_array["desc"][pxid];  
   // document.getElementById('inquiredim').childNodes[0].nodeValue =  p_array["dims"][pxid];  
    document.getElementById('inquiredate').childNodes[0].nodeValue =  p_array["dates"][pxid]; 
    document.cForm.fm_message.value  = artist + p_array["titles"][pxid] + " - " + p_array["dates"][pxid] + separator; 

//	document.getElementById('longdesc').childNodes[0].nodeValue =  p_array["longdesc"][pxid]; 
  	} else { 
			document.getElementById('desc').childNodes[0].nodeValue = whichpic.childNodes[0].nodeValue; 
		} 
		if (g_fPlayMode)
		{ 
		Play();
		}
   	return false; 
	} else { 

		return true; 
	} 
  }	
}

/////////////// SOUND ///////////////
var sndEl=""  // for no autostart
var sndE2="sound.mp3"  //Set to name and path of your sound file
var music_on="images/cpsound_active.gif"		//Set to image to display while music is on
var music_off="images/cpsound.gif"	//Set to image to display while music is off
var active_img="images/cpsound_on.gif"	//Set to image to display while image is hovered

///////////////Stop Editing///////////////

var da=document.all
var preload=[music_on, music_off, active_img]
var preloading=new Array();
for (var i_tem = 0; i_tem < preload.length; i_tem++){
preloading[i_tem]=new Image();
preloading[i_tem].src=preload[i_tem]
}

function textReveal(el, state){
var text=da? da.text : document.getElementById('text')

el.src=state=='on'? active_img : el.lowsrc
}

function toggleSound(el){
var text=da? da.text : document.getElementById('text')
if (da&&da.sound&&da.sound.src!==''){
da.sound.src=''
el.lowsrc=music_off

}
else if (document.getElementById('snd')){
sndE2=document.getElementById('snd')
document.getElementById('sndC').removeChild(sndE2)
el.lowsrc=music_off

}
else if (da&&da.sound&&da.sound.src==''){
da.sound.src=sndE2
el.lowsrc=music_on

}
else {
document.getElementById('sndC').appendChild(sndE2)
el.lowsrc=music_on

}
}

function inita()
{
document.getElementById('pix').childNodes[0].nodeValue = p_array["price"][0]; 
document.getElementById('buyimage').src = "images/" + p_array["files"][0] + "_sm.jpg";
document.getElementById('buydesc').childNodes[0].nodeValue = p_array["desc"][0] + " - "  + p_array["dates"][0]; 
document.getElementById('buytitle').childNodes[0].nodeValue = p_array["titles"][0]; 
document.getElementById('descimage').src = "images/" + p_array["files"][0] + "_sm.jpg";
document.getElementById('desctitle').childNodes[0].nodeValue =  p_array["titles"][0]; 
document.getElementById('descdesc').childNodes[0].nodeValue =  p_array["desc"][0] + " - " + p_array["dates"][0]; 
document.getElementById('inquireimage').src = "images/" + p_array["files"][0] + "_sm.jpg";
document.getElementById('inquiretitle').childNodes[0].nodeValue = p_array["titles"][0]; 
document.getElementById('inquiredesc').childNodes[0].nodeValue =  p_array["desc"][0];  
// document.getElementById('inquiredim').childNodes[0].nodeValue =  p_array["dims"][0];  
document.getElementById('inquiredate').childNodes[0].nodeValue =  p_array["dates"][0];  

document.cForm.fm_message.value  = artist + p_array["titles"][0] + " - " + p_array["dates"][0] + separator;  

// document.getElementById('longdesc').childNodes[0].nodeValue =  p_array["longdesc"][0]; 
g_dwTimeOutSec=5;
}

function getposOffset(overlay, offsettype){
var totaloffset=(offsettype=="left")? overlay.offsetLeft : overlay.offsetTop;
var parentEl=overlay.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}

function overlay(curobj, subobjstr, opt_position){
if (document.getElementById){
var subobj=document.getElementById(subobjstr)
subobj.style.display=(subobj.style.display!="block")? "block" : "none"
var xpos=getposOffset(curobj, "left")+((typeof opt_position!="undefined" && opt_position.indexOf("right")!=-1)? -(subobj.offsetWidth-curobj.offsetWidth) : 0) 
var ypos=getposOffset(curobj, "top")+((typeof opt_position!="undefined" && opt_position.indexOf("bottom")!=-1)? curobj.offsetHeight : 0)
subobj.style.left=xpos+"px"
subobj.style.top=ypos-0+"px"
return false
}
else
return true
}

function overlayclose(subobj){
document.getElementById(subobj).style.display="none"
}

