﻿var augen = function ()
{
	var imgdata;
	var img_count;
	var current = 0;
		
	var img_findnext = function(id)
	{
		if(id<img_count-1) return id+1;
		else return 0;
	};
	
	var img_findprev = function(id)
	{
		if(id>0) return id-1;
		else return img_count-1;
	};
	
	var img_adjust = function()
	{
		if( imgdata[current].height > 580)
		{
			var l = '410px';
			var t = '60px';
		}
		else
		{
			var l = Math.round(document.viewport.getWidth()/2 - imgdata[current].width/2) + 'px';
			var t = '160px';
		}
		document.getElementById("imagewrapper").style.width = imgdata[current].width +'px';
		//$('content').setStyle({left:l,top:t});
	};
	
	return {
		init:function(data)
		{
			img_count = data.length;
			imgdata = data;
			window.onresize = img_adjust;
			augen.img_display(0);
			augen.photos();
		},
			
		img_display:function(id)
		{
			Effect.Fade('content', {duration:.2});
			var src = imgdata[id].url;
			var title = (id+1) + '/' + img_count;
			current = id;
			
			window.location.href = '#'+id;
			
			window.setTimeout(function(){
				var imghtml = '<img src="'+src+'" id="photo" onLoad="augen.img_init()" />';
				$('photo').replace(imghtml);
				
				$('subtitle').update(title);
				if(title=='') $('subtitle').setStyle({display:'none'}); else $('subtitle').setStyle({display:'block'});
			},200);
		},
		
		img_init:function()
		{
			img_adjust();
			new Effect.Appear('content', {queue:'end',duration:0.3});
		},
		
		img_next:function()
		{
			augen.img_display(img_findnext(current));
		},
		
		img_prev:function()
		{
			augen.img_display(img_findprev(current));
		},
				
		contact:function()
		{	
			$('menu0', 'menu1', 'menu2').invoke('show');
			$('menu1').hide();
			$('fuss').hide();			
			$('contact', 'links', 'photo', 'subtitle','next','prev').invoke('hide');
			$('contact').show();
		},
		
		links:function()
		{
			$('menu0', 'menu1', 'menu2').invoke('show');
			$('menu2').hide();
			$('fuss').hide();
			$('contact', 'links', 'photo', 'subtitle','next','prev').invoke('hide');
			$('links').show();
		},
		
		photos:function()
		{
			$('menu0', 'menu1', 'menu2').invoke('show');
			$('menu0').hide();
			$('fuss').show();
			$('contact', 'links', 'photo', 'subtitle','next','prev').invoke('hide');
			$('photo', 'subtitle','next','prev').invoke('show');
		}
	}
}();
