var scroll_timeout;

Cufon.replace('.cufon');

function get_win_width() {
	var myWidth = 0;
	if( typeof( window.innerWidth ) == 'number' ) //Non-IE
		myWidth = window.innerWidth;
	else if( document.documentElement && document.documentElement.clientWidth ) //IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
	else if( document.body && document.body.clientWidth) //IE 4 compatible
		myWidth = document.body.clientWidth;
	return myWidth;
}

function get_win_height() {
	var myHeight = 0;
	if( typeof( window.innerHeight ) == 'number' ) //Non-IE
		myHeight = window.innerHeight;
	else if( document.documentElement && document.documentElement.clientHeight ) //IE 6+ in 'standards compliant mode'
		myHeight = document.documentElement.clientHeight;
	else if( document.body && document.body.clientHeight) //IE 4 compatible
		myHeight = document.body.clientHeight;
	return myHeight;
}

function get_scroll() {
	var yPos = 0;
	if (self.pageYOffset) {
		yPos = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){
		yPos = document.documentElement.scrollTop;
	} else if (document.body) {
		yPos = document.body.scrollTop;
	}
	return yPos;
}

var roster_cell_selected = 0;
var fractions = {1: "Legion", 2: "Hellbourne"};
var shops = {
	1: "Accessories", 2: "Weapons", 3: "Relics", 4: "Supplies", 5: "Secret shop", 6: "Outpost",
	7: "---",
	8: "Initiation", 9: "Supportive", 10: "Protective", 11: "Combative", 12: "Morph"
};
var current_page = '';

$(document).ready(function(){

	$(".icon_values td").tooltip();
	$("span.arrow_up").tooltip();
	$("span.arrow_down").tooltip();
	
	$("#heroes_scroll a").tooltip();
	
	$("a.bb_hero_portrait, a.bb_spell_portrait, a.bb_hero_portrait_64, a.bb_spell_portrait_64, a.bb_hero_portrait_128, a.bb_spell_portrait_128").tooltip();

	$('.account_more').click(function(){
		$('.account_addinfo_content').toggle();
	});

	var stat_gauge_animation = function(){
		var elem = $(this);
		var value = elem.attr('rel');
		var width = parseInt(elem.css('width'));			
		var nwidth = Math.round(width / 100 * value);
		
		elem.find('.fill').css({width: '0px'}).animate({
			width: nwidth+"px"
		}, 2000);
	};

	$('.stat_gauge').each(stat_gauge_animation);
	
	$('div.link_account').click(function(){
		$('#link_account_window .inner > div').hide();
		$('#link_account_window .inner > form').show();

		$(parent).find('.status.loading').show();
		$.openDOMWindow({  
			width:410,
			windowSourceID:'#link_account_window',
			windowBGColor:'transparent',
			modal:true,
			overlayOpacity:'50'
		});
	});
	
	$('#link_account_form').submit(function(){
		var parent = $(this).parent();
		var action = $(this).attr('action');
		var params = $(this).serializeArray();
		
		$(parent).children().hide();
		$(parent).find('.status.loading').show();
		$.post(action, params, function(result){
			var status = result.substr(0, 4);
			var message = result.substr(4);
			if (status == 'ook:')
			{
				$(parent).children().hide();
				$(parent).find('.status.ok .text').html(message);
				$(parent).find('.status.ok').show();
			} else
			{
				if (status != 'err:') message = result;
				$(parent).children().hide();
				$(parent).find('.status.error .text').html(message);
				$(parent).find('.status.error').show();
			}
		});		

		return false;
	});
	
	$("#signatures img").click(function(){
		var uid = $("#signatures").attr('rel');
		var num = $(this).attr('rel');
		$("#signatures #code #forum").val('[url=http://heroesofnewerth.ru/account/view/'+uid+'][img]http://heroesofnewerth.ru/signatures/get/'+uid+'/'+num+'.png[/img][/url]');
		$("#signatures #code #url").val('http://heroesofnewerth.ru/signatures/get/'+uid+'/'+num+'.png');
		$("#signatures #code").show();
	});
	
	$("#userbars img").click(function(){
		var uid = $("#userbars").attr('rel');
		var num = $(this).attr('rel');
		$("#userbars #code #forum").val('[url=http://heroesofnewerth.ru/account/view/'+uid+'][img]http://heroesofnewerth.ru/signatures/get/'+uid+'/'+num+'.png[/img][/url]');
		$("#userbars #code #url").val('http://heroesofnewerth.ru/signatures/get/'+uid+'/'+num+'.png');
		$("#userbars #code").show();
	});

	$(".search_bar .search_button").click(function(){
		$(".search_bar form").submit();
	});

	$(".pages ol li a").click(function(){
		var id = $(this).attr('href').substr(1);
		if (window.current_page != id)
		{
			window.current_page = id;
			$(this).parent().parent().parent().attr('id', id);
		
			window.roster_cell_selected = 0;
			
			$(".subpage").hide();
			$(".subpage#"+id).show();
		}
		
		return false;
	});

	$(".togglecategory").click(function(){
		id = $(this).attr('rel');
		
		var fc = $("#fc_"+id);
		var fo = $("#fo_"+id);

		if (fc.css('display') == 'none')
		{
			fc.show();
			fo.hide();
		} else
		{
			fc.hide();
			fo.show();
		}
	});
	
	$(".togglecategory2").click(function(){
		var id = $(this).attr('rel');
		$("#fo_"+id+" .contentrow").toggle();
		if ($("#fo_"+id+" .contentrow").css('display') == 'none')
		{
			$(this).css('background-position', 'left bottom');
		} else
		{
			$(this).css('background-position', 'left top');
		}
	});

	$(".m_search a").click(function(){
		$(".m_search form").submit();
	});
	
	$("button#preview").click(function(){
		$.post('/news/preview', $("form.edit_item").serializeArray(), function(response){
			$("#preview_box").html(response);
		});
		return false;
	});

	function bind_messages_controls(){
		$(".comment.removable").prepend('<div class="remove_comment"></div>');
		$(".comment.removable .remove_comment").click(function(){
			var elem = $(this);
			var id = elem.parent().attr('rel');
			$.post('/account/remove_comment', {id: id}, function(response){
				if (response == "ok")
				{
					elem.parent().animate({opacity:0}, 500, function(){ $(this).hide(); });
				}
			});
		});

		$(".messages_block .pager a").click(function(){
			var elem = $(this);
			var id = $(".messages_block").attr('rel');
			var page = elem.attr('rel');
			$.post('/account/get_messages', {id: id, page: page}, function(response){
				$(".messages_block").html(response);
				bind_messages_controls();
			});
		});
	}
	
	/*
	var change_resized_img = function(){
		var elem = $(this);
		if (elem.hasClass('small'))
		{
			elem.removeClass('small');
		} else
		{
			elem.addClass('small');
		}
	};

	$("#ipbwrapper img").load(function(){
		var width = $(this).width();
		if (width > 600)
		{
			$(this).addClass('resized').addClass('small').click(change_resized_img);
		}
	});
	*/
	
	bind_messages_controls();
	
	// kb stuff
	
/*
	var sortable_on_stop = function(event, ui) {
		var ids = $(this).sortable('serialize');
		var parent = $(this).attr('id');
		var parent_id = $(this).attr('rel');
		$("#loader").show();
		$.post('/'+parent+'/update_places', {ids: ids, parent_id: parent_id}, function(result){
			$("#loader").hide();
		});
	};
*/
	
	var roster_cell_hover = function(){
//		if (window.roster_cell_selected > 0) return false;

		var id = $(this).parent().parent().attr('rel');
		var hero = window.heroes[id];

		$(this).parent().parent().addClass('selected');

		$("#name_stats #name .name").html(hero["name"]);
		$("#name_stats #stats .str .value").html(hero["str"]);
		$("#name_stats #stats .agi .value").html(hero["agi"]);
		$("#name_stats #stats .int .value").html(hero["int"]);
		$("#name_stats #stats > div").removeClass("primary");
		
		if (hero["pic"] != "")
			$("#name_stats #portrait img").attr("src", "/static/pictures/56/"+hero["pic"]);
		else
			$("#name_stats #portrait img").attr("src", "/static/no_pic56.gif");
		
		if (hero["hru"] != "")
			$("#full_info a").attr("href", "/heroes/view/"+hero["hru"]);
		else
			$("#full_info a").attr("href", "/heroes/view/"+hero["id"]);
		
		if (hero["primaryattr"] == 1) $("#name_stats #stats .str").addClass("primary");
		if (hero["primaryattr"] == 2) $("#name_stats #stats .agi").addClass("primary");
		if (hero["primaryattr"] == 3) $("#name_stats #stats .int").addClass("primary");
		
		$(".stat#fraction").html(window.fractions[hero["fraction"]]);

		$(".stat#dmg_min").html(hero["dmg_min"]);
		$(".stat#dmg_max").html(hero["dmg_max"]);
		$(".stat#armor").html(hero["armor"]);
		$(".stat#move_speed").html(hero["move_speed"]);
		$(".stat#range").html(hero["range"]);
		$(".stat#attack_speed").html(hero["attack_speed"]);
		
		$("#spells .spell").hide();
		
		var spells_count = 0;

		for (var i = 0; i <= 3; i++)
		{
			if (hero["spells"][i]["enabled"] == true)
			{
				spells_count++;
				
				if (hero["spells"][i]["pic"] != "")
					$("#spells #spell"+(i+1)+" .icon img").attr("src", "/static/pictures/32/"+hero["spells"][i]["pic"]);
				else
					$("#spells #spell"+(i+1)+" .icon img").attr("src", "/static/no_pic.gif");

				$("#spells #spell"+(i+1)+" .title .shortname").html("Action: "+hero["spells"][i]["action"]);
				$("#spells #spell"+(i+1)+" .title .name").html(hero["spells"][i]["name"]);
				$("#spells #spell"+(i+1)).show();
			}
		}
		if (spells_count > 0)
			$("#spells_panel").show();
		else
			$("#spells_panel").hide();
		
		$("#wnd1").show();
	};
	
	var roster_cell_click = function(){
		var id = $(this).parent().parent().attr('rel');
		
		if (window.roster_cell_selected > 0 && id == window.roster_cell_selected)
		{
			window.roster_cell_selected = 0;
			$(this).hover();
			$(this).removeClass('selected');
		} else
		{
			$("#roster ul li").removeClass('selected');
			window.roster_cell_selected = 0;
			$(this).hover();
			window.roster_cell_selected = id;
		}

		return false;
	};
	
	var roster_cell_mouseout = function(){
		$(this).parent().parent().removeClass('selected');
		if (window.roster_cell_selected > 0)
		{
			$("#roster li[rel="+window.roster_cell_selected+"] img").hover();
		}
	};
	
	if ($("#details #heroes_scroll .scrollableArea li").length > 9)
	{		
		var startElement = $("#details #heroes_scroll .scrollableArea").attr('rel');
		$("#details #heroes_scroll").smoothDivScroll({
			scrollableArea:'.scrollableArea',
			startAtElementId: startElement
		});
	}
/*
	$("#details #heroes_scroll li a").click(function(){
		var id = $(this).parent().attr('rel');
		$('.tabs .info a').attr('href', '/heroes/view/'+id);
		$('.tabs .guide a').attr('href', '/heroes/guide/'+id);

		$("#details #heroes_scroll li").removeClass('selected');
		$(this).parent().addClass('selected');
		$("#wnd2").load($(this).attr("href")+" #wnd2", function(){	
			bind_guide_controls(true);
		});
		return false;
	});
*/	

	if ($('.heroes_json').length > 0)
	{
//		$.getJSON('/static/heroes.js', function(data)
//		{
			var data = window.heroes;// = data;
			var heroesArray = new Array();

			$(".fraction").each(function(){
				var fraction_id = $(this).attr('rel');
				if (fraction_id != undefined)
				{
					$(this).find('.primaryattr').each(function(){
						var primaryattr_id = $(this).attr('rel');
						
						for (var i in data)
						{
							if (data[i].fraction == fraction_id && data[i].primaryattr == primaryattr_id)
							{
								var li = $('<li rel="'+i+'"><a href="/heroes/view/'+(data[i].hru == '' ? data[i].id : data[i].hru)+'"><img title="'+data[i].name+'" src="'+(data[i].pic != '' ? '/static/pictures/32/'+data[i].pic : '/static/no_pic.gif')+'"></a></li>');
								$(this).append(li);
								heroesArray.push(i);
							}
						}
					});
				}
			});
			
			$(".heroes_json li img").hover(roster_cell_hover);
			$(".heroes_json li img").mouseout(roster_cell_mouseout);
			$(".heroes_json li img").click(roster_cell_click);
			
//			$(".heroes_json ul").sortable({
//				stop: sortable_on_stop,
//			});
			$(".heroes_json ul").disableSelection();

			var randomHero = heroesArray[Math.floor(Math.random() * heroesArray.length)];
			$(".heroes_json li[rel="+randomHero+"] img").click();
//		});
	}
	
	var roster_items_cell_hover = function(){
		var id = $(this).parent().parent().attr('rel');
		var item = window.items[id];
		
		if (item["shop"] >= 1 && item["shop"] <= 6)
			$(".pages ol li a.items").click();
		if (item["shop"] >= 8 && item["shop"] <= 12)
			$(".pages ol li a.reciepes").click();

		$(this).parent().parent().addClass('selected');

		$("#name_stats #item_name .name").html(item["name"]);
		$("#name_stats #item_name .price").html(item["price"]);
		$("#name_stats #descr").html(item["descr"]);
		
		$("#buyat_panel .content").html(window.shops[item["shop"]]);

		if (item["effects_parsed"] != "")
		{
			$("#effects_panel .content").html(item["effects_parsed"]);
			$("#effects_panel").show();
		} else $("#effects_panel").hide();

		if (item["reciepes"] != undefined)
		{
			$("#reciepes_panel .content").html('<ul class="ingredients"></ul>');
			for (var i in item["reciepes"])
			{
				var reciepe_item = window.items[item["reciepes"][i]];
				if (reciepe_item != undefined)
				{
					var li = $('<li rel="'+reciepe_item["id"]+'"><div><img src="'+(reciepe_item["pic"] != '' ? '/static/pictures/32/'+reciepe_item["pic"] : '/static/no_pic.gif')+'"></div> '+reciepe_item["name"]+'<br><span class="item_price">'+reciepe_item["price"]+'</span></li>');
					li.click(leftpanel_items_click);
					$("#reciepes_panel .content ul").append(li);
				}
			}
			$("#reciepes_panel .content").append('<div class="clear"></div>');
			$("#reciepes_panel").show();
		} else $("#reciepes_panel").hide();
		
		if (item["ingredients"] != undefined)
		{
			$("#ingredients_panel .content").html('');
			for (var i in item["ingredients"])
			{
				$("#ingredients_panel .content").append('<ul class="ingredients" rel="'+i+'"></ul>');
				for (var j in item["ingredients"][i])
				{
					var ingredients_item_count = item["ingredients"][i][j]["count"];
					var ingredients_item = window.items[item["ingredients"][i][j]["id"]];
					if (ingredients_item != undefined)
					{
						var li = $('<li rel="'+ingredients_item["id"]+'"><div><img src="'+(ingredients_item["pic"] != '' ? '/static/pictures/32/'+ingredients_item["pic"] : '/static/no_pic.gif')+'"></div> '+ingredients_item["name"]+'<span class="multiplier">'+(ingredients_item_count>1?'x'+ingredients_item_count:'')+'</span><br><span class="item_price">'+ingredients_item["price"]+'</span></li>');
						li.click(leftpanel_items_click);
						$("#ingredients_panel .content ul[rel="+i+"]").append(li);
					}
				}
				if (item["scroll_price"] > 0)
				{
					var li = $('<li><div><img src="/static/scroll.gif"></div> '+item["name"]+'<br><span class="item_price">'+item["scroll_price"]+'</span></li>');
					$("#ingredients_panel .content ul[rel="+i+"]").append(li);
				}
				
				$("#ingredients_panel .content").append('<div class="ingredients_spacer"></div>');
			}
			$("#ingredients_panel .content").append('<div class="clear"></div>');
			$("#ingredients_panel").show();
		} else $("#ingredients_panel").hide();
		
		if (item["pic"] != "")
			$("#name_stats #portrait img").attr("src", "/static/pictures/56/"+item["pic"]);
		else
			$("#name_stats #portrait img").attr("src", "/static/no_pic56.gif");
		
		$("#wnd1").show();
	};
	
	var leftpanel_items_click = function(){
		var id = $(this).attr('rel');
		$(".items_json li[rel="+id+"] img").click();

		return false;
	};
	
	var roster_items_cell_click = function(){
		var id = $(this).parent().parent().attr('rel');
		
		if (window.roster_cell_selected > 0 && id == window.roster_cell_selected)
		{
			window.roster_cell_selected = 0;
			$(this).hover();
			$(this).removeClass('selected');
		} else
		{
			$(".items_json ul li").removeClass('selected');
			window.roster_cell_selected = 0;
			$(this).hover();
			window.roster_cell_selected = id;
		}

		return false;
	};

	var roster_items_cell_mouseout = function(){
		$(this).parent().parent().removeClass('selected');

		if (window.roster_cell_selected > 0)
		{
			$(".items_json li[rel="+window.roster_cell_selected+"] img").hover();
		}
	};
	
	if ($('.items_json').length > 0)
	{
//		$.getJSON('/static/items.js', function(data)
//		{
			var data = window.items;// = data;
			var itemsArray = new Array();

			$(".shop").each(function(){
				var shop_id = $(this).attr('rel');
				if (shop_id != undefined)
				{
					for (var i in data)
					{
						if (data[i].shop == shop_id)
						{
							var li = $('<li rel="'+data[i].id+'"><a href="/items#id='+(data[i].hru == '' ? data[i].id : data[i].hru)+'"><img title="'+data[i].name+'" src="'+(data[i].pic != '' ? '/static/pictures/32/'+data[i].pic : '/static/no_pic.gif')+'"></a></li>');
							$(this).append(li);
							itemsArray.push(data[i].id);
						}
					}
				}
			});
			
			$(".items_json li img").hover(roster_items_cell_hover);
			$(".items_json li img").mouseout(roster_items_cell_mouseout);
			$(".items_json li img").click(roster_items_cell_click);
			
			var randomItem = itemsArray[Math.floor(Math.random() * itemsArray.length)];
			$(".items_json li[rel="+randomItem+"] img").click();
//		});
	};

	var recalculate_carousel_index = function(elem){
		var id = $(elem).attr('rel');
		var total = $('.carousel_items[rel='+id+']>div').length;
		var current = 0;
		var counter = 0;
		$('.carousel_items[rel='+id+']>div').each(function(){
			counter++;
			
			if ($(this).hasClass('visible')) current = counter;
		});
		
		$(elem).find('.pager').html(current+'/'+total);
	};

	var bind_guide_controls = function(forced){
		$(".so_title").click(function(){
			var id = $(this).attr("rel");
			
			$(".so_title").parent().removeClass("active");
			$(".so .scrollable").hide();

			$(this).parent().addClass("active");
			$(".so #"+id).show();
		});
		
		$(".io_title").click(function(){
			var id = $(this).attr("rel");
			
			$(".io_title").parent().removeClass("active");
			$(".io").hide();

			$(this).parent().addClass("active");
			$(".io#"+id).show();
		});
		
/*
		$(".text_title").click(function(){
			var id = $(this).attr('rel');
			$(".guide_text#"+id).toggle();
		});
*/

		if (forced)
		{
			$(".scrollable:visible").smoothDivScroll({
				scrollableArea:'.scrollableArea',
				forcedOnLoad: true
			});

			$(".scrollable:hidden").smoothDivScroll({
				scrollableArea:'.scrollableArea',
				hiddenOnStart:true,
				forcedOnLoad: true
			});
		} else
		{
			$(".scrollable:visible").smoothDivScroll({
				scrollableArea:'.scrollableArea'
			});

			$(".scrollable:hidden").smoothDivScroll({
				scrollableArea:'.scrollableArea',
				hiddenOnStart:true
			});
		}
		
		$(".bag img,.popup").mouseover(function(){
			$(this).parent().parent().find('.popup').show();
		});
		
		$(".bag img,.popup").mouseout(function(){
			$(this).parent().parent().find('.popup').hide();
		});
		
		$(".recommented_items li img, a.bb_item_portrait img, a.bb_item_portrait_64 img, a.bb_item_portrait_128 img, .tactics_block .items li img").tooltip({
			bodyHandler: function() {
				var id = $(this).parent().attr('rel');
				var body = '';
				
				body += '<h4>'+items[id]["name"]+' <span class="item_price">'+items[id]["price"]+'</span></h4>';

				if (items[id]["descr"] != "") body += '<p>'+items[id]["descr"]+'</p>';
				if (items[id]["effects_parsed"] != "") body += items[id]["effects_parsed"]
				
				for(var i in items[id]["ingredients"])
				{
					body += '<div class="tooltip_items_block">';
					var ingredients = items[id]["ingredients"][i];
					for(var j in ingredients)
					{
						var ingid = ingredients[j]["id"];
						var ingcount = ingredients[j]["count"];
						var ingredient = items[ingid];
						body += '<div class="tooltip_item" rel="'+ingid+'"><img align="left" src="'+(ingredient["pic"]!=""?'/static/pictures/32/'+ingredient["pic"]:'/static/no_pic.gif')+'"> <strong>'+ingredient["name"]+'</strong><span class="multiplier">'+(ingcount>1?'x'+ingcount:'')+'</span><br><span class="item_price">'+ingredient["price"]+'</span></div>';
					}
					if (items[id]["scroll_price"] > 0)
					{
						body += '<div class="tooltip_item"><img align="left" src="/static/scroll.gif"> <strong>'+items[id]["name"]+'</strong><br><span class="item_price">'+items[id]["scroll_price"]+'</span></div>';
					}
					body += '<div class="clear"></div></div>';
				}
				
				return body;
			},
			showURL: false,
			extraClass: 'fixed_width_tooltip'
		});
		
		$('.view3d_button').click(function(){
			$('.view3d').slideToggle('fast');
		});
		
		$('.carousel_controls .prev').click(function(){
			var id = $(this).parent().attr('rel');
			$('.carousel_items[rel='+id+']>div.visible').each(function(){
				var prev = $(this).prev();
				if (prev.length)
				{
					$(this).removeClass('visible');
					$(this).prev().addClass('visible');
				} else
				{
					$('.carousel_items[rel='+id+']>div').removeClass('visible');
					$('.carousel_items[rel='+id+']>div:last').addClass('visible');
				}
				$('.carousel_items[rel='+id+']>div').hide();
				$('.carousel_items[rel='+id+']>div.visible').show();
			});
			recalculate_carousel_index($(this).parent());
		});
		
		$('.carousel_controls .next').click(function(){
			var id = $(this).parent().attr('rel');
			$('.carousel_items[rel='+id+']>div.visible').each(function(){
				var next = $(this).next();
				if (next.length)
				{
					$(this).removeClass('visible');
					$(this).next().addClass('visible');
				} else
				{
					$('.carousel_items[rel='+id+']>div').removeClass('visible');
					$('.carousel_items[rel='+id+']>div:first').addClass('visible');
				}
				$('.carousel_items[rel='+id+']>div').hide();
				$('.carousel_items[rel='+id+']>div.visible').show();
			});
			recalculate_carousel_index($(this).parent());
		});
		
		var interval = setInterval(function(){
			recalculate_carousel_index($('.carousel_controls'));
			$('#tactics .carousel_items>div:not(.visible)').hide();
			clearInterval(interval);
		}, 1);
	};
	
	var update_graph = function(){
		if ($('#graphs input.graph_control.options:checked').length > 1 || $('#graphs input.graph_control.options[val=usage]:not(:checked)').length)
		{
			$('.graphs>.graph_title>.title_text').addClass('custom');
		} else
		{
			$('.graphs>.graph_title>.title_text').removeClass('custom');
		}
		
		$('#graph_window').html('<div class="graph_loader"></div>');

		var form_data = $("#graphs").serializeArray();
		$.post('/heroes/graph_xml', form_data, function(result){
			var so = new SWFObject("/static/amline.swf", "amline", "768", "468", "8", "#000003");
			so.addParam("wmode", "transparent");
			so.addVariable("path", "/static/");
			so.addVariable("preloader_color", "#ffffff");
			so.addVariable("settings_file", encodeURIComponent("/static/amline_settings.xml"));
			so.addVariable("chart_data", escape(result));
			so.write("graph_window");
		});
	};

	$('.graph_control').change(update_graph);
	
	$('.graph_settings .btn').click(function(){
		var id = $(this).attr('rel');
		$('.graph_settings .graph_settings_elements').hide();
		$('.graph_settings .graph_settings_elements.'+id).show();
	});

/*
	if ($(".recommented_items li img").length > 0 || $(".bb_item_portrait").length > 0 || $(".tactics_block").length > 0)
	{
		$.getJSON('/static/items.js', function(data)
		{
			window.items = data;
		});
	}
*/
	
	$('#table_of_contents>li').click(function(){
		var id = $(this).attr('rel');
		$('#table_of_contents>ul[rel='+id+']').slideToggle('fast');
		if ($(this).hasClass('collapsed'))
			$(this).removeClass('collapsed');
		else
			$(this).addClass('collapsed');
	});

	bind_guide_controls();

	$(window).konami(function(){ $('.mainwrap').append('<img class="konami" src="/static/konami.svg">'); });
	
	$('.reload_clan_roster').click(function(){
		var id = $(this).attr('rel');
		$(this).hide();
		$('.account_clan_border .loader').show();
		$.get('/api/update_account_clan_info/'+id, function(response){
			$('.account_clan_border').html(response);
		});
	});
});