AIM = {

    frame : function(c) {

        var n = 'f' + Math.floor(Math.random() * 99999);
        var d = document.createElement('DIV');
        d.innerHTML = '<iframe style="display:none" src="/contact.ajax.php" id="'+n+'" name="'+n+'" onload="AIM.loaded(\''+n+'\')"></iframe>';
        document.body.appendChild(d);

        var i = document.getElementById(n);
        if (c && typeof(c.onComplete) == 'function') {
            i.onComplete = c.onComplete;
        }

        return n;
    },

    form : function(f, name) {
        f.setAttribute('target', name);
    },

    submit : function(f, c) {
        AIM.form(f, AIM.frame(c));
        if (c && typeof(c.onStart) == 'function') {
            return c.onStart();
        } else {
            return true;
        }
    },

    loaded : function(id) {
        var i = document.getElementById(id);
        if (i.contentDocument) {
            var d = i.contentDocument;
        } else if (i.contentWindow) {
            var d = i.contentWindow.document;
        } else {
            var d = window.frames[id].document;
        }
        if (d.location.href == "about:blank") {
            return;
        }

        if (typeof(i.onComplete) == 'function') {
            i.onComplete(d.body.innerHTML,i);
        }
    }

}

function startCallback() 
{
   // make something useful before submit (onStart)
   //alert("startCallback");
   return true;
}

function completeCallback(response,frame) 
{
   // make something useful after (onComplete)
   //document.getElementById('nr').innerHTML = parseInt(document.getElementById('nr').innerHTML) + 1;
   $('fc').innerHTML = response;
   if(String(response).substr(1,3) == 'div' && typeof(pageTracker) == 'object')
   {
   	pageTracker._trackPageview("/contact_response");	
   }
   document.body.removeChild(frame);
}

function Shuffle(id)
{
	if(shuffle_available && doShuffle)
	{
		new Ajax.Request('/shuffle.ajax.php',{ onSuccess: 	function(transport)
																		  	{
																		  		new Effect.Fade(id,{ duration: 1.0, afterFinish: function () { $(id).innerHTML = transport.responseText; new Effect.Appear(id,{duration: 2.0, afterFinish: initLightbox });  } });
																		   }
													     });		
	}		     
	return true;
}

var active_shuffle;
var shuffle_available = true;
var doShuffle = true;

function StartShuffle(id)
{
	if(shuffle_available && doShuffle)
	{
		Shuffle(id);
	}
}

function StopShuffle()
{
	window.clearInterval(active_shuffle);
}
function UnableShuffle()
{
	shuffle_available = false;
	doShuffle = false;
}

var pLastPosition = 0;

function ImgMove(pos)
{
	pImagePosition += pos;
	if(pImagePosition < 0) pImagePosition = pImages.length - 1;
	if(pImagePosition > pImages.length-1) pImagePosition = 0;
	$('pImg').src = pImagePrevDir + pImages[pImagePosition][0];
	$('pImg').setAttribute("alt",pImages[pImagePosition][1]);	
	$('pImg').setAttribute("title",pImages[pImagePosition][1]);
	$('cImg_' + pLastPosition).setAttribute("coords", "0,0,0"); 
	$('cImg_' + pImagePosition).setAttribute("coords", "12,12,5"); 
	pLastPosition = pImagePosition;
 		
}

var __ShowImgInfo = true;

function ToggleImgInfo(a)
{
	if(a == __ShowImgInfo)
	{
		__ShowImgInfo = !a;
		Effect.toggle('img_action', 'appear', { delay: 0.5, duration: 0.5 });
	}
}

