/*************************************************/
/**												**/
/**		Development: Hudson Marinho				**/
/**		Phone: +55 (84) 8821 5277				**/
/**		URL: http://hudsonmarinho.co.cc/		**/
/**		-----------------------------------		**/
/**		Agency: Balaio Ideias					**/
/**		URL: http://balaioideias.com.br/		**/
/**		-----------------------------------		**/
/**		Year/month:		2011/Augu				**/
/**												**/
/*************************************************/


/* all functions
.....................................*/

$(function(){
	
	$('ul#slide').cycle({ 
		fx:     'fade', 
		speed:  'slow', 
		timeout: 5000
	});
	
	
	$('div#box-patronage ul').cycle({ 
		fx:     'fade', 
		speed:  'slow', 
		timeout: 2500
	});
	
	
	$('div#box-execution ul').cycle({ 
		fx:     'fade', 
		speed:  'slow', 
		timeout: 4000
	});
	
	
	$('div#top > ul li a, .title-box, .sub-title').each(function(){
		$(this).append('<span></span>');
	});
	
	$('div#top > ul li a').hover(function(){
		//$('span', this).show();
		var w = $(this).parent().attr('id');
		var time = 200;
		
		if(w == 'menu-inicio'){					$('span', this).stop().animate({'width' : '22px'}, time); }
		else if(w == 'menu-evento'){			$('span', this).stop().animate({'width' : '26px'}, time); }
		else if(w == 'menu-programacao'){		$('span', this).stop().animate({'width' : '52px'}, time); }
		else if(w == 'menu-palestrantes'){		$('span', this).stop().animate({'width' : '49px'}, time); }
		else if(w == 'menu-inscricao'){			$('span', this).stop().animate({'width' : '36px'}, time); }
		else if(w == 'menu-contato'){			$('span', this).stop().animate({'width' : '29px'}, time); }
		
	},function(){
		$('span', this).stop().animate({'width' : '0px'});
	});
	
	fadeIcon('div#box-social-networks ul li', 200, '.3');
	fadeIcon('div.box-date ul li', 200, '.3');
	fadeIcon('div#top > div ul li', 200, '.5');
	fadeIcon('div.post-info ul li', 200, '.3');
	
	$('div.box-date h4').each(function(){
		//alert($(this).width());
		
		//$(this).parent().find('ul').css({'margin-top' : (($(this).width() + 15 * 2) + 25) + 'px'});
		
	});
	
	$('ul.accordion li div').hide();
	$('ul.accordion li h4 a').click(function(){
		$(this).parent().parent().find('div:visible').animate({'height' : 'hide'}, 'fast', function(){
			$(this).parent().find('h4 a').css({'background-position' : 'right top'});
		});
		
		$(this).parent().parent().find('div:hidden').animate({'height' : 'show'}, 'slow', function(){
			$(this).parent().find('h4 a').css({'background-position' : 'right bottom'});
		});
	});
	
	//$('ul#inscricao li div').hide();
	$('ul#inscricao li h4 a').click(function(){
		$(this).parent().parent().find('div:visible').animate({'height' : 'hide'}, 'fast', function(){
			$(this).parent().find('h4 a').css({'background-position' : 'right top'});
		});
		
		$(this).parent().parent().find('div:hidden').animate({'height' : 'show'}, 'slow', function(){
			$(this).parent().find('h4 a').css({'background-position' : 'right bottom'});
		});
	});
	
	/*
	$('ul.accordion li h4 a').click(function(){
		var div = $(this).parent().parent().find('div')
		
		$('ul.accordion li div').hide();
		
		div.show();
		
		//div.toggle();
		
		$('ul.accordion li').removeClass('accordion-on');
		$(this).parent().parent().addClass('accordion-on');
	});
	
	$('ul#inscricao li h4 a').click(function(){
		var div = $(this).parent().parent().find('div')
		
		$('ul#inscricao li div').hide();
		
		div.show();
		
		//div.toggle();
		
		$('ul#inscricao li').removeClass('accordion-on');
		$(this).parent().parent().addClass('accordion-on');
	});
	*/
	
	$('ul#inscricao li div ul').each(function(){
		$('li:first', this).addClass('border-top-none');
		$('li:last', this).addClass('border-bottom-none');
	});
	
	$('.hr').each(function(){
		$(this).append('<hr />');
	});
	
	
	$('.box-ms-online').click(function(){
		window.open($(this).attr('href'), 'msn', 'width=600,height=300,scrollbars=0,status=0,location=0,toolbar=0,menubar=0');
		
		return false;
	});
	
	
	
	
	
	
	$('.action-contato').submit(function(){
		var self	= $(this);
		var error	= 0;
		
		$('input,textarea', self).each(function(){
			var input = $(this);
			var txt = input.val();
			
			//alert(input.parent().find('label').text());
			
			
			if (input.val() == '' || input.val() == input.parent().find('label').text()){
				alert(input.parent().find('label').text());
				
				input.focus();
				
				error = 1;
				
				return false;
			}
			else if ((input.attr('alt') == 'email') && ((txt.indexOf("@") < 1) || (txt.indexOf('.') < 7)))
			{
				alert('Email incorreto');
				
				input.focus();
				input.val('');
				
				error = 1;
				
				return false;
			}
			
		});
		
		if(error == 0)
		{
			$.ajax({
				type: "POST",
				url: $(this).attr('action'),
				data: $(this).serialize(),
				success: function(msg)
				{
					alert(msg);
				}
			});
			
			$('input,textarea', this).each(function(){
				$(this).val('');
			});
			
			return false;
		}
		
		return false;
	});
	
	$('div.comentarios ul li:last').addClass('padding-bottom-none margin-bottom-none border-bottom-none');
	
	$(".play").click(function() {
		$.fancybox({
			'padding'       : 0,
			'autoScale'     : false,
			'transitionIn'  : 'none',
			'transitionOut' : 'none',
			'overlayColor'	: '#000',
			'title'         : this.title,
			'width'         : 640,
			'height'        : 385,
			'href'          : this.href.replace(new RegExp("watch\\?v=", "i"), 'v/')+'&autoplay=1',
			'type'          : 'swf',
			'swf'           : {
				'wmode'             : 'transparent',
				'allowfullscreen'   : 'true'
			}
		});
		
		return false;
	});
	
	$(".fancybox").fancybox({
		'padding'       : 0,
		'overlayColor'	: '#000'
	});
	
	
	/*function submitAlert(form){
	var self = $(form);
    var error = 0;

	$('input,textarea', self).each(function(){
		var input = $(this);
		var txt = input.val();
        if (input.val() == '' || input.val() == input.attr('title')){
			alert(input.attr('title'));
			input.focus();
			erro = 1;
			return false;
         }else if ((input.attr('alt') == 'email') && ((txt.indexOf("@") < 1) || (txt.indexOf('.') < 7))){
			alert('Email incorreto');
			input.focus();
			input.val('');
			erro = 1;
			return false;
		 }
     });
	
	if (erro == 1){
		erro = 0;
		return false;
    }else{
		$.ajax({
		type: "POST",
		url: $(form).attr('action'),
		data: $(form).serialize(),
		success: function(msg){
			//alert( msg );
			$(form)[0].reset();
			$('input,textarea', self).each(function(){
				var input = $(this);
				input.focus();
			});
			$('#pag').submit();
		}
		});
		return false;
	}
	
	return false;
}
	*/
	
	$('a#balaioideias').hover(function(){
		$(this).stop().animate({'width' : '50px'}, 200);
	},function(){
		$(this).stop().animate({'width' : '15px'});
	});
	
});

