var animate = true;

function openpicture( base, id )
{
	//alert("id: " + id);
	document.getElementById("content" + id).style.display = "none";
	document.getElementById("largepicture" + id).src = '../pics/' + base + ".jpg";
	document.getElementById("picture" + id).style.display = "block";
}

function closepicture( id )
{
	document.getElementById("picture" + id).style.display = "none";
	document.getElementById("content" + id).style.display = "block";
	return false;
}

var contact1 = "mai";
var asImg = new Array();
var asTitle = new Array();
var asTitleList = new Array();
var asImageLoader = new Array();
var asLoaded = new Array();
var asLoadComplete = 0;
var asCurrent = new Array();
var contact2 = "lto";

function createAutoSlider( img, title, pic, titles )
{
	$(title).innerHTML = 'Loading...';
	var imageLoader = new Image();
	imageLoader.src = pic;
	asImageLoader.push( imageLoader );
	asLoaded.push( false );

	asImg.push( img );
	asTitle.push( title );
	asTitleList.push ( titles );
	asCurrent.push ( 0 );
}

function startAutoSlider()
{
	setTimeout( "checkAutoSlider()", 40 );
}

function checkAutoSlider()
{
	if ( asLoadComplete != asImageLoader.length )
	{
		for ( var i = 0; i < asImageLoader.length; i++ )
		{
			if ( !asLoaded[ i ] && asImageLoader[ i ].complete )
			{
				asLoadComplete++;
				$(asImg[ i ]).src = asImageLoader[ i ].src;
				$(asImg[ i ]).style.display = "block";
				$(asTitle[ i ]).innerHTML = asTitleList[ i ][ 0 ];
			}
		}
		
		if ( asLoadComplete == asImageLoader.length )
			setTimeout( "checkAutoSlider()", 4000 );
		else
			setTimeout( "checkAutoSlider()", 40 );
	}
	else
	{
		for ( var i = 0; i < asCurrent.length; i++ )
		{
			asCurrent[ i ]++;
			if ( asCurrent[ i ] == asTitleList[ i ].length )
			{
				asCurrent[ i ] = 0;
				MochiKit.Visual.Move( asImg[ i ], { x: 225 * ( asTitleList[ i ].length - 1 ), y: 0 } );
			}
			else
				MochiKit.Visual.Move( asImg[ i ], { x: -225, y: 0 } );
				
			$(asTitle[ i ]).innerHTML = asTitleList[ i ][ asCurrent[ i ] ];
		}
		setTimeout( "checkAutoSlider()", 4000 );
	}
}

var contact3 = "subject";
var dm = "&#110;&#101;&#119;&#098;&#117;&#114;&#121;&#109;&#114;&#099;&#046;&#099;&#111;&#046;&#117;&#107;"

function contact( to, sub )
{
	var brk = '&#064;'
	var url = contact1 + contact2 + ":" + to + brk + dm;
	if ( sub != null )
		url += '?' + contact3 + '=' + sub;
	location.href = url;
}

function showAddComment()
{
	animate = false;
	document.getElementById("addcommenth").style.display = "block";
	document.getElementById("addcommentc").style.display = "block";
	scrollIntoView( "addcommenth" );
	document.getElementById("cinterest").focus();
	return false;
}

function validateComment( form )
{
	with ( form )
	{
		if ( bdetails.value.length == 0 )
		{
			alert( "You need to enter a comment" );
			bdetails.focus();
			return false;
		}
	}
	return true;
}

var ss_STEPS = 10;
var ss_stepsize;
var ss_interval;

function scrollIntoView( dest )
{
	var destinationLink = document.getElementById( dest );
	
    // Find the destination's position
    var destx = destinationLink.offsetLeft; 
    var desty = destinationLink.offsetTop;
    var thisNode = destinationLink;
    while (thisNode.offsetParent && 
          (thisNode.offsetParent != document.body)) 
    {
		thisNode = thisNode.offsetParent;
		destx += thisNode.offsetLeft;
		desty += thisNode.offsetTop;
    }
  
    // Stop any current scrolling
    clearInterval( ss_interval );
  
    cypos = getCurrentYPos();
  
    ss_stepsize = parseInt((desty-cypos) / ss_STEPS);
    ss_interval = setInterval('scrollWindow('+ss_stepsize+','+desty+')',10);
}
  
function scrollWindow (scramount,dest) 
{
    wascypos = getCurrentYPos();
    isAbove = (wascypos < dest);
    window.scrollTo(0,wascypos + scramount);
    iscypos = getCurrentYPos();
    isAboveNow = (iscypos < dest);
    if ((isAbove != isAboveNow) || (wascypos == iscypos)) 
    {
      // if we've just scrolled past the destination, or
      // we haven't moved from the last scroll (i.e., we're at the
      // bottom of the page) then scroll exactly to the link
      window.scrollTo(0,dest);
      // cancel the repeating timer
      clearInterval(ss_interval);
    }
}

function getCurrentYPos() 
{
    if (document.body && document.body.scrollTop)
      return document.body.scrollTop;
    if (document.documentElement && document.documentElement.scrollTop)
      return document.documentElement.scrollTop;
    if (window.pageYOffset)
      return window.pageYOffset;
    return 0;
}
