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 MM_displayStatusMsg(msgStr) { //v1.0
  status=msgStr;
  document.MM_returnValue = true;
}

function bookmark(){
var title = 'yalimaytul.com';
var url = location.protocol+'//'+location.host+'/';
if (document.all)
	window.external.AddFavorite(url,title);
if (window.sidebar)
	window.sidebar.addPanel(title, url,""); 
}

function openWin( windowURL, windowName, windowFeatures) {
     window.open( windowURL, windowName, windowFeatures ) ;
}

function closeWin( windowURL ) {
	window.close( windowURL );
}

function slideshow(gallery){
	openWin('/painting/slideshow.shtml?gallery='+gallery,'slideshow','toolbar=no,menubar=no,scrollbars=yes,status=no,resizable=yes,width=750,height=600,top=(screen.availHeight-600)/2, left=(screen.availWidth-600)/2');
}

function gallery(galleryName, contents){
	this.galleryName = galleryName;
	this.contents = new Array();
	this.getGalleryName = function(){
		return galleryName;
	}
	this.getPicpath = function(){
		return galleries_base_url + this.getGalleryName() + '/pics/';
	}
	
	this.getThumbpath = function(){
		return galleries_base_url + this.getGalleryName() + '/thumbs/';
	}
	
	this.getContent = function(index){
		return contents[index];
	}
	
	this.getContentLength = function(){
		return contents.length;
	}
	
	this.findIndex = function(painting){
		for(var index = 0; index<contents.length; index++){
			if(this.getContent(index).getName() === painting){
				return index;
			}
		}
		return 0;
	}
	this.getIndex = function(index){
		return contents[index].getName();
	}
}

function painting(name,text,image,stryear,size,description,collection){
	this.text = text;
	this.name = name;
	this.image = image;
	this.stryear = stryear;
	this.size = size;
	this.description = description;
	this.collection = collection;
	this.getName = function(){
		return name;
	}
	this.getText = function(){
		return text;
	}
	this.getImage = function(){
		return image;
	}
	this.getStrYear = function(){
		return stryear;
	}
	this.getSize = function(){
		return size;
	}
	this.getDescription = function(){
		return description;
	}
	this.getCollection = function(){
		return collection;
	}
}


function votesie_popup () {
 var vurl_string = 'http://www.yalimaytul.com/painting/cgi-bin/votesie/votesie.cgi?Question=';
 vurl_string += escape(document.Votesie.Question.value);
 vurl_string += '&ShowResults=Yes&Vote=';
 for (var i = 0; i < document.Votesie.Vote.length; i++){
    if(document.Votesie.Vote[i].checked){
       vurl_string += escape(document.Votesie.Vote[i].value);
       }
    }

  vurl_string += '&headercolor='; vurl_string += escape(document.Votesie.headercolor.value);
  vurl_string += '&headerfontcolor='; vurl_string += escape(document.Votesie.headerfontcolor.value);
  vurl_string += '&pollcolor='; vurl_string += escape(document.Votesie.pollcolor.value);
  vurl_string += '&pollfontcolor='; vurl_string += escape(document.Votesie.pollfontcolor.value);
  vurl_string += '&resultcolor='; vurl_string += escape(document.Votesie.resultcolor.value);
  vurl_string += '&resultfontcolor='; vurl_string += escape(document.Votesie.resultfontcolor.value);
  vurl_string += '&barcolor='; vurl_string += escape(document.Votesie.barcolor.value);
  vurl_string += '&bordercolor='; vurl_string += escape(document.Votesie.bordercolor.value);

 openWin(vurl_string,'Votesie','width=700,height=230,top=(screen.availHeight-600)/2, left=(screen.availWidth-600)/2,toolbar=no,scrollbars=no,resizable=yes,status=no,directories=no,menubar=no,location=no');
 return false; 
}

function create_slideshow_from_gallery(gallery_name){
	var SLIDES = new slideshow("SLIDES");
	SLIDES.timeout = 3000;
	SLIDES.prefetch = -1;
	SLIDES.repeat = true;

	for(var i=0; i<galleries.length; i++){
		if(galleries[i].getGalleryName()==gallery_name){

			for(j=0;j<galleries[i].getContentLength();j++){
				s = new slide();
				s.src =  galleries[i].getPicpath() + galleries[i].getContent(j).getImage();
				s.text = galleries[i].getContent(j).getText()+' (' + galleries[i].getContent(j).getStrYear() +')<br>' + galleries[i].getContent(j).getSize()+'<br><p>' + galleries[i].getContent(j).getDescription() + '</p>' ;
				s.link = '';
				s.filter = '';
				SLIDES.add_slide(s);
			}	
			return SLIDES;
		}
	}
}

function showPainting(gallery_name,painting){
	
	for(var i=0; i<galleries.length; i++)
	{
		if(galleries[i].getGalleryName()==gallery_name)
		{
			var index = galleries[i].findIndex(painting);
			//alert(index);
			document.write("<tableborder='1' cellpadding='7' cellspacing='7'><tr>");
			if(index != 0)
			{
				document.write("<td valign='bottom'> <a href='/painting/showpainting.shtml?gallery=" + gallery_name + "&painting=" + galleries[i].getIndex(index-1) + "'>Previous</a> </td>");
			}
			else
			{
				document.write("<td valign='bottom'> </td>");
			}
			
			document.write("<td><img src='" + galleries[i].getPicpath() + galleries[i].getContent(index).getImage() + "'></td>");
			
			if(index+1 != galleries[i].getContentLength())
			{
				document.write("<td valign='bottom'> <a href='/painting/showpainting.shtml?gallery=" + gallery_name + "&painting=" + galleries[i].getIndex(index+1) + "'>Next</a> </td>");
			}
			else
			{
				document.write("<td valign='bottom'> </td>");
			}
		  document.write("</tr>");
		  document.write("<tr>");
		  document.write("<td></td>");
		  document.write("<td>");
		  document.write( galleries[i].getContent(index).getText() + ' (' + galleries[i].getContent(index).getStrYear());
		  
		  document.write( ')<br/>' + galleries[i].getContent(index).getSize()+ '<br/><p>' );
		  document.write( galleries[i].getContent(index).getDescription() + '</p><p>' );
		  document.write( galleries[i].getContent(index).getCollection() + '</p>' );
		  document.write( "</td><td></td></tr>");
		  document.write("</table>");
		}
	}
}
