function openComments(baseurl, pht_key)
{
    window.open(baseurl+'/commenti.php?pht_key='+pht_key,'commenti'+pht_key, 'width=480,height=480,scrollbars=yes,status=yes'); 
}

scrolls = Array();
indexes = Object();
rollHeight = 0;
opened = 0;

function mycarousel_initCallback(carousel)
{
    carousel.clip.hover(function() {
            carousel.stopAuto();
    }, function() {
            carousel.startAuto();
    });
};

$(document).ready(function()
{
	if ($('body.galleries #galleries').length>0)
	{
	    $('body.galleries #galleries').jcarousel({
	        auto: 5,
	        scroll:1,
	        buttonNextHTML:"<div id='next'>next</div>",
	        buttonPrevHTML:"<div id='prev'>prev</div>",
	        initCallback: mycarousel_initCallback
	    });
	}    
    $("body.home #footer").css("top", $(window).height()-51+"px");
    
    if ($(document).height()!=$(window).height())
    {
        // Ci sono le scrollbar, sposto il menu
        var div = $('<div style="width:50px;height:50px;overflow:hidden;position:absolute;top:-200px;left:-200px;"><div style="height:100px;"></div>');
        // Append our div, do our calculation and then remove it
        $('body').append(div);
        var w1 = $('div', div).innerWidth();
        div.css('overflow-y', 'scroll');
        var w2 = $('div', div).innerWidth();
        $(div).remove();
        
        $("#menu").css("right", 40-(w1-w2)+"px");
    }
    
    $("#menu-laterale A").click( function() { _scrollTo($(this).attr("href").replace("#", "")); $("#menu-laterale A").removeClass("selected"); $(this).addClass("selected"); return false; } );
    
    // About
    i=0;
    $(".roll").each( function() { scrolls[i] = $(this).attr("id"); indexes[$(this).attr("id")] = i; i++; rollHeight = $(this).height(); } );
    $("#"+scrolls[0]).css("top", "0px");
    
    // Classifica
    if ($(".roller").length>0)
    {
		$(function() {
			$(".roller").smoothDivScroll({ autoScroll: "onstart", autoScrollDirection: "backandforth", autoScrollStep: 1, autoScrollInterval: 15});
		});
	}
	
	// Ricerca
	$("#ricerca .text").click(function() {$("#ricerca").addClass("active");});
	$("#ricerca FORM").submit(function() { document.location='/cerca/'+$("#ricerca .text").val(); return false; });
	
	
	$('.tip').each(function() {$(this).attr("tip", $(this).attr("title")).attr("title", "");});
	$('.tip').CreateBubblePopup({ themeName:"all-black", themePath: 	'http://www.mirkomacari.it/scripts/jquery/bubblepopup/jquerybubblepopup-theme', themeMargins: {total: '3px', difference: '0px' }} );
	$('.tip').mouseover(function(){
		$(this).ShowBubblePopup({ themeName:"all-black", themePath: 	'http://www.mirkomacari.it/scripts/jquery/bubblepopup/jquerybubblepopup-theme', themeMargins: {total: '3px', difference: '0px' }, innerHtml: $(this).attr("tip") });
	});

});

function scroll(to)
{
	if ($(".roller").css("left") != to+"px")
	{
		time = Math.round((($(".roller").css("left").replace("px", "")*1)-to));
		if(time<0) time = 1-time;
		$(".roller").animate({left: to}, time, function() {scroll(to);} );
	}
}

function _scrollTo(href)
{
    if (indexes[href]>opened)
    {
        $("#"+scrolls[opened]).animate({top:'-'+rollHeight+'px'}, 300);
        $("#"+href).animate({top:'0px'}, 300);
    }
    else if (indexes[href]<opened)
    {
        $("#"+href).css("top", "-"+rollHeight+"px");
        $("#"+scrolls[opened]).animate({top:'+'+rollHeight+'px'}, 300);
        $("#"+href).animate({top:'0px'}, 300);
    }
    opened = indexes[href];
    return false;
}

/*******************************************************************************
karma()
Manda su una foto
*******************************************************************************/
function karma(id, voto)
{
	$.post('/karma.inc.php', { karma_vote: id, voto: voto}, 
		function(data) {
	        $("#num_"+id).html(data);
			$("#vota_"+id).fadeOut();
		});		
}

function shadowboxHtml(el)
{
	$.post('/photodetail.inc.php', { url: el["content"]}, 
		function(data) {
			if (data != "")
			{
            data = data.split("|||");
				$("#sb-title").append(data[0]);
				$("#sb-player").wrap("<a href=\""+data[1]+"\"></a>");
			}
		});	
}

function cleanShadowboxHtml()
{
	$("#sb-title #add").remove();
}

