/*** 
    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 :)
***/

TIME_WATCHING = 5000;

function slideSwitch(){

	clearInterval(interval_id);

	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}, 10, function() {
			$active.removeClass('active last-active');
			interval_id = setInterval( "slideSwitch()", TIME_WATCHING );
		});
}

$(function() {
    interval_id = setInterval( "slideSwitch()", TIME_WATCHING );
    
   var userAgent = navigator.userAgent.toLowerCase();

	var isiPhone = (userAgent.indexOf('iphone') != -1 || userAgent.indexOf('ipod') != -1 || userAgent.indexOf('ipad') != -1) ? true : false;
	clickEvent = isiPhone ? 'tap' : 'click';

	if(isiPhone){
    $('#menu_sup li').bind('mousedown', function() {
    e.preventDefault();
    $('#menu_sup li').addClass('tabached');
    //alert('Yay! You just ' + clickEvent + 'ed me!');
	});
	}

});


function envia_dades(){

	nom=document.getElementById("nom").value;
	email=document.getElementById("email").value;
	asunto=document.getElementById("asunto").value;
	msg=document.getElementById("msg").value;
	var filter=/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;

	if((nom == "")||( email == "")||(!filter.test(email))||(msg == "")||( asunto == "")){

		if(nom ==""){
			$("#no_nom").fadeIn("slow");
		}else{
			$("#no_nom").fadeOut("slow");
		}

		if(email==""){
			$("#no_email").fadeIn("slow");
		}else{
			$("#no_email").fadeOut("slow");
			if(!filter.test(email)){
				$("#wrong_mail").fadeIn("slow");
			}else{
				$("#wrong_mail").fadeOut("slow");
			}
		}

		if(asunto ==""){
			$("#no_asunto").fadeIn("slow");
		}else{
			$("#no_asunto").fadeOut("slow");
		}

		if(msg==""){
			$("#no_msg").fadeIn("slow");
		}else{
			$("#no_msg").fadeOut("slow");
		}

	}else{
		document.forms.subscripcio.submit();
	}
}




function envia_dades_news(){

	nom=document.getElementById("nom").value;
	email=document.getElementById("email").value;
	acepto = document.getElementById("acepto").checked;
	var filter=/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;

	if((nom=="")||(email=="")||(!filter.test(email))|| (!acepto)){
		if(nom ==""){
			$("#no_nom").fadeIn("slow");
		}else{
			$("#no_nom").fadeOut("slow");
		}

		if(email==""){
			$("#no_email").fadeIn("slow");
		}else{
			$("#no_email").fadeOut("slow");
			if(!filter.test(email)){
				$("#wrong_mail").fadeIn("slow");
			}else{
				$("#wrong_mail").fadeOut("slow");
			}
		}

		if(!acepto){
			$('#no_acepto').fadeIn("slow");
		}else{
			$('#no_acepto').fadeOut("slow");
		}

	}else{
		document.forms.newsletter.submit();
	}
}
