function photogallery_translate_left(photogallery_div_id, itemWidth, containerWidth)
{
	//'#news_scrollable_container'
	var act_margin = jQuery(photogallery_div_id).css('marginLeft');
	act_margin = parseInt(act_margin.substring(0,act_margin.length-2));
	if(act_margin != 0)
	{
		jQuery(photogallery_div_id).animate({marginLeft: "+="+itemWidth+"px"}, 800);
	} else
	{
		jQuery(photogallery_div_id).animate({marginLeft: "+=60px"}, 200);
		jQuery(photogallery_div_id).animate({marginLeft: "-=60px"}, 200);
	}
}

function photogallery_translate_right(photogallery_div_id, itemWidth, containerWidth, scrollableWidth, tot_items)
{
	var act_margin = jQuery(photogallery_div_id).css('marginLeft');
	act_margin = parseInt(act_margin.substring(0,act_margin.length-2));
	if(tot_items > 3 && act_margin + scrollableWidth != containerWidth)
	{
		jQuery(photogallery_div_id).animate({marginLeft: "-="+itemWidth+"px"}, 800);
	} else
	{
		jQuery(photogallery_div_id).animate({marginLeft: "-=60px"}, 200);
		jQuery(photogallery_div_id).animate({marginLeft: "+=60px"}, 200);
	}
}

/*
 * Tiny Carousel 1.73
 *
 * Copyright (c) 2010 Maarten Baijs
 *
 * Date: 20 / 05 / 2010
 * Library: jQuery
 *
 */
(function($){
    $.fn.homecarousel = function(options){
        var defaults = { 
            animation: true, // false is instant, true is animate.
            duration: 1000 // how fast must the animation move in ms?
        };
        var options = $.extend(defaults, options);  

        var oSlider = $(this);
        var oViewport = $('.viewport', oSlider);
        var oContent = $('.home_news_container', oSlider);
        var oPages = oContent.children('.rss_item');
        var oBtnNext = $('.next', oSlider);
        var oBtnPrev = $('.prev', oSlider);
        var iPageSize, iCurrent, iLeftover;

        return this.each(function(){
            initialize();
        });
        function initialize(){
            iPageSize = $(oPages[0]).outerWidth(true);
            iLeftover = Math.ceil((oViewport.outerWidth() / iPageSize) -1);
            iCurrent = -1;
            oContent.css('width', (iPageSize * oPages.length));
            setEvents();
            move(1);
        }
        function setButtons(){
            oBtnPrev.toggleClass('disable', !(iCurrent > 0));
            oBtnNext.toggleClass('disable', !(iCurrent+iLeftover+1 < oPages.length));
        }
        function setEvents(){
            if(oBtnPrev.length > 0 && oBtnNext.length > 0) {
                oBtnPrev.click(function(){move(-1); return false;});
                oBtnNext.click(function(){move( 1); return false;});
            }
        }
        function move(iDirection) {
            if(iCurrent > 0 || iCurrent +1 < oPages.length){
                iCurrent += iDirection;
                var oPosition = {};
                oPosition['left'] = -(iCurrent * iPageSize);
                oContent.animate(oPosition,{
                    queue: false,
                    duration: options.animation ? options.duration : 0
                });
                setButtons();
            }
        }
    };
})(jQuery);


