var placeholder = function(selector, value) {
	$(selector).focus(function()
	{
		if ($(this).val() == value) {
			$(this).val('');
		}
	})
	.blur(function()
	{
		if ($(this).val().length == 0) {
			$(this).val(value);
		}
	});
},

switch_tabs = function(obj) {
	$('.tab-content').hide();
	$('.tabControl a').removeClass("selected");
	$('.tabControl a').addClass("opacity50");
	obj.removeClass("opacity50");
	var id = obj.attr("rel");
 
	$('#'+id).show();
	obj.addClass("selected");
},

search = function(keys, url) {
	var search = "http://www.google.com/custom?domains=" + url + "&sitesearch=" + url + "&q=" + keys;
	location.href = search;
},

runScript = function() {
	// SLIDER
	/*$('#runCycle')
		.before('<div id="navSlider">')
		.cycle({
			fx:     'fade', 
			speed:  'fast', 
			timeout: 5000, // Velocidade da mudança de slide 5000 = 5s
			pager:  '#navSlider',
			after:	function() {
				var relClass = $(this).attr('rel');

				$('#runTitle').html($('.description.'+relClass).html());
			}
		}
	);
	$('#runTitle').show();*/

	// PLACEHOLDER
	placeholder($('#search'), 'Buscar a palavra-chave');
	placeholder($('#newsNome'), 'nome:');
	placeholder($('#newsEmail'), 'e-mail:');

	// SEARCH
	$('#formSearch button').click(function() {
		console.log('reii');
		search($('#formSearch #search').val(), 'panificadoraformosa.com.br');

		return false;
	});

	$('div.showImg a').click(function() {
		var mainImage = $(this).attr("href"), //Procura nome da Imagem
			img = $('<img />', {
					src : mainImage
				  });

		$(this).siblings('a').removeClass('active')
		
		$(this).addClass('active');
		$(this).siblings('div').html(img);

		return false;		
	});

	// TABS
	$('.tabControl a').click(function(){
		switch_tabs($(this));

		return false;
	});
 
	switch_tabs($('.defaulttab'));

	// CARDAPIO
	$('.boxgrid.peek').hover(function(){
		$(".cover", this).stop().animate({top:'76px'},{queue:false,duration:160});
	}, function() {
		$(".cover", this).stop().animate({top:'0px'},{queue:false,duration:160});
	});

	$('div.boxgrid a').click(function() {
		if (!$(this).parent().hasClass('current')) {
			var id = $(this).attr('rel');

			if ($('div.details h1.intro').length > 0) {
				$('div.details h1.intro').remove();
			}

			$('div.itens').hide();
			$('div.boxgrid').removeClass('current');
			$(this).parent().addClass('current');

			$('#'+id).show('fast');
		}

		return false;
	});

	// FAÇA SEU EVENTO
	$("a[rel=group]").fancybox();
};

$(document).ready(runScript);
