/*************************************************/
/**												**/
/**		Development: Hudson Marinho				**/
/**		Phone: +55 (84) 8821 5277				**/
/**		URL: http://hudsonmarinho.co.cc/		**/
/**		-----------------------------------		**/
/**		Agency: Balaio Ideias					**/
/**		URL: http://balaioideias.com.br/		**/
/**		-----------------------------------		**/
/**		Year/month:		2011/Octo				**/
/**												**/
/*************************************************/


/* all functions
.....................................*/


$(function(){
	
	// title
	/*
	var title = $('title').text();
	$('title').text($('#main > h2').text() + ' - ' + title);
	*/
	
	// main
	$('#main > p:last').addClass('margin-bottom-none');
	
	
	// produtos
	$('ul#produtos-list > li').each(function(e){
		$('h3', this).prepend('<span class="produtos-icon"></span>').append('<span class="clear"></span>');
		
		if(e%2){				$(this).addClass('float-right padding-left-30 border-right-none');	}
		else{					$(this).addClass('float-left padding-right-30');					}
		
		if(e == 2 || e == 3){	$(this).addClass('border-bottom-none padding-top-30');	}
		else{					$(this).addClass('padding-bottom-30');					}
	});
	
	$('ul#produtos-list').each(function(){
		var $list1 = $('#linha-infantil .galery-produtos');
		var $list2 = $('#linha-acessibilidade .galery-produtos');
		var $list3 = $('#linha-veterinaria .galery-produtos');
		var $list4 = $('#linha-clinica .galery-produtos');
		
		var div1 = $list1.height();
		var div2 = $list2.height();
		var div3 = $list3.height();
		var div4 = $list4.height();
		
		if(div1 >= div2)
		{
			$list1.css({		height : div1	});
			$list2.css({		height : div1	});
		}
		else
		{
			$list1.css({		height : div2	});
			$list2.css({		height : div2	});
		}
		
		
		if(div3 >= div4)
		{
			$list3.css({		height : div3	});
			$list4.css({		height : div3	});
		}
		else
		{
			$list3.css({		height : div4	});
			$list4.css({		height : div4	});
		}
		
	});
	
	$('.gallery').each(function(){
		$('br', this).remove();
		
		$('dl.gallery-item', this).each(function(e){
			if(e%5)
			{
				$(this).addClass('margin-left-10');
			}
		});
	});
	
	$('.galery-produtos').each(function(){
		$('a', this).each(function(e){
			if(e%5)
			{
				$(this).addClass('margin-left-10');
			}
		});
	});
	
	
	// serviços
	var servicos		= $('#servicos-btn > a');
	var servicos_load	= $('#load-servicos');
	
	servicos_load.hide();
	
	servicos.click(function(){
		var href = $(this).attr('href');
		
		servicos_load.hide();
		servicos_load.load(href, function(a, c, d){
			if(c == 'success')
			{
				servicos_load.show();
			}
		});
		
		$('div#servicos-btn a').css({
			  '-moz-opacity' : '0.5',
			'-khtml-opacity' : '0.5',
		   '-webkit-opacity' : '0.5',
		        '-o-opacity' : '0.5',
				   'opacity' : '0.5'
		});
		
		$(this).css({
			  '-moz-opacity' : '1',
			'-khtml-opacity' : '1',
		   '-webkit-opacity' : '1',
		        '-o-opacity' : '1',
				   'opacity' : '1'
		});
		
		return false;
	});
	
	
	// vídeos
	$('.player').each(function(){
		var id = $('div.player-video > object > param[name="movie"]', this).val().replace('http://www.youtube.com/v/', '').split("?");
		var w = '640';
		var h = '400';
		
		$(this).prepend('<a href="javascript:;">Play</a>');
		
		$('.img-video', this).attr('src' , 'http://i4.ytimg.com/vi/' + id[0] + '/0.jpg');
		
		$('.player-video > object', this).attr('width' , w);
		$('.player-video > object', this).attr('height' , h);
		
		$('.player-video > object > embed', this).attr('width' , w);
		$('.player-video > object > embed', this).attr('height' , h);
	});
	
	$('#box-videos .player > a').click(function(){
		var shadow = '0px 0px 15px 2px #999';
		var video = $(this).parent().find('div.player-video > object > param[name="movie"]', this).val();
		
		$(this).parent().find('div.player-video > object > param[name="movie"]').attr('value' , video + '&amp;autoplay=1');
		$(this).parent().find('div.player-video > object > embed').attr('src' , video + '&amp;autoplay=1');
		
		$(this).parent().find('.player-img').hide();
		$(this).parent().find('.player-video').show();
		
		$(this).hide();
		
		$(this).parent().css({
			'-webkit-box-shadow' : shadow,
			   '-moz-box-shadow' : shadow,
			     '-o-box-shadow' : shadow,
			        'box-shadow' : shadow
		});
	});
	
	$('section#sp-videos > a').click(function(){
		var $id = $(this).parent().find('.player-img > img').attr('src').replace('http://i4.ytimg.com/vi/' , '').replace('/0.jpg' , '');
		
		$.fancybox({
			'autoScale'		: false,
			'transitionIn'	: 'elastic',
			'transitionOut'	: 'elastic',
			'easingIn'      : 'easeOutBack',
			'easingOut'     : 'easeInBack',
			'overlayColor'	: '#000',
			'padding'		: '0',
			'width'			: 640,
			'height'		: 400,
			'href'			: 'http://www.youtube.com/v/' + $id + '?version=3&hl=pt_BR&rel=0',
			'type'			: 'swf',
			'swf'			: {
			   	 'wmode'		: 'transparent',
				'allowfullscreen'	: 'true'
			}
		});
		
		return false;
	});
	
	
	
	//noticias
	$('#blog-list li article').each(function(){
		$('img', this).removeAttr('width'),
		$('img', this).removeAttr('height'),
		$('img', this).css({
			'max-width' : '640px'
		});
	});
	
	
	// contato	
	$('.btn-google-maps').click(function(){
		$.fancybox({
			'width'			: 940,
			'height'		: 500,
			'type'			: 'iframe',
			'overlayColor'	: '#000',
			'padding'		: '0',
			'transitionIn'	: 'elastic',
			'transitionOut'	: 'elastic',
			'easingIn'      : 'easeOutBack',
			'easingOut'     : 'easeInBack'
		});
		
		return false;
	});
	
	$('form').each(function(){
		$('input,textarea,button', this).each(function(){
			var title = $(this).prev().text();
			var id = $(this).attr('id');
			
			$(this).attr('name' , id);
		});
	});
	
	$('.form-submit').submit(function(){
		
		return false;
	});
	
	
	function soNumeros(v){
	    return v.replace(/\D/g,"")
	}
	
	
	$('ul#blog-list > li').each(function(e){
		if(e==2)
		{
			$(this).addClass('border-bottom-none padding-bottom-none margin-bottom-none');
		}
	});
	
	
	// bottom	
	$('#footer-linhas ul li a').each(function(){
		$(this).prepend('<span></span>');
	});
	
});

