

jQuery(document).ready(
	
	function()
	{
		
		
		
		// manage min-height
		function manage_min_height(class_with_min)
		{
			var offset = jQuery("."+class_with_min).offset();
			
			if (offset)
			{
				var height = jQuery(".omilia").outerHeight(true);
				offset = offset.top;
				var min_height = height - offset + 10;
				jQuery("."+class_with_min).css("min-height", min_height+"px");
			}
		}
		
		manage_min_height("center_content_2_home");
		manage_min_height("center_content_2");
		manage_min_height("center_content_2_pages");
		
		var clicked_by_code = false;
		var slide_interval_hash = null;
		var func_autoslide = function ()
		{
			
			
			var slide_containers = jQuery(".gallery_item");
			for (var c_index = 0; c_index < slide_containers.length; c_index++)
			{
				var container = jQuery(slide_containers[c_index]);
				if (null!=container)
				{
					container.bind('mouseenter',function(){
						//clearInterval(slide_interval_hash);
					});
					container.bind('mouseleave',function(){
						//slide_interval_hash = setInterval(func_autoslide, 8000);
					});
				}
			}
						
			
			var list = jQuery(".gallery_buttons a");
			
			var sel_index = 0;
			for (var i = 0; i < list.length; i++)
				if (jQuery(list[i]).hasClass("selected"))
				{
					sel_index = i;
					break;
				}
				
			var next_index = (i == (list.length - 1)) ? 0 : i + 1;
			
			clicked_by_code = true;
			jQuery(list[next_index]).trigger("click");
			clicked_by_code = false;
		}
		
		var do_calendar_events = function ()
			{
				// alert("hmmm");
				var year = jQuery(this).attr("_year");
				var month = jQuery(this).attr("_month");
				
				var replacement_el = jQuery(this).closest(".d_calendar");
				var is_big = replacement_el.hasClass("d_calendar_big") ? 1 : 0;
				
				// alert(is_big);
				
				jQuery.ajax({
						type: "GET",
						url: "__ajax.php",
						data: {"year" : year, "month": month, "is_big": is_big, "__func" : "ajax_print_calendar_control", "__lang" : __lang },
						success: function(msg)
						{
							replacement_el.replaceWith(msg);
						}
					});
			};
		
		jQuery(".d_calendar .calendar_prev, .d_calendar .calendar_next").live("click", do_calendar_events);
		// jQuery(".d_calendar .calendar_prev_big, .d_calendar .calendar_next_big").live("click", do_calendar_events);
		
		var do_slide_events = function ()
			{
				// alert(clicked_by_code);
				if (!clicked_by_code)
					clearInterval(slide_interval_hash);
				
				var slide_id = jQuery(this).attr("id_slide");
				var div_class = "__gid_" + slide_id;
				
				// jQuery(".gallery_item:visible").hide();
				
				//jQuery("." + div_class).show();
				var last_div = jQuery(".gallery_item:visible");
				// var slide_id_last = last_div.attr("id_slide");
				// var div_class_last = "__gid_" + slide_id_last;
				
				if (last_div.hasClass(div_class))
					return;
				
				last_div.css({"z-index": "1"});
				jQuery("." + div_class).css({"z-index": "2", "display" : "block", "opacity" : "0"});
				// jQuery(".gallery_item:visible, ." + div_class).toggle();
				jQuery("." + div_class).animate({opacity: 1.0}, 900);
				last_div.hide();
				
				jQuery(this).closest(".gallery_buttons").find("a").removeClass("selected");
				jQuery(this).addClass("selected");





			}
		jQuery(".gallery_buttons a").live("click", do_slide_events);
		
		jQuery("a.photo_lightbox").lightBox();
		
		jQuery(".photos_for_gallery a.lightBox").lightBox();
		
		
		var func_manage_gall = function (event)
			{
				// jQuery(this).removeClass("same_photo")
				var new_img_big = jQuery(this).attr("__big_img");
				var new_img_small = jQuery(this).attr("__small_img");
				
				var big_a = jQuery(".all_photos_list").parent().find(".all_photos_big");
				var big_img = jQuery(".all_photos_list").parent().find(".all_photos_big img");
				
				big_a.attr("href", new_img_big);
				big_img.attr("src", new_img_small);
				
				jQuery(".photos_for_gallery a.all_photos_list").addClass('lightBox');
				jQuery(this).removeClass('lightBox');
				
				jQuery(".photos_for_gallery a.lightBox").lightBox();
				jQuery(".photos_for_gallery a.all_photos_list").unbind("click");
				jQuery(".photos_for_gallery a.all_photos_list").click(func_manage_gall);
				
				event.stopPropagation();
				
				return false;
			};
		
		jQuery(".photos_for_gallery a.all_photos_list").unbind("click");
		jQuery(".photos_for_gallery a.all_photos_list").click(func_manage_gall);
			
		
		
		slide_interval_hash = setInterval(func_autoslide, 8000);

	});

