$(document).ready(function()
{
 $(".email").each(function()
 {
  var e = $(this).attr("href") + "@" + $(this).text();
  $(this).text(e);
  $(this).attr("href", "mailto:" + e);
 }
 );
 
 $("#submit_data").hover( function () {
 	$(this).attr("src","/i/send_hover.jpg");
 }).mouseout( function () {
 	$(this).attr("src","/i/send.jpg"); 	
 });
 
 $("#left_arrow").click( function() {
 	redraw_calendar(-1);
 });
 
 $("#right_arrow").click( function() {
 	redraw_calendar(1);
 });
 
 $(".monthbtns").click ( function() {
 	$("div.month ul li").removeClass("selected");
 	$(this).addClass("selected");
 	
 	$("#opacity").show();
 	$("#loader").show();
 	var height = $("#calendar").height();
 	$("#calendar_carcas").css("height",height + "px");
 	
 	var el = this;
    var params = $(el).attr('id').toString();
    params = params.split("_");
 	var id = params[1];
 	
 	$.getJSON(
 		'/calendar',
 		{
  			id: id,	
  			load_calendar: true
 		},
 		function(obj)
 		{
		 $("#calendar").hide();
		 $("#calendar").empty();
		 $("#calendar").html(obj.html);
		 $("#month_name").html(obj.month);
		 
		var height = $("#calendar").height();
 		$("#calendar_carcas").css("height",height + "px");
		 
		 $("#calendar").show("slow");
		 $("#opacity").hide();
 		 $("#loader").hide();
 		}
 		);
 });
}
);

function redraw_calendar(param) {
 	$("#opacity").show();
 	$("#loader").show();
 	var height = $("#calendar").height();
 	$("#calendar_carcas").css("height",height + "px");
 	$.getJSON(
 		'/calendar',
 		{
  			param: param,	
  			change_year: true
 		},
 		function(obj)
 		{
		 $("#calendar").hide();
		 
		 $("#year_name").html(obj.year);
		 $("#year").html(obj.year);
		 
		 $("#calendar").empty();
		 $("#calendar").html(obj.html);
		 
		 var height = $("#calendar").height();
 		 $("#calendar_carcas").css("height",height + "px");
		 
		 $("#calendar").show("slow");
		 $("#opacity").hide();
 		 $("#loader").hide();
 		}
 		);	
}


function loadform(alias)
{
 $('#'+alias).ajaxForm(
 { 
  dataType:  'json', 
  success:   processJsonForm
 }
 );	
}

function processJsonForm(data)
{
 $("#inputresult").html(data.text);	
 if(data.done==1) 
 {
  $("#submit_data").attr("disabled","disabled");
  // ставим задержку, чтобы пользователь мог прочитать надпись
  setTimeout(function(){window.location = data.link;}, 2000);
 }
 else
 {
  $("#submit_data").attr("disabled","");	
 }
 $("#formajaxloader").empty();
}

function loadindicator()
{
 $("#formajaxloader").html("<div style=\"position:absolute;top:0px;left:50%;margin-left:-8px;width:16px;height:16px\"><img src=\"/i/ajax/orange.gif\" width=\"16\" height=\"16\" alt=\"\" /></div>");
}

function show_img(id)
{
 $("#description").empty();
 $("#description").show();	
 $("#img").empty();
 $("#img").show();
 $("#img").html("<div style=\"position:absolute;top:30px;left:50%;margin-left:-8px;width:16px;height:16px\"><img src=\"/i/ajax/orange_black.gif\" width=\"16\" height=\"16\" alt=\"\" /></div>")
 $.getJSON(
 '/gallery',
 {
  id: id,	
  show_img: true
 },
 function(obj)
 {
  $("#img").html(obj.html)
  $("#description").html(obj.description);
 }
 );	
}

function hideall()
{
 $("div#tumbhails div").hide();
}
