if( typeof(Kojoe) == 'undefined' ){
	var Kojoe = {
		VERSION:1,
		getBrowserSize:function()
		{
			var w,h;
			if(window.innerWidth){
				w = window.innerWidth;
				h = window.innerHeight;
			}else if( document.documentElement
				&& ( document.documentElement.clientWidth != 0 )
			){
				w = document.documentElement.clientWidth;
				h = document.documentElement.clientHeight;
			}else if(document.body){
				w = document.body.clientWidth;
				h = document.body.clientHeight;
			}

			return new Array( w, h );
		}
	};

	Kojoe.Options = Class.create();
	Object.extend( Kojoe.Options, {
		BG_PICTURE_ORIG_WIDTH:null,
		BG_PICTURE_ORIG_HEIGHT:null,
		USE_LANG_SELECT:false,
		CURRENT_LANG:'en',
		ASSET_PATH:'assets/'
	});
}



Kojoe.Twitter = Class.create();
Object.extend( Kojoe.Twitter,
{
	init:function()
	{
		getTwitters( 'text-twitter', { 
			id:'iamkojoe', 
			clearContents:true, 
			count:1, 
			withFriends:true,
			ignoreReplies:false,
			template:'<p>%text%<span><a href="http://twitter.com/%user_screen_name%/statuses/%id%">%time%</a></span></p>'
		});
	}
});

Kojoe.Tuesdays = Class.create();
Object.extend( Kojoe.Tuesdays,
{
	bg:null,
	init:function()
	{
		this.bg = $('tuesdays-bg');
		this.resize();
	},
	resize:function()
	{
		var size = Kojoe.getBrowserSize();
		var w,h;
		w = size[0];
		h = size[1];

		this.bg.style.width = w +'px';
		this.bg.style.height = h +'px';
	}
});

Kojoe.Background = Class.create();
Object.extend( Kojoe.Background,
{
	container:null,
	bg:null,
	init:function( list )
	{
		this.container = $('bg-picture');

		var n = Math.floor( Math.random() * list.length );
		var span = document.createElement('span');
		span.setAttribute( 'class', 'enclosure-image enclosure' );
		var img = document.createElement('img');
		img.setAttribute( 'width', '1280' );
		img.setAttribute( 'height', '768' );
		img.setAttribute( 'src', list[n] );
		span.appendChild(img);
		this.container.appendChild(span);

		this.bg = this.container.getElementsByTagName('img')[0];

		Element.removeClassName( this.container, 'hidden' );

		Kojoe.Options.BG_PICTURE_ORIG_WIDTH = parseInt( this.bg.getAttribute('width'), 10 );
		Kojoe.Options.BG_PICTURE_ORIG_HEIGHT = parseInt( this.bg.getAttribute('height'), 10 );

		this.resize();
	},
	resize:function()
	{
		var size = Kojoe.getBrowserSize();
		var ratio = Kojoe.Options.BG_PICTURE_ORIG_HEIGHT / Kojoe.Options.BG_PICTURE_ORIG_WIDTH;
		var w,h;
		w = size[0];
		h = w * ratio;
		if( h < size[1] ){
			ratio = Kojoe.Options.BG_PICTURE_ORIG_WIDTH / Kojoe.Options.BG_PICTURE_ORIG_HEIGHT;
			h = size[1];
			w = h * ratio;
			this.bg.style.left = (( size[0] - w ) / 2 ) +'px';
		}else{
			this.bg.style.left = '0px';
		}

		this.bg.style.top = (( size[1] - h ) / 2 ) +'px';
		this.bg.setAttribute( 'width', w );
		this.bg.setAttribute( 'height', h );
	}
});

Kojoe.Lang = Class.create();
Object.extend( Kojoe.Lang,
{
	selector:null,
	init:function()
	{
		var c = $('lang-selector');
		this.selector = c.getElementsByTagName('a')[0];
	},
	toggle:function()
	{
		var c = $('entries');
		var list = c.getElementsByTagName('div');
		var i = 0;
		while( i < list.length ){
			if( Element.hasClassName( list[i], 'entry' )){
				var e = list[i].getElementsByTagName('div');
				var j = 0;
				while( j < e.length ){
					if( Element.hasClassName( e[j], 'body' )){
						if( Element.hasClassName( e[j], Kojoe.Options.CURRENT_LANG )){
							Element.addClassName( e[j], 'hidden' );
						}else{
							Element.removeClassName( e[j], 'hidden' );
						}
					}
					j++;
				}
			}
			i++;
		}

		if( Element.hasClassName( this.selector, 'en' )){
			Element.removeClassName( this.selector, 'en' );
			Element.addClassName( this.selector, 'jp' );
		}else{
			Element.removeClassName( this.selector, 'jp' );
			Element.addClassName( this.selector, 'en' );
		}

		Kojoe.Options.CURRENT_LANG = ( Kojoe.Options.CURRENT_LANG == 'jp' ) ? 'en' : 'jp';
	}
});

Kojoe.Form = Class.create();
Object.extend( Kojoe.Form,
{
	params:null,
	init:function( params )
	{
		this.params = params;
	},
	send:function( callback )
	{
		var param = '';
		var i = 0;
		while( i < this.params.length ){
			param += this.params[i].id +'=';
			param += this.params[i].label +'：';
			if( this.params[i].type == 'multitext' ){
				param += "¥r¥n";
			}
			param += $F(this.params[i].id).escapeHTML();
			if( i != ( this.params.length - 1 )) param += '&';

			$(this.params[i].id).disabled = 'disabled';
			i++;
		}

		new Ajax.Request(
			'http://www.iamkojoe.com/mail.php',
			{
				method:'post',
				postBody:param,
				onComplete:callback
			}
		);
	}
});

Kojoe.Window = Class.create();
Object.extend( Kojoe.Window,
{
	open:function( url, options )
	{
		var w = window.open( url, 'WINDOW', options );
		w.focus();
	}
});

Kojoe.Player = Class.create();
Object.extend( Kojoe.Player,
{
	init:function()
	{
		swfobject.embedSWF(
			Kojoe.Options.ASSET_PATH +'swf/player.swf',
			'player-inner',
			'86', '32', '10.0.0',
			Kojoe.Options.ASSET_PATH +'swf/expressInstall.swf',
			{
				path:Kojoe.Options.ASSET_PATH
			},
			{
				menu:'false',
				scale:'noScale',
				allowFullscreen:'true',
				allowScriptAccess:'always',
				bgcolor:'#FFFFFF'
			},
			{
				id:'player'
			}
		);
	}
});
