//if(Browser.Platform.ipod==true){
//	window.location = 'http://www.brokentone.net/next/iphone/enter';
//}

function gallery_event(){
$$('.gallery_grid').addEvents({
    'mouseenter': function(){
        this.setStyle('z-index', 10); 
		var omfg = this.getElement('img').getStyle('height').toInt(); 
		var cover = function(){this.getElement('.gallery_cover').setStyle('height', 0);};
		cover.delay(500, this);
		this.getElement('.download_list').fade('in'); 
		this.getElement('.download_list').setStyle('top', 70+omfg); 
		this.getElement('.download_list').setStyle('height', 478-75-omfg);
		this.tween('min-height', 478);
    },
    'mouseleave': function(){
        this.setStyle('z-index', 0); 
		this.getElement('.gallery_cover').setStyle('height', 500);
		this.getElement('.download_list').fade('out'); 
		this.tween('min-height', 0);
    }
});
}

function hide_home(){
	if(Browser.Engine.presto==true){
		(function(){$('news_spoiler1').fade('hide');}).delay(1000);
		(function(){$('news_spoiler2').fade('hide');}).delay(500);
		(function(){$('news_spoiler3').fade('hide');}).delay(500);
	}
	$$('img.vector').fade('out');
	//(function(){$$('img.vector').fade('out');}).delay(800);
	$('recent').tween('height', '0');
	$('news_control').tween('height', '0');
	$('shout_control').tween('height', '0');
	$('news_spoiler2').tween('height', '0');
	$('news_spoiler3').tween('width', '0');
	(function(){$('news_spoiler1').tween('width', '0');}).delay(500);
	(function(){$('news_floral').fade('out');}).delay(500);
	(function(){$('news').tween('height', '0');}).delay(1000);
	(function(){$('shoutbox').tween('height', '0');}).delay(1000);
	(function(){$('news_window').tween('height', '0');}).delay(1000);
}
function hide_walls(){
	$('walls_loader').fade('out');
	$('walls_control').fade('out');
	(function(){$('walls_control').setStyle("height", "0px");}).delay(500);
	$('walls_series').tween('height', '0');
	(function(){$('walls_filters').tween('height', '0');}).delay(500);
	(function(){$('walls_gallery').fade('out');}).delay(400);
	(function(){$('gallery1').tween('max-height', '0');}).delay(300);
	(function(){$('gallery2').tween('max-height', '0');}).delay(200);
	(function(){$('gallery3').tween('max-height', '0');}).delay(100);
	(function(){$('gallery4').tween('max-height', '0');}).delay(300);
	(function(){$('gallery5').tween('max-height', '0');}).delay(200);
	(function(){$('gallery6').tween('max-height', '0');}).delay(100);
	(function(){$('walls_floral').morph({height: 0, width: 0});}).delay(500);
}
function hide_links(){
	if(Browser.Engine.presto==true){
		(function(){$('links_spoiler1').fade('hide');}).delay(900);
		(function(){$('links_spoiler3').fade('hide');}).delay(500);
	}
	(function(){$('links_fill').tween('height', '0');}).delay(600);
	(function(){$('links_spoiler1').tween('width', '0');}).delay(400);
	(function(){$$('a.aff_0').tween('width', '0');}).delay(200);
	(function(){$$('a.aff_1').tween('width', '0');}).delay(200);
	(function(){$$('a.aff_2').tween('width', '0');}).delay(200);
	(function(){$$('a.aff_3').tween('height', '0');}).delay(200);
	(function(){$$('a.aff_4').tween('height', '0');}).delay(200);
	(function(){$$('a.aff_5').tween('width', '0');}).delay(2000);
	(function(){$$('a.aff_6').tween('width', '0');}).delay(200);
	(function(){$$('a.aff_7').tween('height', '0');}).delay(200);
	$('affs_logo').tween('width', '0');
	$('links_spoiler3').tween('width', '0');
	(function(){$('links_affs').tween('height', '0');}).delay(500);
	$('links_other').tween('height', '0');
}
function hide_extras(){
	$('ookami').fade('out');
	$('stats_page').fade('out');
	$('contact_page').fade('out');$('contact_msg').fade('out');
	(function(){$('extras').fade('hide');}).delay(700);
	(function(){$('rss').morph({left: -94, opacity: 0.0});}).delay(200);
	(function(){$('twitter').morph({left: -94, opacity: 0.0});}).delay(500);
	(function(){$('contact').morph({right: -94, opacity: 0.0});}).delay(500);
	(function(){$('stats').morph({right: -94, opacity: 0.0});}).delay(200);
	(function(){$('extras_spoiler1').tween('width', '0');}).delay(200);
	(function(){$('extras_spoiler2').tween('width', '0');}).delay(200);
	(function(){$('extras_spoiler3').tween('width', '0');}).delay(500);
	(function(){$('extras_spoiler4').tween('width', '0');}).delay(500);
	$('rss_info').setStyle('top', '100px');
	$('twitter_info').setStyle('bottom', '100px');
	$('stats_info').setStyle('top', '100px');
	$('contact_info').setStyle('bottom', '100px');
	(function(){$('extras_spoiler1').setStyle('top', '203px');}).delay(700);
	(function(){$('extras_spoiler2').setStyle('top', '203px');}).delay(700);
	(function(){$('extras_spoiler3').setStyle('bottom', '203px');}).delay(1000);
	(function(){$('extras_spoiler4').setStyle('bottom', '203px');}).delay(1000);
	(function(){$('extras_main').morph({left: 400, width: 0});}).delay(500);
}
function hide_about(){
	$$('.about_button').fade('out');
}
function hide_nysha(){
	$$('#nysha_text span').tween('left', '-290');
	$('nysha_sig').tween('height', '0');
	(function(){$('nysha_text').tween('height', '0');}).delay(500);
	$('nysha_links').tween('width', '0');
	(function(){$('nysha_spoiler1').tween('height', '0');}).delay(400);
	(function(){$('nysha_spoiler2').tween('width', '0');}).delay(200);
	$('nysha_spoiler3').tween('height', '0');
	(function(){$('nysha_spoilers').fade('hide');}).delay(900);
	(function(){$('rei').fade('out');}).delay(500);
}
function hide_deto(){
	$$('#deto_text span').tween('left', '-290');
	$('deto_sig').tween('height', '0');
	(function(){$('deto_text').tween('height', '0');}).delay(500);
	$('deto_links').tween('width', '0');
	(function(){$('deto_spoiler1').tween('width', '0');}).delay(400);
	(function(){$('deto_spoiler2').tween('width', '0');}).delay(200);
	$('deto_spoiler3').tween('height', '0');
	(function(){$('deto_spoilers').fade('hide');}).delay(900);
	(function(){$('ling').fade('out');}).delay(500);
}
function hide_all(){
	$$('div.main_menu').removeEvents('click');
	$$('div.main_menu_filler').fade('out');
	if($('recent').getStyle('height').toInt()>0) hide_home();
	if($('walls_filters').getStyle('height').toInt()>0) hide_walls();
	if($('links_fill').getStyle('height').toInt()>0) hide_links();
	if($('rss').getStyle('left').toInt()>0) hide_extras();
	if($('about_deto_button').getStyle('opacity').toInt()>0) hide_about();
	if($('nysha_text').getStyle('height').toInt()>0) hide_nysha();
	if($('deto_text').getStyle('height').toInt()>0) hide_deto();
}
function main_menu(){
	$$('div.main_menu, div.about_button').removeEvents('click');
	var temp_delay = 0;
	if($('walls_filters').getStyle('height').toInt()>0) temp_delay+=1000;
	else if($('links_fill').getStyle('height').toInt()>0) temp_delay+=800;
	else if($('rss').getStyle('left').toInt()>0) temp_delay+=700;
	else if($('recent').getStyle('height').toInt()>0) temp_delay+=1500;
	else if($('about_button_filler').getStyle('opacity').toInt()!=0) temp_delay+=500;
	if($('nysha_text').getStyle('height').toInt()>0) temp_delay+=500;
	if($('deto_text').getStyle('height').toInt()>0) temp_delay+=500;
	
	$('news_button').addEvent('click', function(){
		if($('news_button_filler').getStyle('opacity').toInt()==0){
			var myURI = new URI(window.location).set('fragment', 'p=1').go();
			hide_all();
			$('news_button_filler').fade('in');
			(function(){open_home();}).delay(temp_delay);
		}
	});
	$('walls_button').addEvent('click', function(){
		if($('walls_button_filler').getStyle('opacity').toInt()==0){	
			var myURI = new URI(window.location).set('fragment', 'p=2').go();
			hide_all();
			$('walls_button_filler').fade('in');
			(function(){open_walls();}).delay(temp_delay);
		}
	});
	$('about_button').addEvent('click', function(){
		if($('about_button_filler').getStyle('opacity').toInt()==0){
			var myURI = new URI(window.location).set('fragment', 'p=3').go();	
			hide_all();
			$('about_button_filler').fade('in');
			(function(){open_about();}).delay(temp_delay);
		}
	});
	$('links_button').addEvent('click', function(){
		if($('links_button_filler').getStyle('opacity').toInt()==0){
			var myURI = new URI(window.location).set('fragment', 'p=4').go();	
			hide_all();
			$('links_button_filler').fade('in');
			(function(){open_links();}).delay(temp_delay);
		}
	});
	$('extras_button').addEvent('click', function(){
		if($('extras_button_filler').getStyle('opacity').toInt()==0){
			var myURI = new URI(window.location).set('fragment', 'p=5').go();	
			hide_all();
			$('extras_button_filler').fade('in');
			(function(){open_extras();}).delay(temp_delay);
		}
	});
	$('about_nysha_button').addEvent('click', function(){
		var myURI = new URI(window.location).set('fragment', 'a=nysha').go();	
		hide_all();
		$('about_button_filler').fade('in');
		(function(){open_nysha();}).delay(temp_delay);
	});
	$('about_deto_button').addEvent('click', function(){
		var myURI = new URI(window.location).set('fragment', 'a=deto').go();	
		hide_all();
		$('about_button_filler').fade('in');
		(function(){open_deto();}).delay(temp_delay);
	});
}
function scroll_affs(){
	var aff_value = $('affiliates').getScroll();
	if((aff_value.x>=(92*6)-1)&&(aff_value.x<=(92*6)+1)){ var aff_scroll = new Fx.Scroll($('affiliates')).set(0,0); aff_value.x=0;}
	var aff_scroll = new Fx.Scroll($('affiliates')).start(aff_value.x+92,0);
	(function(){scroll_affs();}).delay(6000);
}
function loading_end(){
		//temp_num+=2500;
		$$('div.main_menu').removeEvents('click');
		$('load_spoiler1').tween('width', '0');
		(function(){$('load_spoiler2').tween('width', '0');}).delay(100);
		(function(){$('load_spoiler3').tween('width', '0');}).delay(200);
		(function(){$('load_spoiler4').tween('width', '0');}).delay(300);
		(function(){$('load_spoiler5').tween('width', '0');}).delay(400);
		if(Browser.Engine.presto==true) (function(){$$('.spoiler').fade('hide');}).delay(900);
		(function(){$('loading').fade('out');}).delay(500);
		(function(){$('bg_grid').tween('width', '1000');}).delay(500);
		(function(){scroll_affs();}).delay(5000);
		(function(){$('load_spoiler1').destroy();$('load_spoiler2').destroy();$('load_spoiler3').destroy();$('load_spoiler4').destroy();$('load_spoiler5').destroy();}).delay(1200);
		var Spoiler_tips = new Tips($$('.spoiler'), {className: 'spoiler_tip'});
		var Aff_tips = new Tips($$('.aff_button'), {onShow: function(Tip){Tip.fade('in');}, onHide: function(Tip){Tip.fade('out');}});
		var Aff_tips2 = new Tips($$('.aff_thumb'), {onShow: function(Tip){Tip.fade('in');}, onHide: function(Tip){Tip.fade('out');}});
		var Filter_tips = new Tips($$('.filter_button'), {onShow: function(Tip){Tip.fade('in');}, onHide: function(Tip){Tip.fade('out');}});
		var Series_tips = new Tips($$('.series_title'), {onShow: function(Tip){Tip.fade('in');}, onHide: function(Tip){Tip.fade('out');}});
		$('recent_spoiler1').addEvent('click', function(){show_recent('recent');});
		$('recent_spoiler2').addEvent('click', function(){show_recent('recent');});
		
		(function(){$('main_menu').setStyle('height', '100px');}).delay(2500);
		(function(){$('news_button').fade('in');}).delay(2600);
		(function(){$('walls_button').fade('in');}).delay(2750);
		(function(){$('about_button').fade('in');}).delay(2900);
		(function(){$('links_button').fade('in');}).delay(3050);
		(function(){$('extras_button').fade('in');}).delay(3200);
		(function(){$('signature').fade('show');}).delay(3000);
		(function(){$('signature').tween('height', '100');}).delay(3000);
		(function(){$('donate').tween('width', '100');}).delay(3600);
		(function(){$('stumble').tween('width', '100');}).delay(3600);
		
		var myURI = new URI(window.location);
		var where_to = myURI.getData('p','fragment');
		var filter_to = myURI.getData('f','fragment');
		var wall_to = myURI.getData('w','fragment');
		var news_to = myURI.getData('n','fragment');
		var cat_to = myURI.getData('c','fragment');
		var page_to = myURI.getData('o','fragment');
		var about_to = myURI.getData('a','fragment');
		if ((where_to==null)&&(wall_to!=null)) (function(){show_recent(wall_to);hide_home();}).delay(2000);
		else if ((where_to==null)&&(news_to!=null)) {(function(){open_home();}).delay(2500);(function(){next_news(news_to);}).delay(2500);}
		else if (where_to=='2'){
			if (filter_to!=null)(function(){show_recent(null);hide_home();}).delay(2000);
			else if(wall_to!=null)(function(){show_recent(wall_to);hide_home();}).delay(2000);
			else (function(){open_walls();hide_home();}).delay(2500);
		}
		else if (where_to=='2')(function(){open_walls();hide_home();}).delay(2500);
		else if (where_to=='4')(function(){open_links();hide_home();}).delay(2500);
		else if (where_to=='5')(function(){open_extras();hide_home();}).delay(2500);
		else if (where_to=='3')(function(){open_about();hide_home();}).delay(2500);
		else if (about_to=='nysha')(function(){open_nysha();hide_home();}).delay(2500);
		else if (where_to=='1'){
			(function(){open_home();}).delay(2500);
			if(news_to!=null) (function(){next_news(news_to);}).delay(2500);
		}
		//else if (where_to<1000) (function(){show_recent((where_to*2)-2);}).delay(2000);
		else (function(){open_home();}).delay(2500);
}
function open_home(){
	if(Browser.Engine.presto==true){
		(function(){$('news_spoiler1').fade('show');}).delay(500);
		(function(){$('news_spoiler2').fade('show');}).delay(1000);
		(function(){$('news_spoiler3').fade('show');}).delay(1000);
		(function(){$('recent_spoiler1').fade('show');}).delay(1000);
		(function(){$('recent_spoiler2').fade('show');}).delay(1500);
	}
	$$('div.main_menu').removeEvents('click');
	$('recent_button').setStyle('height', '0px');
	$('recent_spoiler1').setStyle('height', '0px');
	$('recent_spoiler2').setStyle('height', '0px');
	$('recent').setStyle('height', '300px');
	$('news_window').set('tween', {duration: 700, transition: 'quart:in:out'});
	$('news').set('tween', {duration: 700, transition: 'quart:in:out'});
	$('news_window').tween('height', '500');
	$('news').tween('height', '500');
	(function(){$('news_floral').fade(0.25);}).delay(300);
	(function(){$('news_button_filler').fade('in');}).delay(700);
	(function(){$('news_spoiler1').tween('width', '94');}).delay(500);
	(function(){$('news_spoiler2').tween('height', '94');}).delay(1000);
	(function(){$('news_spoiler3').tween('width', '94');}).delay(1000);
	(function(){$('shiki').fade('in');}).delay(1700);
	(function(){$('recent_button').tween('height', '100');}).delay(500);
	(function(){$('recent_spoiler1').tween('height', '94');}).delay(1000);
	(function(){$('recent_spoiler2').tween('height', '94');}).delay(1500);
	if($('news_control').getStyle('height').toInt()==0) (function(){$('news_control').tween('height', '100');}).delay(700);
	(function(){$('news_previous_button').tween('height', '100');}).delay(700);
	(function(){$('shoutbox_button').tween('height', '100');}).delay(700);
	(function(){main_menu();}).delay(1800);
}
function open_walls(){
	$('walls_button_filler').fade('in');
	(function(){$('walls_loader').fade('hide');}).delay(800);
	(function(){$('walls_control').fade('in');}).delay(800);
	(function(){$('walls_control').setStyle("height", "100px");}).delay(700);
	$$('div.main_menu').removeEvents('click');
	$('walls_filters').tween('height', '200');
	$('walls_gallery').fade('in');
	(function(){$('gallery1').tween('max-height', '300');}).delay(100);
	(function(){$('gallery2').tween('max-height', '300');}).delay(400);
	(function(){$('gallery3').tween('max-height', '300');}).delay(700);
	(function(){$('gallery4').tween('max-height', '300');}).delay(200);
	(function(){$('gallery5').tween('max-height', '300');}).delay(500);
	(function(){$('gallery6').tween('max-height', '300');}).delay(800);
	(function(){$('walls_series').tween('height', '400');}).delay(300);
	(function(){main_menu();}).delay(1000);
	(function(){gallery_event();}).delay(1000);
	(function(){$('walls_floral').morph({height: 277, width: 305});}).delay(800);
}
function open_links(){
	if(Browser.Engine.presto==true){
		(function(){$('links_spoiler1').fade('show');}).delay(400);
		(function(){$('links_spoiler3').fade('show');}).delay(600);
	}
	$('links_button_filler').fade('in');
	$$('div.main_menu').removeEvents('click');
	$('links_fill').tween('height', '100');
	(function(){$('links_spoiler1').tween('width', '94');}).delay(400);
	(function(){$('links_spoiler3').tween('width', '94');}).delay(600);
	(function(){$('links_affs').tween('height', '300');}).delay(50);
	(function(){$('links_other').tween('height', '300');}).delay(800);
	(function(){$$('a.aff_0').tween('width', '100');}).delay(400);
	(function(){$$('a.aff_1').tween('width', '100');}).delay(500);
	(function(){$$('a.aff_2').tween('width', '100');}).delay(600);
	(function(){$$('a.aff_3').tween('height', '100');}).delay(1100);
	(function(){$$('a.aff_4').tween('height', '100');}).delay(700);
	(function(){$$('a.aff_5').tween('width', '100');}).delay(1000);
	(function(){$$('a.aff_6').tween('width', '100');}).delay(900);
	(function(){$$('a.aff_7').tween('height', '100');}).delay(800);
	(function(){$('affs_logo').tween('width', '100');}).delay(1200);
	(function(){main_menu();}).delay(1300);
}
function open_extras(){
	$('extras').fade('show');
	$$('.extras').fade(0.1);
	$('extras_button_filler').fade('in');
	$$('div.main_menu').removeEvents('click');
	(function(){$('rss').morph({left: 203, opacity: 1.0});}).delay(200);
	(function(){$('twitter').morph({left: 203, opacity: 1.0});}).delay(500);
	(function(){$('contact').morph({right: 203, opacity: 1.0});}).delay(500);
	(function(){$('stats').morph({right: 203, opacity: 1.0});}).delay(200);
	(function(){$('ookami').fade('in');}).delay(400);
	(function(){main_menu();}).delay(700);
	(function(){$('extras_spoiler1').tween('width', '94');}).delay(400);
	(function(){$('extras_spoiler2').tween('width', '94');}).delay(400);
	(function(){$('extras_spoiler3').tween('width', '94');}).delay(600);
	(function(){$('extras_spoiler4').tween('width', '94');}).delay(600);
}
function open_about(){
	$('about_button_filler').fade('in');
	$$('div.main_menu').removeEvents('click');
	$('about_deto_button').fade('in');
	(function(){$('about_saf_button').fade('in');}).delay(200);
	(function(){$('about_asa_button').fade('in');}).delay(200);
	(function(){$('about_dalarty_button').fade('in');}).delay(300);
	(function(){$('about_nysha_button').fade('in');}).delay(400);
	(function(){main_menu();}).delay(900);
}
function open_nysha(){
	$('about_button_filler').fade('in');
	$$('div.main_menu').removeEvents('click');
	(function(){$$('#nysha_text span').tween('left', '5');}).delay(500);
	(function(){$('nysha_sig').tween('height', '100');}).delay(500);
	$('nysha_text').tween('height', '500');
	$('nysha_links').tween('width', '200');
	$('nysha_spoilers').fade('show');
	(function(){$('nysha_spoiler1').tween('height', '94');}).delay(100);
	(function(){$('nysha_spoiler2').tween('width', '94');}).delay(300);
	(function(){$('nysha_spoiler3').tween('height', '94');}).delay(500);
	(function(){$('rei').fade('in');}).delay(500);
	(function(){main_menu();}).delay(1000);
}
function open_deto(){
	$('about_button_filler').fade('in');
	$$('div.main_menu').removeEvents('click');
	(function(){$$('#deto_text span').tween('left', '5');}).delay(500);
	(function(){$('deto_sig').tween('height', '100');}).delay(500);
	$('deto_text').tween('height', '400');
	$('deto_links').tween('width', '200');
	$('deto_spoilers').fade('show');
	(function(){$('deto_spoiler1').tween('width', '94');}).delay(100);
	(function(){$('deto_spoiler2').tween('width', '94');}).delay(300);
	(function(){$('deto_spoiler3').tween('height', '94');}).delay(500);
	(function(){$('ling').fade('in');}).delay(500);
	(function(){main_menu();}).delay(1000);
}

function progress_bar(){
	var num = ($('thumb_num').get('text').toInt())-1;
	var recent1 = $random(num-1, num);
	var recent2 = $random(num-3, num-2);
	var rand1 = $random(0, num);
	var rand2 = $random(0, num);
	while(rand2==rand1){
		var rand2 = $random(0, num);
	}
	var rand3 = $random(0, num);
	while((rand3==rand1)||(rand3==rand2)){
		var rand3 = $random(0, num);
	}
	var rand4 = $random(0, num);
	while((rand4==rand1)||(rand4==rand2)||(rand4==rand3)){
		var rand4 = $random(0, num);
	}
	var rand5 = $random(0, num);
	while((rand5==rand1)||(rand5==rand2)||(rand5==rand3)||(rand5==rand4)){
		var rand5 = $random(0, num);
	}
	var news1 = $random(0, num-4);
	var news2 = $random(0, num-4);
	while(news2==news1){
		var news2 = $random(0, num-4);
	}
	var news3 = $random(0, num-4);
	while((news3==news1)||(news3==news2)){
		var news3 = $random(0, num-4);
	}
	var links1 = $random(0, num-4);
	var links3 = $random(0, num-4);
	while((links3==links1)||(links3==news1)||(links3==news2)||(links3==news3)){
		var links3 = $random(0, num-4);
	}
	var extra1 = $random(0, num);
	var extra2 = $random(0, num);
	while(extra2==extra1){
		var extra2 = $random(0, num);
	}
	var extra3 = $random(0, num);
	while((extra3==extra1)||(extra3==extra2)){
		var extra3 = $random(0, num);
	}
	var extra4 = $random(0, num);
	while((extra4==extra1)||(extra4==extra2)||(extra4==extra3)){
		var extra4 = $random(0, num);
	}
	
	var loadSpoilers = new Asset.images(['layout/spoilers/'+rand1+'.png', 'layout/spoilers/'+rand2+'.png', 'layout/spoilers/'+rand3+'.png', 'layout/spoilers/'+rand4+'.png', 'layout/spoilers/'+rand5+'.png'], {
		onProgress: function(counter, index){
			if(counter==2) $('loading').tween('top', '170');
			loadSpoilers[index].setProperty('id', 'load_spoiler'+(index+1)).inject($('bg_grid_right'),'bottom');
		}, onComplete: function(){
			
			var Images = new Asset.images(['layout/spoilers/'+news1+'.png', 'layout/spoilers/'+news2+'.png', 'layout/spoilers/'+news3+'.png', 'layout/spoilers/'+recent1+'.png', 'layout/spoilers/'+recent2+'.png', 'layout/spoilers/'+links1+'.png', 'layout/spoilers/'+links3+'.png', 'layout/shiki.png', 'layout/spoilers/'+extra1+'.png', 'layout/spoilers/'+extra2+'.png', 'layout/spoilers/'+extra3+'.png', 'layout/spoilers/'+extra4+'.png', 'layout/signature.png', 'layout/ookami.png', 'layout/news.png', 'layout/rei.png', 'layout/spoilers/200.png', 'layout/spoilers/158.png', 'layout/spoilers/164.png', 'layout/ling.png', 'layout/spoilers/48.png', 'layout/spoilers/118.png', 'layout/spoilers/30.png'],{
				onError:function(index){
				}, onComplete: function(){
					var rel = '<img onload=\'this.fade(\"hide\");this.fade(1);\' src=\'layout/thumbs/';
					var rel2 = '.jpg\'>';
					
					Images.each(function(item, index){item.set('class', 'spoiler')});
					Images[7].set('class', 'vector');
					Images[13].set('class', 'vector');
					Images[15].set('class', 'vector');
					Images[19].set('class', 'vector');
					
					Images[0].setProperties({title: ' ', id: 'news_spoiler1', rel: rel+(Math.floor(news1/2)+1)+rel2}).inject($('bg_grid_left'),'bottom').addEvent('click', function(){show_recent(news1);});
					Images[1].setProperties({title: ' ', id: 'news_spoiler2', rel: rel+(Math.floor(news2/2)+1)+rel2}).inject($('bg_grid_left'),'bottom').addEvent('click', function(){show_recent(news2);});
					Images[2].setProperties({title: ' ', id: 'news_spoiler3', rel: rel+(Math.floor(news3/2)+1)+rel2}).inject($('bg_grid_right'),'bottom').addEvent('click', function(){show_recent(news3);});
					Images[3].setProperties({title: ' ', id: 'recent_spoiler1', rel: rel+(Math.floor(recent1/2)+1)+rel2}).inject($('recent'),'bottom');	
					Images[4].setProperties({title: ' ', id: 'recent_spoiler2', rel: rel+(Math.floor(recent2/2)+1)+rel2}).inject($('recent'),'bottom');	
					Images[5].setProperties({title: ' ', id: 'links_spoiler1', rel: rel+(Math.floor(links1/2)+1)+rel2}).inject($('bg_grid_right'),'bottom').addEvent('click', function(){show_recent(links1);});
					Images[6].setProperties({title: ' ', id: 'links_spoiler3', rel: rel+(Math.floor(links3/2)+1)+rel2}).inject($('bg_grid_right'),'bottom').addEvent('click', function(){show_recent(links3);});
					Images[7].setProperties({id: 'shiki'}).inject($('bg_grid_right'),'after').fade('hide');
					Images[8].setProperties({title: ' ', id: 'extras_spoiler1', rel: rel+(Math.floor(extra1/2)+1)+rel2}).inject($('bg_grid_right'),'bottom').addEvent('click', function(){show_recent(extra1);});
					Images[9].setProperties({title: ' ', id: 'extras_spoiler2', rel: rel+(Math.floor(extra2/2)+1)+rel2}).inject($('bg_grid_right'),'bottom').addEvent('click', function(){show_recent(extra2);});	
					Images[10].setProperties({title: ' ', id: 'extras_spoiler3', rel: rel+(Math.floor(extra3/2)+1)+rel2}).inject($('bg_grid_right'),'bottom').addEvent('click', function(){show_recent(extra3);});	
					Images[11].setProperties({title: ' ', id: 'extras_spoiler4', rel: rel+(Math.floor(extra4/2)+1)+rel2}).inject($('bg_grid_right'),'bottom').addEvent('click', function(){show_recent(extra4);});	
					Images[12].setProperty('id', 'credits').inject($('signature'),'bottom');	
					Images[13].setProperties({id: 'ookami'}).inject($('shiki'),'after').fade('hide');	
					Images[14].setProperty('id', 'news_floral').inject($('news_window'),'top').fade('hide');	
					Images[15].setProperties({id: 'rei'}).inject($('ookami'),'after').fade('hide');
					Images[16].setProperties({title: ' ', id: 'nysha_spoiler1', rel: rel+(Math.floor(200/2)+1)+rel2}).inject($('nysha_spoilers'),'bottom').addEvent('click', function(){show_recent(200);});
					Images[17].setProperties({title: ' ', id: 'nysha_spoiler2', rel: rel+(Math.floor(158/2)+1)+rel2}).inject($('nysha_spoilers'),'bottom').addEvent('click', function(){show_recent(158);});
					Images[18].setProperties({title: ' ', id: 'nysha_spoiler3', rel: rel+(Math.floor(164/2)+1)+rel2}).inject($('nysha_spoilers'),'bottom').addEvent('click', function(){show_recent(164);});	
					Images[19].setProperties({id: 'ling'}).inject($('rei'),'after').fade('hide');
					Images[20].setProperties({title: ' ', id: 'deto_spoiler1', rel: rel+(Math.floor(48/2)+1)+rel2}).inject($('deto_spoilers'),'bottom').addEvent('click', function(){show_recent(48);});
					Images[21].setProperties({title: ' ', id: 'deto_spoiler2', rel: rel+(Math.floor(118/2)+1)+rel2}).inject($('deto_spoilers'),'bottom').addEvent('click', function(){show_recent(118);});
					Images[22].setProperties({title: ' ', id: 'deto_spoiler3', rel: rel+(Math.floor(30/2)+1)+rel2}).inject($('deto_spoilers'),'bottom').addEvent('click', function(){show_recent(30);});	
					(function(){$('load_spoiler5').tween('height', '94');}).delay(500);
					(function(){loading_end();}).delay(1000);
				}, onProgress: function(counter,index){
					if(counter==6) $('load_spoiler1').tween('height', '94');
					if(counter==10) $('load_spoiler2').tween('height', '94');
					if(counter==13) $('load_spoiler3').tween('height', '94');
					if(counter==17) $('load_spoiler4').tween('height', '94');
				}
			});
		}, onError: function(index){
			alert('error - spoiler '+index);
		} 
	});
	
}

function start_animation(){
	$('bg_grid').set('tween', {duration: 2000}).tween('width', '400');
	$('logo2').set('tween', {duration: 1000});
	$('floral1').set('morph', {duration: 1200});
	(function(){$('logo3').fade('in');}).delay(2000);
	(function(){$('logo1').tween('height', '16');}).delay(2500);
	(function(){$('logo2').tween('width', '140');}).delay(2500);
	(function(){$('floral1').morph({height: 182, width: 195});}).delay(3000);
	(function(){$('loading').fade('in');}).delay(4000);
	(function(){progress_bar();}).delay(4300);
}
function previous_news(e){
		var myURI = new URI(window.location);
		if(e!=null) myURI.setData({p: 1,n: e}, false, 'fragment').go();
		
		$('loader1').fade('in');
    	var PreviousNews = new Element('div', {'id': 'previous_news'});
		PreviousNews.inject($('news'), 'after');
		$('previous_news').set('load', {onSuccess : function(){
			$('news').tween('height', '0');
			$('previous_news').tween('height', '500');
			(function(){$('news').destroy();}).delay(700);
			(function(){$('previous_news').setProperty('id', 'news');}).delay(800);
			(function(){$('loader1').fade('out');}).delay(850);
		}});
		$('previous_news').load('news.php?num='+e);
}
function next_news(e){
		var myURI = new URI(window.location);
		if(e!=null) myURI.setData({p: 1,n: e}, false, 'fragment').go();
		
		$('loader1').fade('in');
    	var NextNews = new Element('div', {'id': 'next_news'});
		NextNews.inject($('news'), 'after');
		$('next_news').set('load', {onSuccess : function(){
			$('news').tween('height', '0');
			$('next_news').tween('height', '500');
			(function(){$('news').destroy();}).delay(700);
			(function(){$('next_news').setProperty('id', 'news');}).delay(800);
			(function(){$('loader1').fade('out');}).delay(850);
		}});
		$('next_news').load('news.php?num='+e);
}
function wall_filter(e,f){
	if(e==1) var myURI = new URI(window.location).set('fragment', 'p=2').go();
	if(f!=null) var myURI = new URI(window.location).set('fragment', 'p=2&f='+e+'&o='+f).go();
	else if(e>1) var myURI = new URI(window.location).set('fragment', 'p=2&f='+e).go();
	
	$('walls_loader').fade('in');
	$('walls_control').fade('out');
	(function(){$('walls_control').setStyle("height", "0px");}).delay(500);
	$$('div.main_menu').removeEvents('click');
	$$('div.filter_button_bg').fade('out');
	$('filter'+e+'_bg').fade(0.7);
	if(e==1) $$('span.series_title').tween('background-color', '#ffffff');
	$('walls_gallery').fade('out');
	(function(){$('walls_gallery').empty();}).delay(500);
	(function(){$('walls_gallery').load('walls.php?filter='+e+'&page='+f);}).delay(550);
	$('walls_gallery').set('load', {onSuccess : function(){											 
		(function(){main_menu();}).delay(800);
		$('walls_gallery').fade('in');
		(function(){$('gallery1').tween('max-height', '300');}).delay(100);
		(function(){$('gallery2').tween('max-height', '300');}).delay(400);
		(function(){$('gallery3').tween('max-height', '300');}).delay(700);
		(function(){$('gallery4').tween('max-height', '300');}).delay(200);
		(function(){$('gallery5').tween('max-height', '300');}).delay(500);
		(function(){$('gallery6').tween('max-height', '300');}).delay(800);
		(function(){$('walls_series').tween('height', '400');}).delay(300);
		(function(){$('walls_control').fade('in');}).delay(500);
		(function(){$('walls_control').setStyle("height", "100px");}).delay(400);
		(function(){$('walls_loader').fade('out');}).delay(200);
		(function(){gallery_event();}).delay(1000);
	}});
	$('series_loader').fade('in');
	(function(){$('series_list').empty();}).delay(500);
	(function(){$('series_list').load('series.php?filter='+e);}).delay(550);
	$('series_list').set('load', {onSuccess : function(){
		var Series_tips = new Tips($$('.series_title'), {onShow: function(Tip){Tip.fade('in');}, onHide: function(Tip){Tip.fade('out');}});											   
		$('series_loader').fade('out');	
		var Series_Scroll = new MooScroller($E('div#series_list'), $E('div#series_knob'));										   
	}});
}
function wall_category(e,f,g){
	var myURI = new URI(window.location);
	if(e!=null) myURI.setData({p: 2,f: f,c: e,o: g}, true, 'fragment').go();
	
	$('walls_loader').fade('in');
	$('walls_control').fade('out');
	(function(){$('walls_control').setStyle("height", "0px");}).delay(500);
	$$('div.main_menu').removeEvents('click');
	$$('span.series_title').tween('background-color', '#ffffff');
	$('series_'+e).tween('background-color', '#dddddd');
	$('filter1_bg').fade('out');
	$('walls_gallery').fade('out');
	(function(){$('walls_gallery').empty();}).delay(500);
	(function(){$('walls_gallery').load('walls.php?filter='+f+'&category='+e+'&page='+g);}).delay(550);
	$('walls_gallery').set('load', {onSuccess : function(){											 
		(function(){main_menu();}).delay(800);
		$('walls_gallery').fade('in');
		(function(){$('gallery1').tween('max-height', '300');}).delay(100);
		(function(){$('gallery2').tween('max-height', '300');}).delay(400);
		(function(){$('gallery3').tween('max-height', '300');}).delay(700);
		(function(){$('gallery4').tween('max-height', '300');}).delay(200);
		(function(){$('gallery5').tween('max-height', '300');}).delay(500);
		(function(){$('gallery6').tween('max-height', '300');}).delay(800);
		(function(){$('walls_series').tween('height', '400');}).delay(300);
		(function(){$('walls_control').fade('in');}).delay(500);
		(function(){$('walls_control').setStyle("height", "100px");}).delay(400);
		(function(){$('walls_loader').fade('out');}).delay(200);
		(function(){gallery_event();}).delay(1000);
	}});
}
function show_recent(e){
	var myURI = new URI(window.location);
	var f = myURI.getData('f','fragment');
	var c = myURI.getData('c','fragment');
	var o = myURI.getData('o','fragment');
	if(e!=null) myURI.setData({p: 2,w: e}, true, 'fragment').go();
	
	$('walls_gallery').set('load', {onSuccess : function(){
		$$('div.download_list').fade('hide');
		if($('walls_filters').getStyle('height').toInt()>0){
			(function(){$('gallery1').tween('max-height', '300');}).delay(100);
			(function(){$('gallery2').tween('max-height', '300');}).delay(400);
			(function(){$('gallery3').tween('max-height', '300');}).delay(700);
			(function(){$('gallery4').tween('max-height', '300');}).delay(200);
			(function(){$('gallery5').tween('max-height', '300');}).delay(500);
			(function(){$('gallery6').tween('max-height', '300');}).delay(800);
			(function(){gallery_event();}).delay(1000);
		}
	}});
	
	$('walls_gallery').empty();
	if(e==null) {
		if((c==null)&&(o!=null)) $('walls_gallery').load('walls.php?filter='+f+'&page='+o);
		else if(c==null) $('walls_gallery').load('walls.php?filter='+f);
		else $('walls_gallery').load('walls.php?filter='+f+'&category='+c+'&page='+o);
	}
	else $('walls_gallery').load('walls.php?wall='+e);
	
	hide_all();
	var temp_delay2 = 0;
	if($('recent').getStyle('height').toInt()>0) temp_delay2+=1500;
	if($('links_fill').getStyle('height').toInt()>0) temp_delay2+=900;
	if($('rss').getStyle('left').toInt()>0) temp_delay2+=700;
	if($('nysha_text').getStyle('height').toInt()>0) temp_delay2+=1000;
	
	(function(){$('walls_button_filler').fade('in');}).delay(temp_delay2);
	(function(){$('walls_loader').fade('hide');}).delay(temp_delay2+800);
	(function(){$('walls_control').fade('in');}).delay(temp_delay2+800);
	(function(){$('walls_control').setStyle("height", "100px");}).delay(temp_delay2+700);
	$$('div.main_menu').removeEvents('click');
	(function(){$('walls_filters').tween('height', '200');}).delay(temp_delay2);
	(function(){$('walls_gallery').fade('in');}).delay(temp_delay2);
	(function(){if($('walls_gallery').hasChild('gallery1')==true){
		(function(){$('gallery1').tween('max-height', '300');}).delay(100);
		(function(){$('gallery2').tween('max-height', '300');}).delay(400);
		(function(){$('gallery3').tween('max-height', '300');}).delay(700);
		(function(){$('gallery4').tween('max-height', '300');}).delay(200);
		(function(){$('gallery5').tween('max-height', '300');}).delay(500);
		(function(){$('gallery6').tween('max-height', '300');}).delay(800);
		(function(){gallery_event();}).delay(1000);
	}else{
	}}).delay(temp_delay2);
	(function(){$('walls_series').tween('height', '400');}).delay(temp_delay2+300);
	(function(){main_menu();}).delay(temp_delay2+1000);
	(function(){$('walls_floral').morph({height: 277, width: 305});}).delay(temp_delay2+800);
	
	$('series_list').set('load', {onSuccess : function(){
		if(c!=null) $('series_'+c).tween('background-color', '#dddddd');
		var Series_tips = new Tips($$('.series_title'), {onShow: function(Tip){Tip.fade('in');}, onHide: function(Tip){Tip.fade('out');}});											   
		$('series_loader').fade('out');	
		var Series_Scroll = new MooScroller($E('div#series_list'), $E('div#series_knob'));										   
	}});
	
	(function(){$('series_list').empty();}).delay(500);
	$('series_loader').fade('in');
	if(e==null){ (function(){$('series_list').load('series.php?filter='+f);}).delay(550);$$('div.filter_button_bg').fade('out');$('filter'+f+'_bg').fade(0.7);}
	else{ (function(){$('series_list').load('series.php?light='+e);}).delay(550);$$('div.filter_button_bg').fade('out');$('filter1_bg').fade(0.7);}
}
function extras_info_add(){
	$('rss').addEvents({'mouseover': function(){$('rss_info').fade(1.0);},'mouseout': function(){$('rss_info').fade(0.0);}});
	$('twitter').addEvents({'mouseover': function(){$('twitter_info').fade(1.0);},'mouseout': function(){$('twitter_info').fade(0.0);}});
	$('stats').addEvents({'mouseover': function(){$('stats_info').fade(1.0);},'mouseout': function(){$('stats_info').fade(0.0);}});
	$('contact').addEvents({'mouseover': function(){$('contact_info').fade(1.0);},'mouseout': function(){$('contact_info').fade(0.0);}});
}
function show_shoutbox(){
		$('loader1').fade('in');
		$('shoutbox').set('load', {onSuccess : function(){										
			$('news').tween('height', '0');
			$('news_control').tween('height', '0');
			$('shout_control').tween('height', '100');
			$('shoutbox').tween('height', '500');
			(function(){$('loader1').fade('out');}).delay(500);
			var Shout_Scroll = new MooScroller($E('div#shoutbox_log'), $E('div#shout_knob', {maxThumbSize: 50}));
			$('shout_form').set('send', {onSuccess : function(e) {
				//new Event(e).stop();
				//$('loader1').fade('in');
				//this.set('send', {onComplete: function(response) {
					show_shoutbox();
					$('loader1').fade('out');
				//}});
				//this.send();
			}});
		}});
		$('shoutbox').load('shoutbox.php');
}
function hide_shoutbox(){
		$('loader1').fade('in');
		$('news').tween('height', '500');
		(function(){$('news_control').tween('height', '100');}).delay(200);
		(function(){$('shout_control').tween('height', '0');}).delay(200);
		$('shoutbox').tween('height', '0');
		(function(){$('loader1').fade('out');}).delay(500);
}

window.addEvent('load', function() {
	if(((Browser.Engine.gecko==true)&&(Browser.Engine.version==18))||(Browser.Engine.trident==true)){
		$('outer_main').setStyle("display", "block");
		$('outer_main').setStyle("height", "800px");
		$('inner_main').setStyle("display", "block");
		$('inner_main').setStyle("height", "800px");
		$('help_main').setStyle("display", "none");
		$('help_main').setStyle("height", "800px");
	}
	if((Browser.Engine.gecko==true)&&(Browser.Engine.version==18)){
		$$('.download_content a').setStyle("display", "inline");
	}
	$('logo1').set('tween', {duration: 500, link: 'chain'}).fade(0.2);
	$('logo3').fade('hide');
	$('floral1').fade(0.4);
	$('loading').fade('hide');
	$('news_button').fade('hide');
	$('walls_button').fade('hide');
	$('about_button').fade('hide');
	$('links_button').fade('hide');
	$('extras_button').fade('hide');
	$('news_button_bg').fade(0.2);
	$('walls_button_bg').fade(0.2);
	$('about_button_bg').fade(0.2);
	$('links_button_bg').fade(0.2);
	$('extras_button_bg').fade(0.2);
	$('recent_button_bg').fade(0.3);
	$('news_next_button_bg').fade(0.2);
	$('news_previous_button_bg').fade(0.2);
	$('shoutbox_button_bg').fade(0.2);
	$('shout_submit_button_bg').fade(0.2);
	$('shout_news_button_bg').fade(0.2);
	$('news_button_filler').fade('hide');
	$('walls_button_filler').fade('hide');
	$('about_button_filler').fade('hide');
	$('links_button_filler').fade('hide');
	$('extras_button_filler').fade('hide');
	$('news_button').addEvents({'mouseover': function(){$('news_button_bg').fade(0.5);},'mouseout': function(){$('news_button_bg').fade(0.2);}});
	$('walls_button').addEvents({'mouseover': function(){$('walls_button_bg').fade(0.5);},'mouseout': function(){$('walls_button_bg').fade(0.2);}});
	$('about_button').addEvents({'mouseover': function(){$('about_button_bg').fade(0.5);},'mouseout': function(){$('about_button_bg').fade(0.2);}});
	$('links_button').addEvents({'mouseover': function(){$('links_button_bg').fade(0.5);},'mouseout': function(){$('links_button_bg').fade(0.2);}});
	$('extras_button').addEvents({'mouseover': function(){$('extras_button_bg').fade(0.5);},'mouseout': function(){$('extras_button_bg').fade(0.2);}});
	$('recent_button').addEvents({'mouseover': function(){$('recent_button_bg').fade(0.6);},'mouseout': function(){$('recent_button_bg').fade(0.3);}});
	$('news_next_button').addEvents({'mouseover': function(){$('news_next_button_bg').fade(0.5);},'mouseout': function(){$('news_next_button_bg').fade(0.2);}});
	$('news_previous_button').addEvents({'mouseover': function(){$('news_previous_button_bg').fade(0.5);},'mouseout': function(){$('news_previous_button_bg').fade(0.2);}});
	$('shoutbox_button').addEvents({'mouseover': function(){$('shoutbox_button_bg').fade(0.5);},'mouseout': function(){$('shoutbox_button_bg').fade(0.2);}});
	$('shout_submit_button').addEvents({'mouseover': function(){$('shout_submit_button_bg').fade(0.5);},'mouseout': function(){$('shout_submit_button_bg').fade(0.2);}});
	$('shout_news_button').addEvents({'mouseover': function(){$('shout_news_button_bg').fade(0.5);},'mouseout': function(){$('shout_news_button_bg').fade(0.2);}});
	$('stumble').addEvents({'mouseover': function(){$('stumble').fade(1.0);},'mouseout': function(){$('stumble').fade(0.6);}});
	$('donate').addEvents({'mouseover': function(){$('donate').fade(1.0);},'mouseout': function(){$('donate').fade(0.6);}});
	extras_info_add();
	$('stats').addEvent('click', function(){$('ookami').fade('out');$('stats_page').fade('hide');$('contact_msg').fade('hide');$('contact_page').fade('hide');$$('.extras').removeEvents('mouseover').removeEvents('mouseout');$$('div.extras_info').fade('hide');$('rss').tween('left', '103');$('twitter').tween('left', '103');$('stats').tween('right', '103');$('contact').tween('right', '103');$('rss_info').tween('top', '0');$('stats_info').tween('top', '0');$('twitter_info').tween('bottom', '0');$('contact_info').tween('bottom', '0');(function(){extras_info_add();}).delay(500);$('extras_main').morph({left: 200, width: 400});(function(){$('stats_page').fade('in')}).delay(500);$('extras_spoiler1').tween('top', '103');$('extras_spoiler2').tween('top', '103');$('extras_spoiler3').tween('bottom', '103');$('extras_spoiler4').tween('bottom', '103');});
	$('contact').addEvent('click', function(){$('ookami').fade('out');$('stats_page').fade('hide');$('contact_msg').fade('hide');$('contact_page').fade('hide');$$('.extras').removeEvents('mouseover').removeEvents('mouseout');$$('div.extras_info').fade('hide');$('rss').tween('left', '103');$('twitter').tween('left', '103');$('stats').tween('right', '103');$('contact').tween('right', '103');$('rss_info').tween('top', '0');$('stats_info').tween('top', '0');$('twitter_info').tween('bottom', '0');$('contact_info').tween('bottom', '0');(function(){extras_info_add();}).delay(500);$('extras_main').morph({left: 200, width: 400});(function(){$('contact_page').fade('in')}).delay(500);$('extras_spoiler1').tween('top', '103');$('extras_spoiler2').tween('top', '103');$('extras_spoiler3').tween('bottom', '103');$('extras_spoiler4').tween('bottom', '103');});
	var aff_scroll = new Fx.Scroll($('affiliates')).set(0,0);
	$('loader1').fade('hide');
	$('donate').getElement('form').fade(0.01);
	$$('div.filter_button_bg').fade('hide');
	$$('div.extras_info').fade('hide');
	$('filter1_bg').fade(0.7);
	$('walls_gallery').fade('hide');
	$('series_loader').fade('hide');
	$('walls_control').fade('hide');
	$('walls_control').setStyle("height", "0px");
	$('walls_loader').fade('hide');
	var Series_Scroll = new MooScroller($E('div#series_list'), $E('div#series_knob'));
	$('walls_floral').fade(0.3);
	$('extras').fade('hide');
	$('signature').fade('hide');
	$('stumble').fade(0.6);
	$('donate').fade(0.6);
	$('stats_page').fade('hide');
	$('contact_page').fade('hide');
	$('contact_msg').fade('hide');
	$$('.about_button').fade('hide');
	$('deto_spoilers').fade('hide');
	$('nysha_spoilers').fade('hide');
							   
  	$$('.gallery_image img').getPrevious().fade('out');
 	$$('.gallery_image img').fade(1);
	
	start_animation();
});

window.addEvent('domready', function(){
	$('contact_form').addEvent('submit', function(e) {
		new Event(e).stop();
		$('contact_msg').fade('in');
		this.set('send', {onComplete: function(response) {
			$('contact_msg').set('html', response);
		}});
		this.send();
	});
});