var content_proc = "/_front_end/go.php?what=structure";
var cache_content = new Array();	
var cache_page = new Array();	

$(document).ready(function(){
	
	$('.jqmWindow').hide();
	
	$('.sort_button').bind('click', function(e){
		if($("."+$(this).attr("id")).css("display") == "none"){
			$(this).addClass('act_green');
			if($(this).attr("id") == "alfa"){
				$("#beta").removeClass('act_green');
				$(".alfa").show();
				$(".beta").hide();
			} else {
				$("#alfa").removeClass('act_green');
				$(".alfa").hide();
				$(".beta").show();			
			}
		}
	});
	

	$('.close').bind('click', function(e){
		$('.jqmWindow').jqm().jqmHide();
	});
	
	$('#search').bind('click',  function(e){
		var search_block = $('#search_form');
		if(search_block.css("display") == "none") search_block.show();
		else search_block.hide();
		return false;
	});
	
	$('.show_in_jqm').bind('click', showInJQM);
				   
});

showInJQM = function() {
	$("#jqm_window_content").html("<div class=\"inner scroll-pane\"></div>");
	var link = $(this).attr("href"); //alert(link);
	link = link.replace(/http:\/\/games\.sands\.kg/i,"");
	if(cache_content[link]==undefined){
		$.post(
			content_proc+'&action=get_content',
			{link: link},
			function(xml){
				if($("message", xml).attr("result") == 1){ 
					cache_content[link] = xml;
					reScrool(link);
					$("#jqm_window").jqm({target: '.target', modal: true}).jqmShow();
				}
			}
		);
	} else {
		reScrool(link);
		$("#jqm_window").jqm({target: '.target', modal: true}).jqmShow();		
	}
	$('.map').facebox();
	return false;
}

function reScrool(link) {
	$(".scroll-pane").html($("message", cache_content[link]).text()).find(".show_in_jqm").bind('click', showInJQM);
	setTimeout('$(".scroll-pane").css("height",($(".scroll-pane").height())).jScrollPane()',100);
}

function showPage(obj) {
	$(".busy").css("visibility","visible");
	var id = $(obj).text() == ""?$(obj).attr("rel"):$(obj).text();
	if(cache_page[id]==undefined){
		$.post(
			content_proc+'&action=get_page',
			{id: id},
			function(xml){
				if($("message", xml).attr("result") == 1){ 
					cache_page[id] = xml;
					$("#page_content").html($("message", xml).text()).find('.show_in_jqm').bind('click', showInJQM);
					$(".busy").css("visibility","hidden");
				}
			}
		);
	} else {
		$("#page_content").html($("message", cache_page[id]).text()).find('.show_in_jqm').bind('click', showInJQM);	
		$(".busy").css("visibility","hidden");
	}
	
	return false;
}
