(function($) {
	$('document').ready(function() {
	
	$('a.menu-topo-busca-submit, a.sidebar-produto-busca-submit').live('click', function(e){
		e.preventDefault();
		$(this).parent('form').submit();
	});
	
	/**
	 * Função para criar placeholders em inputs.
	 */
	jQuery.fn.extend({
		printLabel: function( label ) {
			if ( $(this).val() !== label ) {
				return;
			}
			$(this).val(label);
			$(this).focus(function(){ if($(this).val() === label) {$(this).val(''); }});
			$(this).blur(function(){ if($(this).val() === '') {$(this).val(label); }});
		}
	});
	
	/**
	 * Implementação dos placeholders.
	 */
	$('#header-busca-input').printLabel('Pesquisar no site...');
	$('input#sidebar-pesquisar-produto-termo').printLabel('Pesquisar produto...');
	$('input#footer-input-nome').printLabel('Seu nome...');
	$('input#footer-input-email').printLabel('Seu e-mail...');
	$('input#footer-input-telefone').printLabel('Seu telefone...');
	$('textarea#footer-input-mensagem').printLabel('Sua mensagem...');
	
	/**
	 * Implementação do slideshow.
	 */
	slide_transition = false;
	
	$('ul#slideshow-slides li').hide();
	$('ul#slideshow-slides li:first').show();
	
	slide_interval = setInterval(function() 
	{
		next = $('li.slide-ativo').next('li').length
			 ? $('li.slide-ativo').next('li').attr('id') 
			 : $('ul#slideshow-slides li:first').attr('id');
			
		slideSwitch(next);
	}, 4500);
	
	$('div#slide-seletores a').live('click', function() 
	{
		clearInterval(slide_interval);
		if ( $(this).hasClass('ativo') === true ) {
			return;
		}
		slideSwitch($(this).attr('id').slice(8));
	});
	
	function slideSwitch(slide_id)
	{
		if ( slide_transition === true ) {
			return;
		}
		
		slide_transition = true;
		$('div#slide-seletores a').removeClass('ativo');
		$('a#seletor-' + slide_id).addClass('ativo');

		// Slide atualmente ativo (antes desta função de troca).
		active = $('li.slide-ativo');
		
		// Slide que estará na sequência após o que for selecionado.
		after_next = $('li#' + slide_id).next('li').length ? $('li#' + slide_id).next('li') : $('ul#slideshow-slides li:first');

		$('ul#slideshow-slides li').hide();
		active.show();
		$('li#' + slide_id).show();
		
		active.fadeOut(1500, function() 
		{
			$('li#' + slide_id).addClass('slide-ativo');
			active.removeClass('slide-ativo');
			after_next.show();
			
			slide_transition = false;
		});
	}
	
	/**
	 * Rastreamento de cliques nos banners.
	 */
	$('li.slide-ativo').live('click', function() {
		//alert($(this).attr)
	});
	
	/**
	 * Fancybox da para galeria de fotos de produtos.
	 */
	$('a.produto-fancy-img,.fancybox').fancybox({
		'titleShow'	: true,
		'autoscale'	: false,
		'overlayOpacity': 0.7,
		'overlayColor'	: '#f0f0f0',
		'padding'	: 5,
		'margin'	: 5,
		'centerOnScroll' : true
	});
	
	/**
	 * Carrocel p/ galeria de imagens.
	 */
	$("div#produto-galeria-imagens").carousel({
		loop		: true,
		dispItems	: 3,
		animSpeed	: 500
	});
	
	/**
	 * Tabgroup da página de produto.
	 */
	$('.tab').hide();
	$('.tab:first').show();
	$('.tab-group a').live('click', function(e) 
	{
		e.preventDefault();
		if ( $(this).hasClass('active') === true ) {
			return;
		}
		
		$('.tab-group a').removeClass('active');
		$(this).attr('class', 'active');
		
		$('.tab').stop(true,true).hide();
		$ ( $('ul.tab-group a.active').attr('href').replace(/^.*?#([^#]+)$/, '#tab-$1') ).slideDown('slow');
	});
	
	
	});
})(jQuery);
