/*Modernizr.load({
  test: Modernizr.fontface,
  yep : 'js/do-cufon.js'
});*/

$(document).ready(function(){

    /*if($('#flashMessage')[0]){
		window.location.href=window.location.href+'#flashMessage';
	}*/

	if( typeof $.prettyPhoto != 'undefined' ) $("#conteudo a[rel^=prettyPhoto]").prettyPhoto({theme:'light_square'});

	// locales
	$('#locales').each(
		function()
		{
			$(this).addClass( 'js' );
			$('li:not(.current)', this).hide();

			$('li.current', this).toggle(
				function() { $('li:not(.current)', $(this).parent() ).show(); },
				function() { $('li:not(.current)', $(this).parent() ).hide(); }
			);
		}
	);

    $('ul#parceiros')
		.Slides()
		.css( 'cursor', 'pointer' )
		.click( function(){
			location.href = ('./parceiros');
	});

    $('#navegacao').navMenu();



    /*    function alignMiddle($img,$altura){
        list($width, $height) = getimagesize($img);
        $sobra = $altura - $height;
        $resultado = $sobra/2;
        return $resultado;
    }*/

	/*var blabla = new Array('teste','teste2','teste3');

	console.log(blabla);
	debugger;*/
	
	
	//	Máscaras formulários
	//$("#ContatoTelefone").mask("(99) 9999-9999");
	

	// formulario de busca
	$('#buscaRapida').parseFormNoLabels();

    /*$(".botoes li").each(function(){
        $(this).hover(function() {
            var i = $(this).index();
		    $('.imagens li:eq('+i+') a img').animate({marginTop: "-35"}, "fast");
        }, function() {
            var i = $(this).index();
            $('.imagens li:eq('+i+') a img').animate({marginTop: "0"}, "slow");
        });
    });*/

    	// slides de destaques de noticias
	//$('#auxiliar > li.noticias ul').Slides();

});

$(window).load(function(){
    //alinha no meio as imgs do produtos
    $('.listaProdutos ul li a img').each(function(index){
        altura = $(this).height();
        height = $(this).parent().height();
        sobra =  height - altura;
        resultado = sobra/2;
        $(this).css('marginTop',resultado);
    });

    altura = $('.produto figure a img').height();
    sobra = $('.produto figure a img').parent().height() - altura;
    resultado = sobra/2;
    $('.produto figure a img').css('marginTop',resultado);
});




(function ($) {
// PARSE FORM NO LABELS
$.fn.parseFormNoLabels = function() {
	return this.each(function(i){
	var f = $(this);
	f.addClass( 'parsed' );
	f.find( 'label' ).css( {'position':'absolute', 'cursor':'text', 'display':'block' });
	f.find( 'input[type=text], select' ).each( function(){ this.label=$('label[for='+this.id+']'); } );
	f.find( 'input[type=text], select' ).focus( function() { $(this.label).css('opacity','0.5'); } );
	f.find( 'input[type=text], select' ).blur( function() { $(this.label).css('opacity','1'); } );
	f.find( 'input[type=text], select' ).bind( 'keyup change', function() {
		if( $(this).val() ) $(this.label).css('display','none');
		else $(this.label).css('display','inline');
	} );
	});
};
})(jQuery);



///////////////////////////// SLIDES
(function($) {

	$.Slides = {
		tempo			:	5000,
		itensControle	:	[],
		atual			:	0,
		interval		:	null,
		imgs			:	[],
		tgt				:	null
	};

	$.fn.Slides = function(settings) {

		if (settings) $.extend($.Slides, settings);

		var ulOriginal = $(this);

		ulOriginal.before( '<div id="SlidesControle"></div>' );
		var controle = $('#SlidesControle');

		controle.html('<a href="javascript:;" class="anterior">anterior</a><a href="javascript:;" class="proximo">próximo</a>');

		controle.find('a.anterior').click( anterior );
		controle.find('a.proximo').click( proximo );

		ulOriginal
			.mouseover( interrompeTempo )
			.mouseout( iniciaTempo );


		$.Slides.tgt = ulOriginal.find( 'li' );

		var im = $.Slides.tgt.find('img').each(
			function() {

				var im = $(this);
				im.css('margin-top', Math.floor( (im.parent().height() - im.height()) / 2 ));

				$(this).ready( function(){
					im.css('margin-top', Math.floor( (im.parent().height() - im.height()) / 2 ));
				} );
			}
		);

		$.Slides.tgt.css('display','none');

		trocaSlide( 0 );


		return this;


	};


	var proximo = function() { trocaSlide( $.Slides.atual+1 ); }
	var anterior = function() { trocaSlide( $.Slides.atual-1 ); }

	var iniciaTempo = function() { $.Slides.interval = setTimeout( proximo, $.Slides.tempo ); }
	var interrompeTempo = function() { clearTimeout( $.Slides.interval ); }


	var trocaSlide = function( slide )
	{

		if( $.Slides.tgt.queue('fx') != undefined && $.Slides.tgt.queue('fx').length == 0) {	

			if( slide > $.Slides.tgt.length-1 ) slide = 0;
			if( slide < 0 ) slide = $.Slides.tgt.length-1;

			$.Slides.atual = slide;

			var atual = $( $.Slides.tgt[$.Slides.atual] );
			$.Slides.tgt.each( function(){
				if( this != $.Slides.tgt[$.Slides.atual] ) $(this).fadeOut();
		} );


			atual.fadeIn();

			interrompeTempo();
			iniciaTempo();
		}
	}

})(jQuery);

function strtolower (str) {
    return (str + '').toLowerCase();
}

/***************************/
/*
 * jQuery stringToSlug plug-in 1.2.0
 *
 * Plugin HomePage http://leocaseiro.com.br/jquery-plugin-string-to-slug/
 *
 * Copyright (c) 2009 Leo Caseiro
 *
 * Based on Edson Hilios (http://www.edsonhilios.com.br/ Algoritm
 *
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 */

jQuery.fn.stringToSlug = function(options) {
	var defaults = {
 		setEvents: 'keyup keydown blur', //set Events that your script will work
		getPut: '#permalink', //set output field
		space: '-', //Sets the space character. If the hyphen,
		prefix: '',
		suffix: '',
		replace: '' //Sample: /\s?\([^\)]*\)/gi
	};

	var opts = jQuery.extend(defaults, options);

	jQuery(this).bind(defaults.setEvents, function () {
		var text = jQuery(this).val();
		text = defaults.prefix + text + defaults.suffix; //Concatenate with prefix and suffix
		text = text.replace(defaults.replace, ""); //replace
		text = jQuery.trim(text.toString()); //Remove side spaces and convert to String Object

		var chars = []; //Cria vetor de caracteres
		for (var i = 0; i < 32; i++) {
			chars.push ('');
		}

		/*** Abaixo a lista de caracteres ***/
		chars.push (defaults.space); // Unicode 32
		chars.push ('');   // !
		chars.push ('');   // "
		chars.push ('');   // #
		chars.push ('');   // $
		chars.push ('');   // %
		chars.push ('');   // &
		chars.push ("");   // '
		chars.push ('-');  // (
		chars.push ('-');  // );
		chars.push ('');   // *
		chars.push ('');   // +
		chars.push ('-');  // );
		chars.push ('-');  // -
		chars.push ('-');  // .
		chars.push ('-');  // /
		chars.push ('0');  // 0
		chars.push ('1');  // 1
		chars.push ('2');  // 2
		chars.push ('3');  // 3
		chars.push ('4');  // 4
		chars.push ('5');  // 5
		chars.push ('6');  // 6
		chars.push ('7');  // 7
		chars.push ('8');  // 8
		chars.push ('9');  // 9
		chars.push ('');   // :
		chars.push ('');   // ;
		chars.push ('');   // <
		chars.push ('');   // =
		chars.push ('');   // >
		chars.push ('');   // ?
		chars.push ('');   // @
		chars.push ('A');  // A
		chars.push ('B');  // B
		chars.push ('C');  // C
		chars.push ('D');  // D
		chars.push ('E');  // E
		chars.push ('F');  // F
		chars.push ('G');  // G
		chars.push ('H');  // H
		chars.push ('I');  // I
		chars.push ('J');  // J
		chars.push ('K');  // K
		chars.push ('L');  // L
		chars.push ('M');  // M
		chars.push ('N');  // N
		chars.push ('O');  // O
		chars.push ('P');  // P
		chars.push ('Q');  // Q
		chars.push ('R');  // R
		chars.push ('S');  // S
		chars.push ('T');  // T
		chars.push ('U');  // U
		chars.push ('V');  // V
		chars.push ('W');  // W
		chars.push ('X');  // X
		chars.push ('Y');  // Y
		chars.push ('Z');  // Z
		chars.push ('-');  // [
		chars.push ("-");  // /
		chars.push ('-');  // ]
		chars.push ('');   // ^
		chars.push ('-');  // _
		chars.push ('');   // `
		chars.push ('a');  // a
		chars.push ('b');  // b
		chars.push ('c');  // c
		chars.push ('d');  // d
		chars.push ('e');  // e
		chars.push ('f');  // f
		chars.push ('g');  // g
		chars.push ('h');  // h
		chars.push ('i');  // i
		chars.push ('j');  // j
		chars.push ('k');  // k
		chars.push ('l');  // l
		chars.push ('m');  // m
		chars.push ('n');  // n
		chars.push ('o');  // o
		chars.push ('p');  // p
		chars.push ('q');  // q
		chars.push ('r');  // r
		chars.push ('s');  // s
		chars.push ('t');  // t
		chars.push ('u');  // u
		chars.push ('v');  // v
		chars.push ('w');  // w
		chars.push ('x');  // x
		chars.push ('y');  // y
		chars.push ('z');  // z
		chars.push ('-');  // {
		chars.push ('');   // |
		chars.push ('-');  // }
		chars.push ('');   // ~
		chars.push ('');   // ?
		chars.push ('C');
		chars.push ('A');
		chars.push ('');
		chars.push ('f');
		chars.push ('');
		chars.push ('');
		chars.push ('T');
		chars.push ('t');
		chars.push ('');
		chars.push ('');
		chars.push ('S');
		chars.push ('');
		chars.push ('CE');
		chars.push ('A');
		chars.push ('Z');
		chars.push ('A');
		chars.push ('A');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('-');
		chars.push ('-');
		chars.push ('');
		chars.push ('TM');
		chars.push ('s');
		chars.push ('');
		chars.push ('ae');
		chars.push ('A');
		chars.push ('z');
		chars.push ('Y');
		chars.push ('');
		chars.push ('');
		chars.push ('c');
		chars.push ('L');
		chars.push ('o');
		chars.push ('Y');
		chars.push ('');
		chars.push ('S');
		chars.push ('');
		chars.push ('c');
		chars.push ('a');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('r');
		chars.push ('-');
		chars.push ('o');
		chars.push ('');
		chars.push ('2');
		chars.push ('3');
		chars.push ('');
		chars.push ('u');
		chars.push ('p');
		chars.push ('');
		chars.push ('');
		chars.push ('1');
		chars.push ('o');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('A');
		chars.push ('A');
		chars.push ('A');
		chars.push ('A');
		chars.push ('A');
		chars.push ('A');
		chars.push ('AE');
		chars.push ('C');
		chars.push ('E');
		chars.push ('E');
		chars.push ('E');
		chars.push ('E');
		chars.push ('I');
		chars.push ('I');
		chars.push ('I');
		chars.push ('I');
		chars.push ('D');
		chars.push ('N');
		chars.push ('O');
		chars.push ('O');
		chars.push ('O');
		chars.push ('O');
		chars.push ('O');
		chars.push ('x');
		chars.push ('O');
		chars.push ('U');
		chars.push ('U');
		chars.push ('U');
		chars.push ('U');
		chars.push ('Y');
		chars.push ('D');
		chars.push ('B');
		chars.push ('a');
		chars.push ('a');
		chars.push ('a');
		chars.push ('a');
		chars.push ('a');
		chars.push ('a');
		chars.push ('ae');
		chars.push ('c');
		chars.push ('e');
		chars.push ('e');
		chars.push ('e');
		chars.push ('e');
		chars.push ('i');
		chars.push ('i');
		chars.push ('i');
		chars.push ('i');
		chars.push ('o');
		chars.push ('n');
		chars.push ('o');
		chars.push ('o');
		chars.push ('o');
		chars.push ('o');
		chars.push ('o');
		chars.push ('');
		chars.push ('o');
		chars.push ('u');
		chars.push ('u');
		chars.push ('u');
		chars.push ('u');
		chars.push ('y');
		chars.push ('');
		chars.push ('y');
		chars.push ('z');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('C');
		chars.push ('c');
		chars.push ('D');
		chars.push ('d');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('E');
		chars.push ('e');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('N');
		chars.push ('n');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('R');
		chars.push ('r');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('S');
		chars.push ('s');
		chars.push ('');
		chars.push ('');
		chars.push ('T');
		chars.push ('t');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('U');
		chars.push ('u');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('');
		chars.push ('Z');
		chars.push ('z');

		for (var i = 256; i < 100; i++) {
			chars.push ('');
		}

		var stringToSlug = new String (); //Create a stringToSlug String Object
		for (var i = 0; i < text.length; i ++) {
			stringToSlug += chars[text.charCodeAt (i)]; //Insert values converts at slugs
		}

		stringToSlug = stringToSlug.replace (new RegExp ('\\'+defaults.space+'{2,}', 'gmi'), defaults.space); // Remove any space character followed by Breakfast
		stringToSlug = stringToSlug.replace (new RegExp ('(^'+defaults.space+')|('+defaults.space+'$)', 'gmi'), ''); // Remove the space at the beginning or end of string

		stringToSlug = stringToSlug.toLowerCase(); //Convert your slug in lowercase


		jQuery(defaults.getPut).val(stringToSlug); //Write in value to input fields (input text, textarea, input hidden, ...)
		jQuery(defaults.getPut).html(stringToSlug); //Write in HTML tags (span, p, strong, h1, ...)


		return this;
	});

  return this;
}





