$().ready(function(){
	// Slider Menu Hover Effect:
    $('#slider-menu li a').not($('.selected')).hover(
	    function()
	    {
			$(this).stop().animate({ paddingLeft: '45px' }, 200);
		}, 
		function()
		{
			$(this).stop().animate({ paddingLeft: '20px' });
	    }
    );
	
	/* TABS */
    if($('ul.tabs').length > 0)
    {
		$('ul.tabs').tabs('div.panes > div', { history: true });
    }
	
	/* ACCORDION */
	$('.pane .panesContent').hide();
	$('.pane').find('.panesContent:first').addClass('show').show();
	
	$('.pane h3').click(function(){
		if($(this).next('.panesContent').hasClass('show'))
		{
			return false;
		}
		
		var context = $(this).parent();
		
		$('.show', context).removeClass('show').slideUp();
		$(this).next('.panesContent').slideDown().addClass('show');
	});
	
	/* DOCUMENTATION */
	$('#document .documents').hide();
	$('#document').find('.documents:first').show().addClass('show');
	
	$('.documentation li a').each(function(i){
		$(this).click(function(e){
			e.preventDefault();			
			$('.show', '#document').hide().removeClass('show');
			$('#document .documents').eq(i).show().addClass('show');
		});
	});
	
	/* FAQ */
	$('.answers').hide();
	
	$('.questions').click(function(){
		if($(this).parent().hasClass('open'))
		{
			console.log('ok');
			return false;
		}
		
		$('.open .answers').slideUp();
		$('.open').removeClass('open');
		
		$(this).parent().toggleClass('open');
		$('.answers', $(this).parent()).slideDown();
	});

	// Allow to use text shadow even in IE
	$('#slider h2, #slider-menu a, #news h3, .button').textShadow({x: 1, y: 2, radius: 3, color: '#555555'});
	
	// Contact form errors
	$('ul.errors').each(function(i){
		$(this).hide();
		$(this).next('p').children('input, textarea').css({border: '1px solid #EA9E9E', backgroundColor: '#FFEAEA'});
	});
	
	/* CONTACT FORM */
	if($('#contactForm').length > 0)
	{
		var height = $('#type').parent('p').height();
		var padding = height + 5;
		
		console.log($('#type').height());
		
		if($('#type').val() == 'independant')
		{
			$('#company').parent('p').hide();
			$('#rightForm').css({paddingTop : padding  + 'px'});
		}
		else
		{
			$('#rightForm').css({paddingTop : '5px'});
		}
		
		$('#type').change(function(){
			$('#company').parent('p').toggle();

			padding = $(this).val() == 'independant' ? height + 5 : 5;		
			$('#rightForm').css({paddingTop : padding + 'px'});
		});
	}
	
	/* CHEAT CODE xD */
	if($('.news').length > 0 || $('.partners').length > 0)
	{
		$('#menu-11').parent('li').addClass('active');
	}
	
	/* VIDEO */
	if($('#video').length > 0)
	{
		$("#video a[rel]").overlay({
		    mask:
		    {
		    	color: '#000',
		    	loadSpeed: 200,
		    	opacity: 0.5
		    },
		    closeOnClick: false
		});
	}
	
});

/* SLIDERS */
$(window).load(function() {
	if($('#slide').length > 0)
	{
		$('#slide').nivoSlider({
			effect: 'fade',
			slices: 1,
			pauseTime: 3000,
			directionNav: false,
			directionNavHide: false, //Only show on hover
			controlNav: false,
			controlNavThumbs: false,
			controlNavThumbsFromRel: false,
			pauseOnHover: true
		});
	}
		
	if($('#gallery').length > 0)
	{
		$('#gallery').nivoSlider({
			effect: 'fade',
			slices:1,
			pauseTime: 5000,
			directionNav: true,
			directionNavHide: true, //Only show on hover
			controlNav: false,
			controlNavThumbs: false,
			controlNavThumbsFromRel: false,
			pauseOnHover: true
		});
	}
	
	if ($('#workslider').length > 0)
	{
		$('#workslider').nivoSlider({
			effect: 'fade',
			slices:1,
			pauseTime: 3000,
			directionNav: false,
			directionNavHide: false, //Only show on hover
			controlNav: false,
			controlNavThumbs: false,
			controlNavThumbsFromRel: false,
			pauseOnHover: true
		});
	}
	
	if ($('#bannerSlider').length > 0)
	{
		$('#bannerSlider').nivoSlider({
			effect: 'fade',
			slices:1,
			pauseTime: 3000,
			directionNav: false,
			directionNavHide: false, //Only show on hover
			controlNav: false,
			controlNavThumbs: false,
			controlNavThumbsFromRel: false,
			pauseOnHover: true
		});
	}
});
