var search_id = 0;
var search_box = false;
var busy = ' <img src="/images/busy.gif" border="0" align="absmiddle" class="agc_busy" />';
var page_content_array = new Array();

var search_bg = new Image(250,120).src="/images/search_bg.png";
var blue_more_gif = new Image(6,18).src="/images/blue_more.gif";
var busy_gif = new Image(15,15).src="/images/busy.gif";

$(document).ready(function(){
	
	$('div.navig').hover(
		function(){
			$(this).stop().animate({"left": "-100px"}, "slow");
			$("div.block").stop().animate({"left": "-100px"}, "slow");
			$("div.block_title").fadeOut("slow");
			
		},function(){			
				$(this).stop().animate({"left": "-725px"}, "slow");
				$("div.block").stop().animate({"left": "-725px"}, "slow");
				$("div.block_title").fadeIn("slow");			
		}
	);
	
	
		
	$('div.sec_block').hover(
		function(){
			$(this).stop().animate({"left": "-400px"}, "slow");
			$("div.block2").stop().animate({"left": "-400px"}, "slow");
		},function(){			
				$(this).stop().animate({"left": "-725px"}, "slow");	
				$("div.block2").stop().animate({"left": "-725px"}, "slow");	
		}
	);	
	
	$("div.navig li").mouseover(
			function () {
				var rel = $(this).attr("rel");
				
				$("#menuitemcontentholder").html($("div#menuitemcontent"+rel).html());
				/*
				$("#menuitemcontentholder").fadeOut("normal", function(e){
					$("#menuitemcontentholder").html('');
				});
				
				$("#menuitemcontentholder").fadeIn("slow", function(e){
					$("#menuitemcontentholder").html($("div#menuitemcontent"+rel).html());
				});	*/
			
				return false;
				
			});
			
			
$('a.click').click(function () {
		
		if ($("div.search_act").is(":hidden")) {   				
				 $("div.inner_search").show();
				 $("div.search_act").show();
				  $(this).css("color", "#006FB7");
 
  } else {     			
				$("div.inner_search").hide(); 
				$("div.search_act").hide(); 
				 $(this).css("color", "#FFFFFF");
 		 }
 return false;
	});		
		
	$('.windowclose').bind('click', function(e){
		$('.jqmWindow').jqm().jqmHide();
	});
	
	$(".search_field").keypress( function() { 
		search_id = 0;
	} );
	
	$(".search_field").focus( function() { 
		if($(this).attr("id") == "") {
			$(this).attr("id","changed");
			this.value='';
		}
	} );
	
	$("#search_do").bind("click", function(e){ 
		SearchLoad(1); 
	});
	
	$(".search_box").bind("click", function(e){ 
		search_box = this.checked ; 
		search_id = 0;
	});
	
	$(".ajaxGetContent").bind("click",  function(){ 
		rel = $(this).attr("rel");
		href = $(this).attr("href");
		ajaxGetContent(this);
		return false;
	});
	
}); 

function SearchLoad(page){
	
	$('#search_window').jqm({target: '.target', overlay: '9', modal: false}).jqmShow();
	
	var str = $('.search_field').val();
	
	$('#search_img').show();
	
	$("#search_content").html("");
	
	$.post(
		"/_front_end/go.php?what=search&action=search", 
		{
			str: str, 
			page: page, 
			only_news: search_box, 
			search_id: search_id
		},
		function(xml){
			if($("message", xml).attr('result') == 1) {
				if($("pager", xml).text() == "&nbsp;"||$("pager", xml).text() == "&nbsp;1&nbsp;") 
					$("#search_pager").hide();
				else $("#search_pager").show();
				$('#search_img').hide();
				$("#search_pager").html($("pager", xml).text());
				$("#search_content").html($("content", xml).text());
				search_id = $("message", xml).attr('search_id');
			} else
				alert($("message", xml).text());
		}
	);	
	
	return false;
	
}

function ajaxGetContent(obj){
	var div = ($(obj).attr("rel") == undefined || $(obj).attr("rel") == "")?$("#alpc"):$("#"+$(obj).attr("rel"));
	if($("img",obj).attr("rel") == undefined) {
		
		$(obj).append(busy);
		
		$.post(
			'/_front_end/go.php?what=structure&action=get_content',
			{nick: href},
			function(xml){ 
				if($("message", xml).attr('result') == 1){
					div.html($("message", xml).text());
					$("img",obj).attr("rel",page_content_array.length);
					page_content_array[page_content_array.length] = $("message", xml).text();
					$(".agc_busy").hide();				
					return false;
				}
					
			}
		);
	} else {
		div.html(page_content_array[$("img",obj).attr("rel")]);
		
	}
	return false;
}