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


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


$(function(){
	
	$('a[rel="blank"]').click(function(){
		window.open(this.href);
		return false;
	});
	
	$('a[rel="facebook"]').click(function(){
		window.open(this.href, 'facebook', 'width=600, height=300, scrollbars=no, status=no, location=no, toolbar=no, menubar=yes');
		
		return false;
	});
	
	$('.more-link').remove();
	
	$('.magic-label').each(function(){
		var self       = $(this);
		var self_id    = self.attr('id');
		var self_label = $('label[for='+self_id+']').hide();
		
		self_label.next('br').hide();
		
		var reset_value = function(){
			if (self.val() == '')
				self.val(self_label.html());
		}
		
		reset_value();
		
		self.focus(function(){
			if (self.val() == self_label.html())
				self.val('');
		}).blur(reset_value);
	
		self.parents('form').submit(function()
		{
			self.focus();
		});
	});
	
	$('div#menu > ul > li:eq(0)').addClass('menu-shopping');
	$('div#menu > ul > li:eq(1)').addClass('menu-lojas');
	$('div#menu > ul > li:eq(2)').addClass('menu-servicos');
	$('div#menu > ul > li:eq(3)').addClass('menu-novidades');
	$('div#menu > ul > li:eq(4)').addClass('menu-blog');
	$('div#menu > ul > li:eq(5)').addClass('menu-contato');
	
	
	$('div#menu > ul > li > a').parent().hover(function(){
		
		$('div', this).show(0);
		$('.sub-menu', this).stop().animate({ top : 0 }, 300);
		$('#no-bug-menu').stop().animate({ top : 80 }, 100);
		
	},function(){
		
		var topo = $(this).find('ul').height();
		
		$('.sub-menu', this).stop().animate({ top : -topo - 20 }, 750, function(){ $(this).parent().hide(0); $('#no-bug-menu').stop().css({ top : 70 }, 600); });
		
	});
	
	$('div#box-novidades-eventos-index > ul > li:first').addClass('margin-right-40');
	
	$('.box-radious-shadow').each(function(){
		$(this).css({'background-image' : 'url(' + $('img', this).attr('src') + ')'});
		$('img', this).remove();
	});
	
	$('#promocao-slide').cycle({ 
		fx:			'fade', 
		speed:		750, 
		timeout:	5000, 
		pager:		'#nav' 
	});
	
	$('div#novidades-slide ul').cycle({ 
		fx:			'fade', 
		speed:		750, 
		timeout:	5000, 
		pager:		'#novidade-nav' 
	});
	
	$('.select').jqTransform();
	
	$('div#box-midias-sociais > ul > li').each(function(){
		var html = $(this).text();
		
		$(this).append('<span>' + html + '</span>');
		$('span', this).append('<span>');
		
		var margin =  - $('span:first', this).width() / 2 + (5);
		
		$('span:first', this).css({ 'margin-left' : margin });
	});
	
	$("div#box-midias-sociais > ul > li").hover(function() {
		$('span:first', this).show(0).stop().animate({opacity: 1, top: "-35"}, "fast");
	},
	function()
	{
		$('span:first', this).stop().animate({opacity: 0, top: "-45"}, "slow", function(){ $(this).hide(0); });
	});
	
	$('.post-image').each(function(){
		$(this).css({
			'background-image' : 'url('+$('img', this).attr('src')+')'
		});
		$('img', this).hide();
	});
	
	$('div.post-content').each(function(){
		$('p:last', this).addClass('margin-bottom-none');
	});
	/*
	$('div#chamada-site > h2').each(function(){
		$(this).css({'background' : 'url(' + $('img', this).attr('src') + ')'});
		$(this).html($('img', this).attr('alt'));
	});
	*/
	$('ul.list-box-green li').each(function(e){
		$(this).addClass(e % 2 ? 'float-right' : 'float-left');
	});
	
	
	//$('ul#list-lojas li:last').addClass('margin-bottom-none').addClass('padding-bottom-none').addClass('border-bottom-none');
	
	
	//$('#s-segmento').change(function() {
	//	alert('Handler for .change() called.');
	//});
	
	$("#box-lojas-servicos div.jqTransformSelectWrapper ul li a, #box-lojas-servicos-index div.jqTransformSelectWrapper ul li a").click(function(){
		var value = $("#box-lojas-servicos div.jqTransformSelectWrapper span").text();
		var number = $(this).attr('index');
		//var select = $(this).parent().parent().parent().find('select option:eq('+number+')').text();
		var select = $(this).parent().parent().parent().find('select option:eq('+number+')').attr('value');
		
		//window.location = './?s=' + select;
		
		if(select != '-1')
		{
			window.location = './?cat=' + select;
			//alert('agora vai')
		}
		
		return false; //prevent default browser action
	});
	
	$("#box-novidades-eventos div.jqTransformSelectWrapper ul li a, #box-novidades-eventos-page div.jqTransformSelectWrapper ul li a").click(function(){
		var value = $("#box-novidades-eventos div.jqTransformSelectWrapper span").text();
		var number = $(this).attr('index');
		var select = $(this).parent().parent().parent().find('select option:eq('+number+')').attr('value');
		
		window.location = './' + select + '/';
		
		return false; //prevent default browser action
	});
	
	$("#box-select-serv div.jqTransformSelectWrapper ul li a, #box-novidades-eventos-page div.jqTransformSelectWrapper ul li a").click(function(){
		var value = $("#box-select-serv div.jqTransformSelectWrapper span").text();
		var number = $(this).attr('index');
		var select = $(this).parent().parent().parent().find('select option:eq('+number+')').attr('value');
		
		//alert(select);
		
		if(select != '-1')
		{
			window.location = './?cat=' + select;
			//alert('agora vai')
		}
		return false; //prevent default browser action
	});
	
	
	$('#twitter-app').tweet({
		count: 1,
		query: "from:cidadejardimRN",
		loading_text: "Carregando twitter..."
	});
	
});

