/* ||||||||||||||||||||||||||||||||||||||||||||||||| SLIDESHOW ||||||||||||||||||||||||||||||||||||||||||||||||| */

function nextSlide() {
	var $active = $('#slideshow IMG.active');

	if ( $active.length == 0 ) $active = $('#slideshow IMG:last');
	var $next =  $active.next().length ? $active.next()
	: $('#slideshow IMG:first');

	$active.addClass('last-active');
	$next.css({opacity: 0.0}).addClass('active').animate({opacity: 1.0}, 400, "swing", function() { $active.removeClass('active last-active'); });
}
	
function slideshow() {
	var revolvingSlides = setInterval( "nextSlide()", 5000 ); 
}
	
	
/* ||||||||||||||||||||||||||||||||||||||||||||||||| HOMEPAGE SLIDESHOW ||||||||||||||||||||||||||||||||||||||||||||||||| */

function homepageNextSlide() {
	var $active = $('#homepageSlideshow IMG.active');

	if ( $active.length == 0 ) $active = $('#homepageSlideshow IMG:last');
	var $next =  $active.next().length ? $active.next()
	: $('#homepageSlideshow IMG:first');

	$active.addClass('last-active');
	$next.css({opacity: 0.0}).addClass('active').animate({opacity: 1.0}, 400, "swing", function() { $active.removeClass('active last-active'); });
}
	
function homepageSlideshow() {
	var revolvingSlides = setInterval( "homepageNextSlide()", 5000 ); 
}
	


/* ||||||||||||||||||||||||||||||||||||||||||||||||| ONLOAD ||||||||||||||||||||||||||||||||||||||||||||||||| */

(function($) {
	$(function() {
		if (document.getElementById("slideshow")) { slideshow(); }
		if (document.getElementById("homepageSlideshow")) { homepageSlideshow(); }
		
		var isOpen = false;
		$('#contact-tab').click(function() {
			$form = $(this).parent();
			if ($('body.new').length > 0) {
				padding = parseInt( $form.css('padding-top') ) + parseInt( $form.css('padding-bottom') );
				if (isOpen) {
					$form.removeClass('open').animate({ 'top' : '-' + ($form.height() + padding - 75) + 'px' }, 1000);
					isOpen = false;
				} else {
					$form.addClass('open').animate({ 'top' : '75px' }, 1000);
					isOpen = true;
				}
			} else {
				padding = parseInt( $form.css('padding-left') ) + parseInt( $form.css('padding-right') );
				if (isOpen) {
					$form.removeClass('open').animate({ 'left' : '-' + ($form.width() + padding) + 'px' }, 1000);
					isOpen = false;
				} else {
					$form.addClass('open').animate({ 'left' : 0 }, 1000);
					isOpen = true;
				}
			}
			return false;
		});
		/* some sort of Ajax issue with some plugins. Open if message */
		if ( $('.wpcf7-mail-sent-ok, .wpcf7-validation-errors').length > 0 ) {
			$('#side-contact').addClass('open').animate({ 'left' : 0 }, 1000);
			isOpen = true;
		}
		
	});
})(jQuery);
