$(document).ready(function(){
	$("a[rel='external']").attr("target", "_blank");
	
	$(".faq-list h5").click(function(){	   
	   $('.faq-list li').removeClass('active');	   
	   $(this).parent().addClass('active');	   
	   return false;
	});
	
	$('#contato-localidades').hide();

    $('a#show-localidades').click(function() {
        $('#contato-localidades').fadeIn(250);
        return false;
    });
       

    $('a#hide-localidades').click(function() {
	    $('#contato-localidades').fadeOut(250);
	        return false;
    });    
	
});

$(window).load(function(){
	ajustSidebar();
});

function ajustSidebar(){
	if($("#sidebar").height() < $("#site-content").height()){
		$("#sidebar").height($("#site-content").height()+30);
	}
}

function changeProduct(id){
	$('div.product').hide();
	$('div.product.p'+id).show();
	
	ajustSidebar();
};

function formValidate(form){
	$(form).submit(function(){
		var canSubmit = true;
		$(".error-field").removeClass("error-field");
		$('.required').each(function(){
			if($(this).val() == ""){
				$(this).addClass("error-field");	
				canSubmit = false;
			}
		});
		
		if ($('#contact_card').length) {
		  var card = $('#contact_card')
		  if (card.val().length < 16 || strpos(card.val(),"605007") !== 0) {
		      card.addClass("error-field");
		      alert("Número do cartão inválido");
		  }		  
		}
		
		return canSubmit;
	});
}

function openLayer(){
	$('#layer').show();
	
};
function closeLayer(){
	$('#layer').hide();
	return false;
};


if($.browser.msie && $.browser.version <= 6.0) {
	$(document).ready(minMsieProperties);
	$(window).resize(minMsieProperties);
}

function minMsieProperties() {
	if(jQuery(window).height() <= 656) { // COLOCAR ALTURA M�NIMA DO FLASH PARA IE6
		jQuery('html, body, #layer, #overlay').css("height","656px");
	}
	else {
		jQuery('html, body, #layer, #overlay').css("height","100%");
	}
}


function strpos (haystack, needle, offset) {
    // Finds position of first occurrence of a string within another  
    // 
    // version: 909.322
    // discuss at: http://phpjs.org/functions/strpos
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Onno Marsman    
    // +   bugfixed by: Daniel Esteban
    // *     example 1: strpos('Kevin van Zonneveld', 'e', 5);
    // *     returns 1: 14
    var i = (haystack+'').indexOf(needle, (offset ? offset : 0));
    return i === -1 ? false : i;
}
