jQuery.noConflict();
var theatre$ = jQuery;

theatre$.theatre_loader = {
	init: function() {
		for (module in theatre$.theatre_loader) {
			if (theatre$.theatre_loader[module].init)
				theatre$.theatre_loader[module].init();
		}
	}
};

theatre$(document).ready(theatre$.theatre_loader.init);

var num=0;
var imgPreLoader=new Array();
var active="li.li_1 img";
theatre$.theatre_loader.click = {

	init: function() {
		theatre$('A.loader').bind('click', this.click)
		theatre$('A.loader_profile').bind('click', this.click_profile)
	},

	click: function() {
		var st=theatre$(document.body).scrollTop();
		st = (!st)?document.documentElement.scrollTop:st;
		var l=this.href;
		var h=theatre$(window).height();
		var target=theatre$(this).attr('id');
		theatre$('body').append("<div id='contents_block' style='position:absolute;top:"+st+"px;left:0;display:block;width:100%;height:100%;z-index:1000;text-align: left;'><div id='background' style='position:absolute;top:0;left:0;display:block;width:100%;height:100%;background-color:#000;z-index:1001;cursor:hand;color:#ccc;line-height:2.0em;font-weight:bold;text-align:center;'></div><div id='contents_main' style='position:relative;margin:0 auto;color:#fff;text-align:left;z-index:1002'></div></div>")
		theatre$('#background').css({opacity: 0, height: h});
		theatre$('#background').fadeTo("fast",0.8, function(){
			theatre$('#contents_main').load(l,function(text,status){
				theatre$('#contents_main').css({opacity: 0});
				var imageW=theatre$('#item-main').width();
				var imageH=theatre$('#contents_main').height();
				theatre$('#contents_main').width(imageW);
				var t=(h/2)-(imageH/2);
				var t=(t<0)?0:t;
				theatre$('#contents_main').css({top: t});
				theatre$(active).fadeTo("fast",0.5);
				theatre$('#rewind a').fadeTo("fast",0.25);
				if(theatre$('#items').width()<=imageW){
					theatre$('#forward a').fadeTo("fast",0.25);
				}
				theatre$('#contents_main').fadeTo("fast",1);
			});
		});
		theatre$('#background').click( function() {
			theatre$('#contents_main').remove();
			theatre$(this).fadeTo("fast",0, function(){theatre$('#contents_block').remove();});
		});
		return false;
	},

	click_profile: function() {
		var st=theatre$(document.body).scrollTop();
		st = (!st)?document.documentElement.scrollTop:st;
		var l=this.href;
		var h=theatre$(window).height();
		var target=theatre$(this).attr('id');
		theatre$('body').append("<div id='contents_block' style='position:absolute;top:"+st+"px;left:0;display:block;width:100%;height:100%;z-index:1000;text-align: left;'><div id='background' style='position:absolute;top:0;left:0;display:block;width:100%;height:100%;background-color:#000;z-index:1001;cursor:hand;color:#ccc;line-height:2.0em;font-weight:bold;text-align:center;'></div><div id='contents_main' style='position:relative;margin:0 auto;color:#fff;text-align:left;z-index:1002'></div></div>")
		theatre$('#background').css({opacity: 0, height: h});
		theatre$('#background').fadeTo("fast",0.8, function(){
			theatre$('#contents_main').load(l,function(text,status){
				theatre$('#contents_main').css({opacity: 0});
				var imageW=theatre$('#profile-main').width();
				var imageH=theatre$('#contents_main').height();
				theatre$('#contents_main').width(imageW);
				var t=(h/2)-(imageH/2);
				var t=(t<0)?0:t;
				theatre$('#contents_main').css({top: t});
				theatre$(active).fadeTo("fast",0.5);
				theatre$('#contents_main').fadeTo("fast",1);
			});
		});
		theatre$('#background').click( function() {
			theatre$('#contents_main').remove();
			theatre$(this).fadeTo("fast",0, function(){theatre$('#contents_block').remove();});
		});
		return false;
	}

};

theatre$.theatre_loader.resize = {
	init: function() {
		theatre$(window)
		.bind('resize', this.resize)
		.bind('scroll', this.scroll)
	},
	resize: function() {
		if(theatre$('#background').css('opacity')!=undefined){
			var h=theatre$(window).height();
			theatre$('#background').css({height: h});
			var t=h/2-(theatre$('#contents_main').height()/2);
			var t=(t<0)?0:t;
			theatre$('#contents_main').css({top: t});
		}
	},
	scroll: function() {
		if(theatre$('#background').css('opacity')!=undefined){
			var st=theatre$(document.body).scrollTop();
			st = (!st)?document.documentElement.scrollTop:st;
			theatre$('#contents_block').css({top: st});
		}
	}
};
function image_close() {
	if(active)theatre$(active).fadeTo("fast",1);
	active="li.li_1 img";
	theatre$('#contents_main').remove();
	theatre$('#background').fadeTo("fast",0, function(){theatre$('#contents_block').remove();});
};

var count = 0;
var w = 650;
function image_rewind() {
	var l=theatre$('#items').css('left');
	l=(l=='auto')?0:parseInt(l);
	theatre$('#forward a').fadeTo("fast",1);
	p=l+650;
	if(p>=0){
		p=0;
		theatre$('#rewind a').fadeTo("fast",0.25);
	}else{
		theatre$('#rewind a').fadeTo("fast",1);
	}
	theatre$('#items').animate({ left:p },"slow");
};

function image_forward() {
	var w=theatre$('#items').width();
	if(w>650){
		w-=650;
		var l=theatre$('#items').css('left');
		l=(l=='auto')?0:parseInt(l);
		theatre$('#rewind a').fadeTo("fast",1);
		p=l-650;
		if(p<=-w){
			p=-w;
			theatre$('#forward a').fadeTo("fast",0.25);
		}else{
			p=p;
		}
		theatre$('#items').animate({ left:p },"slow");
	}
};

function image_change(n,u) {
	if(active)theatre$(active).fadeTo("fast",1);
	active = 'li.'+n+' img';
	theatre$(active).fadeTo("fast",0.5);
	theatre$('#item-main').fadeTo("fast",0, function(){
		theatre$('#item-main').load(u,function(text,status){
			theatre$('#item-main').fadeTo("fast",1);
		});
	});
};