
var topMenu_width		=	0;
var topMenu_height		=	0;
var topMenu_minWidth	=	920;
var topMenu_animation_duration	=	400;
var thumb_width			=	120;
var thumb_height		=	120;



$(document).ready(function() {
  dopPicturesCountx = Math.ceil(($("body").width()-60)/120);
  dopPicturesCounty = $("body").height() < 1080 ? 9 : Math.ceil(($("body").height()-60)/120);
  dopPicturesCount  = dopPicturesCountx * dopPicturesCounty - 81;
  if (dopPicturesCount > 0) {
   morePictures(dopPicturesCount);
   

  } 
 
 
	topMenu_height	=	$('#top_menu').height();
	
	$('#top_menu_minimize_button').click(function () {minimizeTopMenu();});	
	
	// Show top_menu
	$('#top_menu_maximize_button').click( function() {
		
		$('#top_menu').addClass('top_menu_full_before_maximize');
		
		$('#top_menu').animate({
				width:topMenu_width,
				height:topMenu_height
			}, {
			duration: topMenu_animation_duration,
			complete: function() {
				$('#top_menu').removeClass('top_menu_small');
				$('#top_menu').removeClass('top_menu_full_before_maximize');
				$('#top_menu_minimize_button').show();
			}
		})
		$(this).blur();
		return false;
	});
	
	$('#bottom_menu_minimize_button').click(function () {minimizeBottomMenu();});	
	
	
	
	$(window).resize(function(){
				  
		if (!$('#top_menu').hasClass('top_menu_small')) {
			sizeTopMenu();
		}
		
		sizeThumbs();
		sizeBottomMenu();
		
	});
	
	
	$('#login_link').click(function(){
		hover_panel_active	=	1;	
		$('#top_menu_minimize_button').click();
		setTimeout('showHoverPanel("login_panel")', topMenu_animation_duration+100);
		$(this).blur();
	});
	$('#reg_link').click(function(){
		hover_panel_active	=	1;
		$('#top_menu_minimize_button').click();
		setTimeout('showHoverPanel("reg_panel")', topMenu_animation_duration+100);
		$(this).blur();
	});
	
	
	$('.login_link2').click(function(){
		$('#reg_panel').hide();
		$('#login_panel').show();
		$(this).blur();
	});
	$('.reg_link2').click(function(){
		$('#reg_panel').show();
		$('#login_panel').hide();
		$(this).blur();
	});
	
	$('a.back_from_panel').click(function(){
		hideHoverPanel(this);
		$('#top_menu').removeClass('top_menu_small_panel');
		setTimeout("$('#top_menu_maximize_button').click()", topMenu_animation_duration+100);
		hover_panel_active	=	0;
	});
	
	
	$('.checkbox_desc').click(function(){
		$(this).prev().click();
	});
	
	
	sizeTopMenu();
	sizeThumbs();
	sizeBottomMenu();
	
 var reg = /(more)$/;
 if(reg.test(this.location) === true) {
  minimizeTopMenu();
  minimizeBottomMenu();
 }
	
});

function morePictures (c) {
 $.post("/ajax/more_picture.php", {count : c}, function (data) {
  $(data).appendTo("#main_images_container");
		if (!$('#top_menu').hasClass('top_menu_small')) {
			sizeTopMenu();
		}
		
		sizeThumbs();
		sizeBottomMenu();
  });
}

function minimizeTopMenu() {
		
		$('#top_menu').animate({
				width:'190px',
				height:'102px'
			}, {
			duration: topMenu_animation_duration,
			complete: function() {
				$('#top_menu').addClass('top_menu_small');
				$('#top_menu_minimize_button').hide();
			}
		})
		
		$(this).blur();
		return false;
}

function minimizeBottomMenu() {
		
		$('#bottom_menu').hide('drop',{duration:1000});

		$(this).blur();
		return false;
}

function sizeTopMenu() {
	topMenu_width	=	$('body').width()-100;
	
	if (topMenu_width < topMenu_minWidth) 
		topMenu_width	=	topMenu_minWidth;
	
	$('#top_menu').width(topMenu_width);

}

function sizeBottomMenu() {

	bottomMenu_width	=	$('body').width()-100;
	
	if (bottomMenu_width < topMenu_minWidth) 
		bottomMenu_width	=	topMenu_minWidth;
	
	$('#bottom_menu').width(topMenu_width);
	
	bottomMenu_top	=	$('#main_images_overflow').height() - $('#bottom_menu').height() - 20;
	
	$('#bottom_menu').css('margin-top',bottomMenu_top);
}

function sizeThumbs() {
	thumbs_total		=	$('#main_images_container').children().length;
	thumbs_per_width	=	parseInt($(window).width() / thumb_width) + 1;
	thumbs_per_height	=	parseInt(thumbs_total / thumbs_per_width);

	$('#main_images_container').width(thumb_width	*	thumbs_per_width);
	
	$('#main_images_overflow').width($(window).width());	
	$('#main_images_overflow').height(thumb_height	*	thumbs_per_height);	
}






