/*** 
	Download link form validation and submit
	http://net.tutsplus.com/tutorials/javascript-ajax/submit-a-form-without-page-refresh-using-jquery/
***/
$(function() {
    $('#contact_form').hide();
	var xw_form = $.cookie('xw_form');
	if (xw_form != 'complete') {
		$('#contact_form').fadeIn(1500);
	};
	$(function() {
		$(".close").click(function() {
			$('#contact_form').fadeOut(1500);  
			return false;
		});
		$(".button").click(function() {
			
			// VALIDATION
			$('.error').hide();
			var name = $("input#name").val();
			if (name == "") {
				$("label#name_label").addClass('required');
				$("input#name").addClass('required');
				$("input#name").focus();
				return false;
			}
			var company = $("input#company").val();
			if (company == "") {
				$("label#company_label").addClass('required');
				$("input#company").addClass('required');
				$("input#company").focus();
				return false;
			}
			var email = $("input#email").val();
			if (email == "") {
				$("label#email_label").addClass('required');
				$("input#email").addClass('required');
				$("input#email").focus();
				return false;
			}
			var phone = $("input#phone").val();
			
			// PROCESSING
			var dataString = 'name='+ name + '&company='+ company + '&email=' + email + '&phone=' + phone;  
			//alert (dataString);return false;  
			$.ajax({  
				type: "POST",  
				url: "/bin/process.php",  
				data: dataString,  
				success: function() {  
					$('#contact_form').fadeOut(1500);
					$.cookie('xw_form', 'complete', { expires: 15 }); // set cookie and expiration in days
				}  
			});  
			return false;
		});
	});
});


/*** 
    Simple jQuery Slideshow Script
    Released by Jon Raasch (jonraasch.com) under FreeBSD license: free to use or modify, not responsible for anything, etc.  Please link out to me if you like it :)
***/

function slideSwitch() {
    var $active = $('#slideshow img.active');

    if ( $active.length == 0 ) $active = $('#slideshow img:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow img:first');

    // uncomment the 3 lines below to pull the images in random order
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval( "slideSwitch()", 6000 );
});