/**
 * @author daniel
 */
$(document).ready(function(){
	
	$('.toplink').mouseover(function(){
		orgColor = $(this).css('backgroundColor');
		$(this).css({
			'backgroundColor':'#' + $(this).attr('id').split('-')[1]
		});
	});
	$('.toplink').mouseout(function(){
		$(this).css({
			'backgroundColor':orgColor
		});
	});
	
	if($('#slideshow').exists())
	{
		var t = setInterval(function(){
			var next = 1;
			var current = $('#slideshow .holder .active').attr('id').split('-')[1];
			if(current == 4)
			{
				next = 1;
			}
			else
			{
				next = parseInt(current) + 1;
			}
			$('#slideshow .controls .active').removeClass('active');
			$('#slideshowcontrol-' + next).addClass('active');
			changeImg('#slideshowimg-' + next);
		}, 5000);
		
		$('#slideshow .controls > a').click(function(){
			var id = '#slideshowimg-' + $(this).attr('id').split('-')[1];
			$('#slideshow .controls .active').removeClass('active');
			$(this).addClass('active');
			clearInterval(t);
			changeImg(id);
			return false;
		});
	}
	
	if($('.faq-headline').exists())
	{
		$('.faq-headline').click(function(){
			var id = '#faqbox-' + $(this).attr('id').split('-')[1];
			$(id).toggle();
			return false;
		});
	}
	
	//$('.zoom').fancybox();
	
});

$.fn.exists = function()
{
	return $(this).length !== 0;
}

function changeImg(id)
{
	if(!$(id).hasClass('active'))
	{
		$(id).css({
			'left':580
		});
		$(id).removeClass('hidden');
		$('#slideshow .holder .active').filter('.active').animate({
			'left':-580
		}, 500, function(){
			$(this).removeClass('active');
			$(this).addClass('hidden');
		});
		$(id).animate({
			'left':0
		}, 500, function(){
			$(this).addClass('active');
		});
		
	}
}


