// JavaScript Document

var url = document.location.href;
var hash = window.location.hash;
var path;
var hashurl;
var file;

var window_w;
var window_h;

var sound;
var sound_playing;
var sound_flash;

var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

var iPad = navigator.userAgent.match(/iPad/i) != null;
var iPhone = navigator.userAgent.match(/iPhone/i) != null;
var iPod = navigator.userAgent.match(/iPod/i) != null;
var Firefox = navigator.userAgent.match(/Firefox/i) != null;
var IE = navigator.userAgent.match(/Windows/i) != null;
var audioTag = !!document.createElement('audio').canPlayType
var hasTouch = 'ontouchstart' in document.documentElement;

var menu_touch_start = 0;
var menu_touch_end = 0;
var menu_touch_move = 0;

var footer_touch_start = 0;
var footer_touch_end = 0;
var footer_touch_move = 0;

var showcase_who = 0;
var showcase_interval;

var project_url;
var project_str;

var timeline_w = 0;
var timeline_url;
var timeline_str;

var share


// Window 

$(window).ready(function(e)
{
		
	// Path
	path = url.split('/');
	
	// Verify if has a hash	
	if(path[3] != '#' && path[3] != '')
	{
		
		hashurl = '/#/';
		
		for(var i = 3; i <= path.length-2; i++)
		{
			hashurl += path[i]+'/';
		}
	
		window.location.href = hashurl;	
		pageChange(hashurl);
		
		
	}
	else if(path[3] == '#')
	{
		pageChange(hash);
	}
	else
	{
		hashurl = '/#/intro/';	
		window.location.href = hashurl;	
		pageVerify();		
	}
	
	setInterval(pageVerify, 1000);
		
});

var pageVerify = function()
{
	if(window.location.hash != hash)
	{
		hash = window.location.hash
		pageChange(hash);
	}
}

var pageChange = function(section)
{	
	file = section.split('/');
	$.post('/view/'+file[1]+'.php', {from:'ajax', sub:file[2]}, function(data)
	{
		//alert(data);
		
		$('#content').html(data);
		
		switch(file[1])
		{			
			case 'intro':
				intro();
				break;
				
			case 'home':
				home();
				break;
				
			case 'biografia':
				biografia();
				break;
				
			case 'projetos':
				projetos();
				break;
				
			case 'livro':
				livro();
				break;
				
			case 'timeline':
				timeline();
				break;
			
			case 'contato':
				contato();
				break;
		}
		
		if(file[1] != 'intro')
		{
			$('#menu').css({'visibility':'visible'});
			$('#footer').css({'visibility':'visible'});
		}
		
		resize();
				
	});
	

}


// Ready

$(document).ready(function(e)
{	
	resize();
	
	if(hasTouch)
	{
		$('#btn_twitter').bind('touchstart', twitter);
		$('#btn_facebook').bind('touchstart', facebook);
		$('#btn_vimeo').bind('touchstart', vimeo);
		$('#btn_sound').bind('touchstart', sound_toogle);
	}		
	else
	{
		$('#btn_twitter').bind('click', twitter);
		$('#btn_facebook').bind('click', facebook);
		$('#btn_vimeo').bind('click', vimeo);
		$('#btn_sound').bind('click', sound_toogle);
	}
	
	swfobject.embedSWF('/swf/sound.swf', 'sound_flash', '2', '2', '9.0.45.0', '', {}, {allowscriptaccess:'always'});		
		
});

$(window).resize(function(){ resize(); });

//

function getFlashMovie(movieName)
{
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	return (isIE) ? window[movieName] : document[movieName];
}


// Resize

var resize = function()
{
	
	$('#menu').css({'margin-left':($(content).width()/2)-150+'px'});
	$('#footer').css({'margin-left':($(content).width()/2)-50+'px'});	
	$('#footer').css({'top':'0px'});	
	$('#footer').css({'top':($(document).height()-250)+'px'});	
	
	
	$('#project_container').css({'top':($(content).height()/2)-165+'px'});
	
	$('#timeline_container').css({'top':($(content).height()/2)-220+'px'});
	$('#timeline').css({'background-position': '0px '+(($(content).height()/2)+210)+'px'});
	$('#running_small').css({'top':(($(content).height()/2)+175)+'px'});
	
}


// Functions

$(function()
{
	
	// Menu
	
	$('#menu a').bind('click', function(evt)
	{
		window.location = '/#'+$(this).attr('href');		
		return false;
		
	});
	
	if(iPad)
	{
		$('#menu').bind('touchstart', function(evt)
		{
			menu_touch_start = event.touches[0].clientY;		
			
		}).bind('touchmove', function(evt)
		{
			evt.preventDefault();			
			menu_touch_end = event.touches[0].clientY;
			menu_touch_move = 1;		
			
		}).bind('touchend', function()
		{
			if(menu_touch_move)
			{
				if( (menu_touch_start-menu_touch_end) > 0)
					$('#menu').stop(true, false).animate({'margin-top':'-430px'}, 1000, 'easeOutExpo');
				else
					$('#menu').stop(true, false).animate({'margin-top':'0px'}, 1000, 'easeOutExpo');
			}
			else
			{
				if($('#menu').css('margin-top') == '0px')
					$('#menu').stop(true, false).animate({'margin-top':'-430px'}, 1000, 'easeOutExpo');
				else
					$('#menu').stop(true, false).animate({'margin-top':'0px'}, 1000, 'easeOutExpo');
					
			}
			
		});
		
	}
	else
	{
		
		$('#menu').mouseenter(function()
		{
			$('#menu').stop(true, false).animate({'margin-top':'0px'}, 1000, 'easeOutExpo');
		
		}).mouseleave(function()
		{
			$('#menu').stop(true, false).animate({'margin-top':'-440px'}, 1000, 'easeOutExpo')
		});
		
	}
	
	// Fancybox
	
	$('#menu, #footer').bind('touchstart', function(evt){ $.fancybox.close(); });
	$('#menu, #footer').mousedown(function(){ $.fancybox.close(); });
	
	
	
	// Footer	
	
	if(iPad)
	{
		
		$('#footer').bind('touchstart', function(evt)
		{
			footer_touch_start = event.touches[0].clientY;		
			
		}).bind('touchmove', function(evt)
		{
			evt.preventDefault();			
			footer_touch_end = event.touches[0].clientY;
			footer_touch_move = 1;		
			
		}).bind('touchend', function()
		{
			if(footer_touch_move)
			{
				if( (footer_touch_start-footer_touch_end) > 0)
					$('#footer_container').stop(true, false).animate({'margin-top':'0px'}, 1000, 'easeOutExpo');
				else
					$('#footer_container').stop(true, false).animate({'margin-top':'200px'}, 1000, 'easeOutExpo');
					
			}
			else
			{
				
				
				if($('#footer_container').css('margin-top') == '200px')
					$('#footer_container').stop(true, false).animate({'margin-top':'0px'}, 1000, 'easeOutExpo');
				else
					$('#footer_container').stop(true, false).animate({'margin-top':'200px'}, 1000, 'easeOutExpo');
					
			}
			
		});
		
	}
	else
	{
		$('#footer').mouseenter(function()
		{
			$('#footer_container').stop(true, false).animate({'margin-top':'0px'}, 1000, 'easeOutExpo');
		
		}).mouseleave(function()
		{
			$('#footer_container').stop(true, false).animate({'margin-top':'200px'}, 1000, 'easeOutExpo');
		});
	}
	
	
		
	
});


// Intro

var intro = function()
{
	document.title = 'Leo Romano';
	
	
	// Hide menus
	$('#menu').css({'visibility':'hidden'});
	$('#footer').css({'visibility':'hidden'});
	
	// Get window size
	window_w = $(window).width();
	window_h = $(window).height();
	
	
	// Init
	intro_init();
	
	
	// Sound
	if(audioTag)
	{
		sound = document.getElementById('sound');
		sound.load();
		
		if(Firefox)		
			sound.src = '/files/sounds/berrante.ogg';
		else
			sound.src = '/files/sounds/berrante.mp3';
		
	}
	else
	{
		sound_flash = document.getElementById('sound_flash');
	}
	
	$('#lowing, #touchme').bind('click', function()
	{
		if(audioTag)
		{
			sound.addEventListener('playing', function(){ $('#playing').val(1); },false);
			sound.addEventListener('pause', function(){ $('#playing').val(0); },false);
			
			sound.addEventListener('ended', function()
			{
											
				if(Firefox)		
					sound.src = '/files/sounds/'+$('#next').val()+'.ogg';
				else
					sound.src = '/files/sounds/'+$('#next').val()+'.mp3';
				
				sound.play();
				change_sound();
				
			},false);
			
			
			sound.play();
			
		}
		else
		{
			sound_flash.init();
		}
		
		
		lowing();
		sound_playing = 1;
		
		$('#touchme').fadeOut('fast');
		
		setTimeout(intro_end, 12000);
	
	});
		
	
}

var intro_init = function()
{
	
	$('#running').css({'top':((window_h/2)-50)+'px'});	
	$('#running').animate({'left':((window_w/2)-100)+'px'}, 5000, 'linear');
	$('#lowing').css({'top':((window_h/2)-50)+'px', 'left':((window_w/2)-97)+'px'});
	$('#touchme').css({'top':((window_h/2))+'px', 'left':((window_w/2)+50)+'px'});	
	
	running();
	setTimeout(function(){ $('#running').hide(0); $('#lowing').show(0);}, 6000);
	
	setTimeout(function()
	{
		$('#touchme').animate({'top':((window_h/2)-150)+'px', 'width':'150px', 'height':'100px'}, 1000, 'easeOutElastic');
	}, 6000);
	
}

var intro_end = function()
{
	$('#menu').fadeIn('fast');
	$('#footer').fadeIn('fast');
	window.location.href = '/#/home/';
}

var running_times = 151;
var running_timeout = 0;
var running_frame = 0;
var running = function()
{
	
	$('#running').css({'background-position':'0px '+(-(running_frame*150))+'px'});
	
	if(running_frame == 29)
		running_frame = 0;
	else
		running_frame++;
	
	running_timeout = setTimeout(running, 33);
	
	running_times--;
	if(running_times == 0)
		clearTimeout(running_timeout);		
	
}





var lowing_times = 25;
var lowing_timeout = 0;
var lowing_frame = 0;
var lowing = function()
{
	
	$('#lowing, #touchme').unbind('click');
	$('#lowing, #touchme').css({'cursor':'default'});
	
	$('#lowing').css({'background-position':'0px '+(-(lowing_frame*150))+'px'});
	
	lowing_frame++;
	lowing_times--;
	
	lowing_timeout = setTimeout(lowing, 33);
	
	if(lowing_times == 0)
		clearTimeout(lowing_timeout);
		
	
}


var lowingback_times = 25;
var lowingback_timeout = 0;
var lowingback_frame = 24;
var lowingback = function()
{
	
	$('#lowing').css({'background-position':'0px '+(-(lowingback_frame*150))+'px'});
	
	lowingback_frame--;
	lowingback_times--;
	
	lowingback_timeout = setTimeout(lowingback, 33);
	
	if(lowingback_times == 0)
		clearTimeout(lowingback_timeout);
		
}


// Sound
var sound_toogle = function()
{
	
	if(audioTag)
	{
		
		if(!sound)
		{
			
			// Sound
			
			sound = document.getElementById('sound');
			sound.load();
			
			if(Firefox)		
				sound.src = '/files/sounds/1.ogg';
			else
				sound.src = '/files/sounds/1.mp3';
				
			$('#playing').val(1);
			$('#next').val(2);
						
			sound.addEventListener('ended', function()
			{				
				if(Firefox)		
					sound.src = '/files/sounds/'+$('#next').val()+'.ogg';
				else
					sound.src = '/files/sounds/'+$('#next').val()+'.mp3';
				
				sound.play();
				change_sound();
				
			},false);
					
				
			sound.play();
			
			sound_playing = 1;
			
		}
		else
		{
			if(sound_playing)
			{
				sound.pause();
				sound_playing = 0;
			}
			else
			{
				sound.play();
				sound_playing = 1;
			}
				
		}
	
	}
	else
	{
		
		if(!sound_flash)
		{
			sound_flash = document.getElementById('sound_flash');
			sound_flash.init();
			
		}			
		else
		{
			sound_flash.volume();
		}
		
	}
		
	
}

var change_sound = function()
{
	
	switch($('#next').val())
	{
		case '1':
			$('#next').val(2);
			break;
			
		case '2':
			$('#next').val(3);
			break;
			
		case '3':
			$('#next').val(4);
			break;
			
		case '4':
			$('#next').val(1);
			break;
	}
	
}


// Home

var home = function()
{
	
	document.title = 'Leo Romano';
	
	function homeSlide()
	{
		
		$('.home_item').each(function(index, element)
		{
			if(index == showcase_who)
				$(element).stop(true, false).animate({'-webkit-opacity':'1', '-moz-opacity':'1', '-ms-opacity':'1', 'opacity':'1', 'z-index':'1'}, 1500, 'swing');
			else
				$(element).stop(true, false).animate({'-webkit-opacity':'0', '-moz-opacity':'0', '-ms-opacity':'0', 'opacity':'0', 'z-index':'0'}, 1500, 'swing');
			
		});
			
		if(showcase_who == 2)
		{
			showcase_who = 0
		}
		else
		{
			showcase_who++;
		}
		
		
	}
	
	setInterval(homeSlide, 8000);
	homeSlide();
	
	
	$('#home a').bind('click', function(evt)
	{
		window.location = '/#'+$(this).attr('href');		
		return false;
		
	});
	
	
}


// Biografia

var biografia = function()
{
	document.title = 'Biografia - Leo Romano';
}



// Projetos

var projetos = function()
{
	
	// Titles
	
	switch(file[2])
	{
		case 'arquitetura-comercial':
			document.title = 'Arquitetura comercial  - Leo Romano';
			break;
			
		case 'arquitetura-residencial':
			document.title = 'Arquitetura residencial  - Leo Romano';
			break;
			
		case 'interiores-comercial':
			document.title = 'Interiores comercial  - Leo Romano';
			break;
			
		case 'interiores-comercial':
			document.title = 'Interiores residencial  - Leo Romano';
			break;
			
		case 'produtos':
			document.title = 'Produtos  - Leo Romano';
			break;
			
		case 'mostras':
			document.title = 'Mostras  - Leo Romano';
			break;
			
		case 'eventos':
			document.title = 'Eventos  - Leo Romano';
			break;
			
		case 'decorados':
			document.title = 'Decorados  - Leo Romano';
			break;
		
		default:
			document.title = 'Projetos  - Leo Romano';
			break;
			
	}
	
	
	
	
	// Add scroll plugin
	$('#project_container').css({'width':(600*$('.project_item').length)+'px'});
			
	if(iPad)
		$('#project_container').iosscroll();		
	else
		$('#project_container').mousescroll();
		
	
	// Add fancybox	
	function fancyboxTitle(title, currentArray, currentIndex, currentOpts)
	{
		
		var obj = $('.project_item')[currentIndex];
		project_url = $('a', obj).parent().attr('id').replace('project_', '');
		project_str = $('img', obj).attr('title');
		
				
		var code = '';
		code += '<div class="project_item_close"><a href="javascript:;" onclick="$.fancybox.close();"><img src="/img/arrow_close.png" width="50" height="50" /></a></div>';
		code += '<div class="project_item_left"><a href="javascript:;" onclick="$.fancybox.prev();"><img src="/img/arrow_left.png" width="50" height="50" /></a></div>';
		code += '<div class="project_item_right"><a href="javascript:;" onclick="$.fancybox.next();"><img src="/img/arrow_right.png" width="50" height="50" /></a></div>';
		code += '<div class="project_item_twitter"><a href="javascript:;" onclick="twitter();"><img src="/img/arrow_twitter.png" width="50" height="50" /></a></div>';
		code += '<div class="project_item_facebook"><a href="javascript:;" onclick="facebook();"><img src="/img/arrow_facebook.png" width="50" height="50" /></a></div>';
		code += '<div class="project_item_title">' + (title && title.length ? '' + title + '' : '' ) + '<br /><div class="project_item_count">' + (currentIndex + 1) + ' de ' + currentArray.length + '</div></div>';
			
		return code;
		
	}
	
	
	
	function fancyboxComplete(currentArray, currentIndex, currentOpts)
	{
		
		var img_w = $('#fancybox-img').width();
		var img_h = $('#fancybox-img').height();
		
		var current = (currentIndex+1);
		var amount = (currentArray.length);
		
		if(current > 1)
			$('.project_item_left').css({'top':-(img_h/2)+'px', 'left':(-50)+'px'});
		else
			$('.project_item_left').css({'display':'none'});
		
		
		if(current < amount)
			$('.project_item_right').css({'top':-(img_h/2)+'px', 'left':(img_w)+'px'});
		else
			$('.project_item_right').css({'display':'none'});
			
		
		$('.project_item_close').css({'top':-(img_h+50)+'px', 'left':(img_w)+'px'});
		$('.project_item_twitter').css({'top':-(110)+'px', 'left':(img_w)+'px'});
		$('.project_item_facebook').css({'top':-(50)+'px', 'left':(img_w)+'px'});
		
		
		
		if(iPad)
		{
			
			var swipe;
			
			$('#fancybox-img').bind('touchstart', function(evt)
			{
				swipe = evt.originalEvent.changedTouches[0].pageX;
				evt.preventDefault();
				
			}).bind('touchend', function(evt)
			{
				swipe = evt.originalEvent.changedTouches[0].pageX - swipe;
				if(swipe > 0)
					//swipe = 1;
					$.fancybox.prev();
				else if(swipe < 0)
					//swipe = -1;
					$.fancybox.next();
				
			});
			
		
		}
		
			
	}
	
	
	
	$('a[rel=gallery]').fancybox({
		
		'titlePosition'		: 'inside',
		'titleFormat'		: fancyboxTitle,
		'padding'			: 0,
		'margin'			: 100,
		'changeFade'		: 300,
		'overlayShow'		: true,
		'autoScale'     	: true,
		'centerOnScroll'	: true,
		'showNavArrows'		: false,
		'showCloseButton'	: false,
		'hideOnOverlayClick': false,
		'overlayColor'		: '#000',
		'overlayOpacity'	: 0.75,
		'onComplete'		: fancyboxComplete
	});
	
	if(file[3])
		$('a', '#project_'+file[3]).trigger('click');
	
	
	
}


// Livro

var livro = function()
{
	document.title = 'Livro - Leo Romano';
}



// Timeline

var timeline = function()
{
	
	document.title = 'Timeline - Leo Romano';
	
	// Add scroll plugin
	$('#timeline_container').css({'width':(200*$('.timeline_item').length)+'px'});
	
		
	if(iPad)
		$('#timeline_container').iosscroll();		
	else
		$('#timeline_container').mousescroll();
		
		
	// Running	
	running_small();
	
	
		
	// Fancybox
	
	function fancyboxTitle(title, currentArray, currentIndex, currentOpts)
	{	
		
	
		var code = '';
		code += '<div class="project_item_close"><a href="javascript:;" onclick="$.fancybox.close();"><img src="/img/arrow_close.png" width="50" height="50" /></a></div>';
		code += '<div class="project_item_left"><a href="javascript:;" onclick="$.fancybox.prev();"><img src="/img/arrow_left.png" width="50" height="50" /></a></div>';
		code += '<div class="project_item_right"><a href="javascript:;" onclick="$.fancybox.next();"><img src="/img/arrow_right.png" width="50" height="50" /></a></div>';
		code += '<div class="project_item_twitter"><a href="javascript:;" onclick="twitter();"><img src="/img/arrow_twitter.png" width="50" height="50" /></a></div>';
		code += '<div class="project_item_facebook"><a href="javascript:;" onclick="facebook();"><img src="/img/arrow_facebook.png" width="50" height="50" /></a></div>';
		
		return code;
	}
	
	
	
	function fancyboxComplete(currentArray, currentIndex, currentOpts)
	{		
		
		var current = (currentIndex+1);
		var amount = (currentArray.length);
		
		$('.project_item_close').css({'top':-($('#fancybox-wrap').height())+'px', 'left':'275px'});
		$('.project_item_twitter').css({'top':'-130px', 'left':'275px'});
		$('.project_item_facebook').css({'top':'-75px', 'left':'275px'});
		
		if(current > 1)
			$('.project_item_left').css({'top':-($('#fancybox-wrap').height()/2)-50+'px', 'left':'-325px'});
		else
			$('.project_item_left').css({'display':'none'});
		
		
		if(current < amount)
			$('.project_item_right').css({'top':-($('#fancybox-wrap').height()/2)-50+'px', 'left':'275px'});
		else
			$('.project_item_right').css({'display':'none'});
			
		
	}
	
	$('.timeline_item_info').mousedown(function()
	{
		$('a', this).trigger('click');
		timeline_url = $(this).attr('id').replace('timeline_', '');
		timeline_str = $(this).attr('title');
		
		
	});
	
	$('a[rel=timeline]').fancybox(
	{
		'width'				: 550,
		'height'			: 350,
		'titleFormat'		: fancyboxTitle,
		'padding'			: 25,
		'margin'			: 100,
		'changeFade'		: 300,
		'overlayShow'		: true,
		'autoScale'     	: true,
		'centerOnScroll'	: true,
		'showNavArrows'		: false,
		'showCloseButton'	: false,
		'hideOnOverlayClick': true,
		'overlayColor'		: '#000',
		'overlayOpacity'	: 0.75,
		'onComplete'		: fancyboxComplete
		
	});
	
	if(file[2])
		$('#timeline_'+file[2]).trigger('mousedown');
	
}

var running_small_frame = 0;
var running_small_timeout = 0;


var running_small = function()
{
	
	$('.running_small').css({'background-position':'0px '+(-(running_small_frame*32))+'px'});
	
	$('.running_small').css({'left':($('.running_small').position().left+2)+'px'});
	if($('.running_small').position().left >= $('#running_small').width())
		$('.running_small').css({'left':'-32px'});
	
	
	if(running_small_frame == 29)
		running_small_frame = 0;
	else
		running_small_frame++;
	
	running_small_timeout = setTimeout(running_small, 33);

}



// Contato

var contato = function()
{
	
	document.title = 'Contato - Leo Romano';
	
	var markers = new Array();	
	var location = new google.maps.LatLng(-16.697, -49.265);
	var map;
		
	function initMap()
	{
		var mapOptions = {
			zoom: 17,
			scrollwheel: false,
			mapTypeId: google.maps.MapTypeId.ROADMAP,
			center: location
		};
		
	
		map = new google.maps.Map(document.getElementById("contato_map"), mapOptions);
		marker = new google.maps.Marker(
		{
			title: 'LEO ROMANO',
			map: map,
			draggable: false,
			clickable: true,
			animation: google.maps.Animation.DROP,
			position: new google.maps.LatLng(-16.697800, -49.267980),
			icon: '/img/pin.png'
		});
		
		 google.maps.event.addListener(marker, 'click', function(evt)
		 {
			$('#contato_link').trigger('click');	
				 
		 });
		  
		
	}
	
	initMap();
	
		
	
	// Fancybox
	
	function fancyboxTitle(title, currentArray, currentIndex, currentOpts)
	{
		
		var code = '';
		code += '<div id="contato_info_close"><a href="javascript:;" onclick="$.fancybox.close();"><img src="/img/arrow_close.png" width="50" height="50" /></a></div>';
		return code;
		
	}
	
	$('#contato_link').fancybox(
	{
		'titleFormat'		: fancyboxTitle,
		'padding'			: 0,
		'margin'			: 75,
		'changeFade'		: 300,
		'overlayShow'		: false,
		'autoScale'     	: true,
		'centerOnScroll'	: true,
		'showNavArrows'		: false,
		'showCloseButton'	: false,
		'hideOnOverlayClick': true,
		'overlayColor'		: '#000',
		'overlayOpacity'	: 0.0,
		'onComplete'		: function(){ $('#contato_info_close').css({'top':'-555px', 'left':'215px'}); initForm(); },
		'onStart'			: function(){ $('#contato').fadeIn('fast'); }, 
		'onClosed'			: function(){ $('#contato').css({'display':'none'}); } 
	});
	
	
	// Form
	function initForm()
	{
		
		$('#submit').click(function()
		{
			$('form').submit();
					
		});
		
		
		$('form').submit(function()
		{
			
			
			var requireds = $('form').find('.required');
			function verify_requireds()
			{
				
				var arr = [];
				
				requireds.each(function(index)
				{
					result = false;
									
					if($(this).val() == '')
					{
						arr.push(true);
					}
					
				});
				
				if(arr == '')
				{
					return false;
				}
				else
				{
					return true;
				}
			
			}
			
			if(verify_requireds(requireds))
			{
				alert_this('Por gentileza, preencha os campos acima!');
			}
			else
			{
											
			if($('form input[name=email]').length && !reg.test($('form input[name=email]').val()))
			{
				alert_this('O email preenchido não parece válido!');
			}
			else
			{
				$('.alert').hide('fast');
				$('.alert').html('');
				
				$.post(
					'/view/'+$(this).attr('action')+'_.php', 
					$('form').serialize(), 
					function(data)
					{
						//alert(data);
					
						var msg = data.split('#')
						
						if(Number(msg[0]) == 1)
						{
							$('#contato_form').slideUp(500);
							
							setTimeout(function()
							{
								$('#contato_form').html(msg[1]);
							}
							, 750);
							
							$('#contato_form').delay(1000).slideDown(500);
						}
						else
						{
							alert_this(msg[1]);
						}
						
					});
					
			}
			
			}
				
			return false;	
			
		});
		
	}
	
	
	
	
	
}



// Form

var alert_this = function(msg)
{
	$('.alert').html(msg);
	$('.alert').show('fast');
}



// Share

var twitter = function()
{
	
	share = 'http://www.leoromano.com.br/'+file[1]+'/';
	if(file[2])
		share = share+file[2]+'/';
	
	if($(this).attr('id') == 'btn_twitter')
	{
		window.open('http://twitter.com/intent/tweet?source=webclient&text='+document.title+' @romanoleo '+share, 'twitter', 'width=550, height=450');
	}		
	else if(file[1] == 'projetos')
	{
		window.open('http://twitter.com/intent/tweet?source=webclient&text='+project_str+' @romanoleo '+share+project_url+'/', 'twitter', 'width=550, height=450');
	}
	else if(file[1] == 'timeline')
	{
		window.open('http://twitter.com/intent/tweet?source=webclient&text='+timeline_str+' @romanoleo '+share+timeline_url+'/', 'twitter', 'width=550, height=450');
	}
}
	
var facebook = function()
{
	
	share = 'http://www.leoromano.com.br/'+file[1]+'/';
	if(file[2])
		share = share+file[2]+'/';
	
	
	if($(this).attr('id') == 'btn_facebook')
	{
		window.open('http://www.facebook.com/share.php?u='+share, 'facebook', 'width=550, height=450');
	}		
	else if(file[1] == 'projetos')
	{
		window.open('http://www.facebook.com/share.php?u='+share+project_url+'/', 'facebook', 'width=550, height=450');
	}
	else if(file[1] == 'timeline')
	{
		window.open('http://www.facebook.com/share.php?u='+share+timeline_url+'/', 'facebook', 'width=550, height=450');
	}
	
}

var vimeo = function()
{
	window.open('http://vimeo.com/leoromano', 'vimeo');
}


/*

$(document).ready(function() {
    $.ajax({
        url: "soundfile.mp3",
        success: function() {
            $("#play_button").show();
        }
    });
});

*/

