$(document).ready(function(){
	
	$(".opacity").css("opacity","0.75"); 
    $("#menu-master li:last a").css("border-right", "none");

	$(".opacity").click(function(){
		$(".opacity, #ampliacao, #solicitar-orcamento, #call, #meerkat-wrap").fadeOut("fast");
	});

    $("a[href='#tabs']").click(function(){
        var selected = $(this).attr('rel');
        $(".tabs li").removeClass();
        var tab = $(".tabs li a[href="+selected+"]");
        tab.parent().parent().addClass('selected');
        $(".info-tabs").hide();
		$("#tab-"+selected).show();
    });

	$(".tabs a").click(function(){
		
		var i = $(this).attr("href");

		if($(this).parent().parent().attr("class")){
			return false;
		} else {
			$(this).parent().parent().parent().find("li").removeClass();
			$(this).parent().parent().addClass("selected");
			$(".info-tabs").slideUp("fast");
			$("#tab-"+i).slideDown();
			return false;
		}
	});
	
	$(".btn-orcamento").click(function(){
		modal("solicitar-orcamento", $(this).attr("href"));
		return false;
	});
	
	$("a#politica").click(function(){
		modal ("solicitar-orcamento", "politica.html");
		return false;
	});
		
	$("#highlight-atendimento a").click(function(){
		modal ("call", "atendimento.php");
		return false;
	});

	$("a.highslide").each(function() {
		this.onclick = function() {
			return hs.expand(this, config1);
		};
	});
	
	$("#marquee").mouseout(function(){
		startit();
	}).mouseover(function(){
		stop();
	});
	
});

/*
   Função para:
 	- Ampliação da imagem do Produto, 
 	- Janela para Solicitação de Orçamento
	- Janela de atendimento telefonico.
*/
function modal (seletor, page){
	$("#"+seletor).load(page);
	$("#meerkat-wrap").show();
	$(".opacity, #" + seletor).fadeIn();
	
	meerkat({
		showMeerkatOnLoad: 'false',
		dontShow: 'none',
		dontShowExpire: 0,
		removeCookie: 'none',
		meerkatPosition: 'top',
		animation: 'fade',
		height: '100%'
	});
};

/*
 * Marquee
 */

var speed = 2; // change scroll speed with this value
var go = 0;
var timeout = '';

function scrollFromBottom(){
  clearTimeout(timeout);
    
  var el = document.getElementById("marquee");
  
  if(el.scrollTop >= el.scrollHeight-el.offsetHeight){
    el.scrollTop = 0;
  };
  el.scrollTop = el.scrollTop + speed;
  if(go == 0){
    timeout = setTimeout("scrollFromBottom()",50);
  };
}
 
function stop(){go = 1;}
 
function startit(){go = 0;scrollFromBottom();}


/*
 * JQuery Plugin: "EqualHeights"
 */

function equalHeight(group) {
    var tallest = 0;
    group.each(function() {
        var thisHeight = $(this).height();
        if(thisHeight > tallest) {
            tallest = thisHeight;
        }
    });
    group.height(tallest);
}


