var player = {
	plItems:4, plItem:0, plOn:false, title:'', listener:null,
	init:function()
	{
		this.listener = new Object();
		this.listener.onInit = function() { }
		this.listener.onUpdate = function() {
				if( this.isPlaying != 'true' && player.plOn) { player.playstop(); player.playstop(); }
				if( player.title != this.id3_songname && player.plOn && this.isPlaying == 'true' ) $('#sndswitch').attr( 'title', this.id3_songname);
			}
		
		var o = document.createElement( 'div');
		o.innerHTML = '<object id="myFlash" type="application/x-shockwave-flash" data="/js/fpjs.swf" width="1" height="1"><param name="movie" value="/js/fpjs.swf"><param name="AllowScriptAccess" value="always"><param name="FlashVars" value="listener=player.listener&amp;interval=500"></object>';
		$('body').append(o);
	},
	playstop:function()
	{
		if( this.plOn)
		{
			this.plOn = false;
			document.getElementById('myFlash').SetVariable( 'method:stop', '');
			$('#sndflag').html( 'n');
			$('#sndswitch').attr( 'title', '');
			this.plItem = (this.plItem + 1) % this.plItems;
		}
		else
		{
			document.getElementById('myFlash').SetVariable( 'method:setUrl', '/upl/media/bgm'+(this.plItem+1)+'.mp3');
			document.getElementById('myFlash').SetVariable( 'method:play', '');
			$('#sndflag').html( 'ff');
			document.getElementById('myFlash').SetVariable( 'enabled', 'true');
			this.plOn = true;
		}
	}
};

var page = {
	cnt:0, bs:false, ab:null, nb:null, pos:0, tm:null, to:null, postinit:null,
	go:function( url)
	{
		if( this.bs) return;
		
		this.ab = document.getElementById('cbl' + this.cnt);
		this.nb = document.getElementById('cbl' + (1-this.cnt));
		$('#aldr').show();
		$.post( url, {ajax:'int'}, page.loaded);
	},
	loaded:function(data)
	{
		if( this.tm != null) clearInterval(this.tm);
		if( this.to != null) clearTimeout(this.to);
		this.bs = true;

		data = data.split(/###%###/); 
		$('#co' + (1-page.cnt)).html( data[2]);
		$('#co' + (1-page.cnt)+' a.pint').click( function(e) { page.go(e.target.parentNode.href); return false; });
		$('#co' + (1-page.cnt)+' a.int').click( function(e) { page.go(e.target); return false; });

		document.title = data[0];
		$('#topmenu').html( data[1]);
		$('#topmenu a.int').click( function(e) { page.go(e.target); return false; });
		$('#aldr').hide();
		page.move();
	},
	move:function()
	{
		this.cnt = (this.cnt + 1) % 2;
		this.pos = 100;
		this.nb.style.left = '100%';
		this.nb.style.display = 'block';
		this.updatescroll();
		this.tm = setInterval( 'page.posdo()', 12);
		this.movedo();
	},
	movedo:function()
	{
		this.ab.style.left = -(100 - this.pos) + '%';
		this.nb.style.left = this.pos + '%';
		if( this.pos == 0) this.moveend();
		else this.to = setTimeout( 'page.movedo()', 15)
	},
	moveend:function()
	{
		document.getElementById('co' + (1-this.cnt)).innerHTML = '';
		this.ab.style.display = 'none';
		this.bs = false;
		if( this.postinit != null) { eval(this.postinit); this.postinit = null; }
	},
	posdo:function()
	{
		this.pos -= 5;
		if( this.pos <= 0) { this.pos = 0; clearInterval(this.tm); }
	},
	updatescroll:function()
	{
		$('#co'+ this.cnt).jScrollPane({showArrows:true,scrollbarWidth:11,arrowSize:16});
	}
};

var isLoaded = false;
$(document).ready( function()
{
	isLoaded = true;
	$('#co0').jScrollPane({showArrows:true,scrollbarWidth:11,arrowSize:16});
	player.init();
	
	$('#sndswitch').click( function() { player.playstop(); return false; });
	$('body a.int').click( function(e) { page.go(e.target); return false; });
	$('body a.pint').click( function(e) { page.go(e.target.parentNode.href); return false; });
	
	if( page.postinit != null) { eval(page.postinit); page.postinit = null; }

	$('.ddmenu > li').mouseover( function() { $(this).addClass('over') }).mouseout( function() { $(this).removeClass('over') });
	
});

function toCart(id)
{
	$('#aldr').show();
	$.post( '/shop/?ajax=x1', { op:'toCart', id:id }, function(a) { $('#cb'+id).addClass('bks'); $('#cartflag').html(a); $('#aldr').hide(); } );
}

function removeCart(id)
{
	$('#aldr').show();
	$.post( '/shop/?ajax=x1', { op:'removeCart', id:id }, function(a) { $('#cartflag').html(a); $('#aldr').hide(); page.go('/shop/cart.html'); } );
}

