/* JavaScript for module "Система статей" */

$(document).ready(function(){
	
	$("a.oe-preview-changer").click(function(){
		var id = $(this).attr("title");
		$("#oe-preview-"+id).html($("#"+id).val());
		$("#oe-preview-"+id).toggle();
		$("#"+id).toggle();
	});

	$("div.articles-in-column h3 a").mouseover(function(){
		var block = $(this).parent().parent();
		var offset = block.find("h3").offset();
		$(this).parent().addClass("active");
		block.find("div").css("top",offset.top + block.height()).css("left",offset.left).css("width",block.width() -12).slideDown(300);
	});

	$("div.articles-in-column h3").mouseout(function(){
		$(this).parent().find("div").stop(true, true).css("display","none");
		$(this).removeClass("active");
	});

});
	
/* JavaScript for module "Модуль компаний" */

$(document).ready(function(){

	$(".company-show-description").click(function(){
		$(this).css("display","none");
		$(this).parent().parent().find("div.company-description").fadeIn(500);
	});

	$(".company-show-by-tag").click(function(){
	
		$("#companies span.yellow").removeClass("yellow");
		$("#companies").attr("title",$(this).html());
		$(".company").css("display","none");
			
		if ($(this).attr("id") != 'company-show-all'){
		
			$(".company span.company-show-by-tag").each(function(i,elem){
				if ($(this).html() == $("#companies").attr("title")){
					$(this).addClass("yellow");
					$(this).parent().parent().parent().parent().fadeIn(500);
				}
			});
			
		} else {
			$(".company").fadeIn(500);
		}

		$("#companies").attr("title","");

	});
});
	
/* JavaScript for module "Модуль афиши" */

$(document).ready(function(){
	
	$("div#afisha-show-all-link a").click(function(){
		$("div#afisha-show-all-link a").css("display","none");
		$("div#afisha").css("height","auto");
	});

});
	
/* JavaScript for module "Вакансии" */

$(document).ready(function(){
$("div.job-digest:odd").addClass('job-digest-g1');
$("div.job-digest:even").addClass('job-digest-g2');
});
	
/* JavaScript for module "system.js" */

$(document).ready(function(){
	
	$("a.ajax").click(function(){
		
		if ($(this).hasClass("ausure")){
			var process = confirm('Вы уверены?');
		} else {
			var process = true;
		}
		
		if (process){
		
			var href = $(this).attr("href");
			href = href.substring(href.indexOf('?'),href.length);
			var url = href.substring(0,href.lastIndexOf('#'));
			var target = href.substring(href.lastIndexOf('#'),href.length);
			if (url != ''){
				ajax(url,target,'get','');
			} else {
				$(target).css("display","block");
			}
		
		}
		
	});
	
	$(".menu a.ajax").click(function(){
		$(".menu a.selected").removeClass("selected");
		$(this).addClass("selected");
	});
	
	$("form.ajax").submit(function(){
		var href = $(this).attr("action");
		href = href.substring(href.indexOf('?'),href.length);
		var url = href.substring(0,href.lastIndexOf('#'));
		var target = href.substring(href.lastIndexOf('#'),href.length);
		
		var query = '';
		
		$(this).find(".send").each(function(i){
			
			if (i > 0){
				query += '&';
			}
			
			query += $(this).attr("name")+"="+encodeURIComponent($(this).val());
		});
		
		ajax(url,target,$(this).attr("method"),query);
	});
	
	function ajax(query,textid,type,query2){
		
		if (query.charAt(0) == '?'){
			query = query.substring(1,query.length);
		}
				
		$.ajax({
			type: type,
			url: "http://ibryansk.ru/ajax.php?"+query,
			data: "ajax=ajax&"+query2+"&ajaxAntiCache="+Math.floor(Math.random()*100000 + 1),
			beforeSend: function(){
				$(textid).html('<img src="http://ibryansk.ru/files/www/ajax.gif" alt="AJAX Picture: http://ibryansk.ru/files/www/ajax.gif" />');
			},
			success: function(response){
				if (textid == '#page-text'){
					document.title = response.getElementsByTagName("header-title").item(0).firstChild.data;
					$("#page-title").html(response.getElementsByTagName("page-title").item(0).firstChild.data);
				}
				
				$(textid).html('');
				
				var i;
				var tmptext = '';
				var text = response.getElementsByTagName("page-text").item(0).getElementsByTagName("text");
				
	            for (i = 0; i < text.length; i++){
	            		tmptext += text.item(i).firstChild.data;
	            }
	            
	            if (tmptext.length > 0){
	            	$(textid).append(tmptext);
	            }
			}
		});
		
	}
	
});
	

