$(function(){ 

 
	$('.contact-form .submit-btn').hover(function(){ 
		$(this).toggleClass('submit-btn-hover');
	 });
	 
	 //Form Validation
	$('.validate-form').submit(function(){
		var form = $(this);
		form.find('.required').parents('.row:eq(0)').removeClass('field-error');
		
		var field, v, id, msg, t, field_holder;
		var alert_msg = $('.msg-alert');
		var error = false;
		form.find('.required').each(function(){
			field = $(this);
			field_holder = field.parents('.row:eq(0)');
			v = $(this).val();
			t = $(this).attr('title');
			id = $(this).attr('id');
			
			if( $(this).hasClass('valid-email') ){
				if( /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(v) == false ) {
					error = true;
				}
			}else {
				if( v == '' || v == t ){
					error = true;
				}
			}
			
			if( error ) {
				field.addClass('field-error');
				field.prev().addClass('label-error');
				alert_msg.fadeIn();
				//error_fields.push( field );
			}
		});
		
		if( !error ) {
		
			form.find('.required').removeClass('field-error');
			form.find('label').removeClass('label-error');
			var data = {}
			

			$('.msg-thanks').html('<p><img src="images/spinner.gif" alt="" /><br>Enviando...</p>');		
			
			$.post('includes/send-mail.php', $("#contact-form").serialize(), function(data){
							form.find('.text-field').each(function(){
				data[ $(this).attr('name') ] = $(this).val();
			});
			
			form.find('.text-field').each(function(){
				$(this).val( $(this).attr('title') );
			});																	  
				alert_msg.fadeOut();
				form.find('.msg-thanks').fadeIn(function(){
					$('#message').val( $('#message-field').attr('title') );
					$('.msg-thanks').html(data);
					window.setTimeout(function(){
						form.find('.msg-thanks').fadeOut();
					}, 7000);
					
				});
			});
		}
		
		return false;
	});
	
	//Contact Form Input Focus 
 	  $('.row .field').focus(function(){ 
 	  	$(this).addClass('field-focus');
 	   }).blur(function(){
 	   	$(this).removeClass('field-focus'); 	  
 	 });	 	


			$("#faded").faded({
				speed: 500,
				crossfade: false,
				autoplay: 9000,
				autopagination:false
			});

				
				$("area[rel^='prettyPhoto']").prettyPhoto();
				
				$("a[rel^='prettyPhoto']").prettyPhoto({
				animationSpeed:'slow',
				theme:'facebook',
				social_tools: false,
				slideshow:false,
				autoplay_slideshow: false,
				show_title: true,
				overlay_gallery: false});			
				
	    
});

    $('.playm').each(function(index) {
        var i  = $(this).attr('id').replace('playerd_', '');
        var cancion = $("#download_" + i).val();                           
        $(this).jPlayer({
            ready: function () {
                $(this).jPlayer("setMedia", {
                    mp3: "media/downloads/" + cancion
                }).jPlayer("stop");
            },
            swfPath: "js",
            supplied: "mp3",
            cssSelectorAncestor: "#playm_interface_" + i
        }).bind($.jPlayer.event.play, function() { 
            $(this).jPlayer("pauseOthers");
        });
    });
	
	
	
jQuery(function() {
	jQuery('.project_images li img').hide();
});

jQuery(window).bind('load', function() {
	 var i = 1;
	 var imgs = jQuery('.project_images li img').length;
	 var int = setInterval(function() {
		 //console.log(i); check to make sure interval properly stops
		 if(i >= imgs) clearInterval(int);
		 jQuery('.project_images li img:hidden').eq(0).fadeIn(300);
		 i++;
	 }, 300);
});

