function reload_pages(dir,page){
			
            $.post('admin/pages.php', {dir:dir,page:page}, function(text) {
            $('.pages').html(text);
            });
}
function add_picter(){
			//$(".previews a").prettyPhoto({theme: 'light_square', showTitle: false, padding: 10});
			$(".previews a").find("img").live("mouseover",(function(){
cols = 5;
width = 201;
height = 112;
        current_index = parseInt($(this).attr("rel"));
        var old_rel = current_index;
        var left = ((current_index-1) % cols)*width;
        var top = parseInt((current_index-1)/cols)*height;
        title = $(this).attr("alt");
        author = $(this).attr("author");
        desc = $(this).parent().attr("title2");
    im_src = $(this).attr("src");
	big_src = $(this).parent().attr("href");

    var left_ed = left;
    var top_ed = top+90;

		$(".tooltip").html(desc);
		$(".tooltip").css({
						"left":left_ed+"px",
						"top":top_ed+"px",
						"position":"absolute",
						"background-color":"#000",
						"color":"#ffffff",
						"text-decoration":"none",
						"opacity":0.8,
						"width":(width-20)+"px",
						"height":(height-20)+"px",
						"display":"block",
						"text-align":"left",
						"cursor":"pointer",
						"padding": "10px"
						 });
                $(".tooltip > a").css({
                        "color":"#000000",
                        "text-decoration":"none"
                         });

}));
}
function pretty_ph(count){

	if(count==0) $(".tooltip a[rel^='prettyPhoto']").prettyPhoto({theme: 'light_square', showTitle: false, padding:10});
}
$(document).ready(function(){

            $("a[rel^='prettyPopin']").prettyPopin({
                callback : function(){
                }
            });
		$("a[rel^='prettyPhoto']").prettyPhoto({theme: 'light_square', showTitle: false, padding:20});	
cols = 5;
rows  = $('#rows').val();
width = 201;
height = 112;
count=0;
add_picter();

$(".tooltip").live("mouseout",(function(){
     $(".tooltip").css({"display":"none"});
    }));
$(".tooltip").live("click",(function(){
									$.prettyPhoto.open(big_src, title, desc);
									return false;
										 }));
			var buildoverlay = function() {
				$('body').append('<div id="overlay"><img src="../images/loader_cms.gif"></div>');
				$('#overlay').css('height',$(document).height());
				$('#overlay').css('opacity',0).fadeTo(400,0.7);
					$('#overlay').click(function(){
						closeOverlay();
					});
			};
			var closeOverlay = function() {
				$('#overlay').fadeOut(400,function(){ $(this).remove(); });
			};
         $('#menu').change(function(){
            dir = $("#menu option:selected").val();
			buildoverlay();
            var page = 1;
            $.post('picters.php', {dir: dir}, function(text) {
            $('.previews').html(text);
            var all_count = $('#prev').val();
            reload_pages(dir,"1");
            position_new="";
            closeOverlay();
            add_picter();
            return false;
            });
        });
        $(".pages > a").live("click",(function(){
            var dir = $("#menu option:selected").val();
            var page = $(this).text();
					if(page==">>"){ page = parseInt($(".current").text(), 10)+1; }
					if(page=="<<"){ page = parseInt($(".current").text(), 10)-1; }	

			buildoverlay();
            $.post('picters.php', {dir: dir, page:page}, function(text) {
            $('.previews').html(text);
            var all_count = $('#prev').val();
            reload_pages(dir,page);
            position_new="";
            $('.temp_data').empty();
			closeOverlay();
            add_picter();
            return false;
            });
        }));
})
