$(document).ready(function() 
{		
	add_fansybox();	
	bubleInfo('.photo_descr');
	page_limiter();			
	/* Buttons for stepcarousel control */
	$(".slider_left").click(function(){stepcarousel.stepBy('slider',-1);});
	$(".slider_right").click(function(){stepcarousel.stepBy('slider',1);});
	
	$("#gallery_photos").ajaxStop(function(){
		add_fansybox();		
		page_limiter();	
		bubleInfo('.photo_descr');
	});
});
function page_limiter()
{
	$(".page_limiter a").click(
		function()
		{
			var main_mod = $("#main_mod").val();
			main_mod = "&main_mod="+main_mod;
			var id = $("#tree_id").val();			
			var href = $(this).attr("href");			
			var page = parseInt(href.substring(href.lastIndexOf("/")+1));			
			if(page > 0) page = '&p='+page;
			else page = '';			
			var load = '/ajax/s/gallery/def/?tree_id='+id+main_mod+page;
			$("#gallery_photos").load(load);
			return false;
		}
	);
}
function add_fansybox()
{
	var isIE = ($.browser.msie && parseInt($.browser.version.substr(0,1)) < 8);
	if(isIE) 
	{	
		$('#gallery_photos a[target="_blank"],.belt a[target="_blank"]').fancybox({
			'zoomOpacity'			: false,
			'overlayShow'			: false,
			'zoomSpeedIn'			: 1,
			'zoomSpeedOut'			: 1
		});
	} 
	else {		
		 $('#gallery_photos a[target="_blank"],.belt a[target="_blank"]').fancybox({
			 'zoomOpacity'			: true,
		     'overlayShow'			: false,
		     'zoomSpeedIn'			: 0,
			 'zoomSpeedOut'			: 0
		 });
	}	 
}
function bubleInfo(selector)
{
    $(selector).each(function () {    	
        var distance = 10;
        var time = 250;
        var hideDelay = 100;

        var hideDelayTimer = null;

        var beingShown = false;
        var shown = false;
        var trigger = $('.photo_cont', this);
        var info = $('.popup', this).css('opacity', 0);
		
        $(this).next('.photo_img').mouseover(function () {        		
            if (hideDelayTimer) clearTimeout(hideDelayTimer);
            if (beingShown || shown) return;
            else
            {
                beingShown = true;
                
                info.css({
                    top: -40,
                    left: -33,
                    display: 'block'
                }).animate({
                    top: '-=' + distance + 'px',
                    opacity: 1
                }, time, 'swing', function() {
                    beingShown = false;
                    shown = true;
                });
            }

            return false;
        }).mouseout(function () {
            if (hideDelayTimer) clearTimeout(hideDelayTimer);
            hideDelayTimer = setTimeout(function () {
                hideDelayTimer = null;
                info.animate({
                    top: '-=' + distance + 'px',
                    opacity: 0
                }, time, 'swing', function () {
                    shown = false;
                    info.css('display', 'none');
                });

            }, hideDelay);

            return false;
        });
    });
}
