$j(function() {
	if ($j.fn.slider)
	{
		$j.fn.slider.defaults.autoSlideStopOnHover = false;
	}
	
	$j('#hide-title').click(function() {
		$j(this).hide();
		$j('#show-title').show();
//		$j('.mod_slider_sidebar, .title-container').fadeOut("slow");
		$j('.mod_slider_sidebar, .title-container').hide();
	});
	
	$j('#show-title').click(function() {
		$j(this).hide();
		$j('#hide-title').show();
//		$j('.mod_slider_sidebar, .title-container').fadeIn("slow");
		$j('.mod_slider_sidebar, .title-container').show();
	});
	
	$j('.mod_slider_arrow_play').click(function() {
		$j(this).hide();
		$j('.mod_slider_arrow_pause').show();
		$j('.mod-slider').getSlider().setTimeout();
	});
	
	$j('.mod_slider_arrow_pause').click(function() {
		$j(this).hide();
		$j('.mod_slider_arrow_play').show();
		$j('.mod-slider').getSlider().clearTimeout();
	});
});

$j(function()
{
	$j(window).load(function()
	{
		$j('#loader').remove();
		$j('#slider-container .page-element-box, #text-container, .mod_slider_sidebar, #portfolio-container .module').css('visibility', 'visible');
	});
	
	var sliderWithText = $j('.slider-with-text');
	
	if (sliderWithText.length)
	{
		$j('#text-container').remove();
	}
	
	var container = $j('#portfolio-container');
	
	if (!container.length)
	{
		return;
	}
	
	var list = container.find('ul');
	
	var activeItem = $j('#portfolio-container .mod_links .active'),
		itemsToSlide = 5,
		listItems = list.find('li'),
		listItemWidth = listItems.outerWidth(),
		fullWidthNegative = (list.setFullWidth().width() * -1) + container.width() - 1,
		left = toInteger(list.css('left')) + (activeItem.get(0).offsetLeft * -1) + (listItemWidth * 2);
	
	if (listItems.length <= 5)
	{
		container.find('#portfolio-carousel-left, #portfolio-carousel-right').hide();
		
		return;
	}
	
	if (left < fullWidthNegative)
	{
		left = fullWidthNegative;
	}
	else if (left > 0)
	{
		left = 0;
	}
	
	list.css('left', left);
	
	var toLeft = function()
	{
		if (left === 0)
		{
			return;
		}
		
		left += (listItemWidth * itemsToSlide);
		
		if (left > 0)
		{
			left = 0;
		}
		
		list.animate({'left': left + 'px'});
	};
	
	container.find('#portfolio-carousel-left').click(toLeft);

	var toRight = function()
	{
		left -= (listItemWidth * itemsToSlide);
		
		if (left === fullWidthNegative)
		{
			return;
		}
		
		if (left < fullWidthNegative)
		{
			left = fullWidthNegative;
		}
		
		list.animate({'left': left + 'px'});
	};
	
	container.find('#portfolio-carousel-right').click(toRight);
});

