/*-----------------------------------------------------------------------------------------------------------*/
/*MENSAGEM DE ALERTA*/
function Mensagem(sMensagem){
     alert(sMensagem);
}
function verifica() {
     window.alert("erro")
     return false;
}

/*-----------------------------------------------------------------------------------------------------------*/
/*BANNER TOPO HOME*/
$(document).ready(function() {
	$(".paging").show();
	$(".paging a:first").addClass("active");
	
	var imageWidth = $(".window").width();
	var imageSum = $(".image_reel img").size();
	var imageReelWidth = imageWidth * imageSum;
	
	$(".image_reel").css({'width' : imageReelWidth});
	
	rotate = function(){	
		var triggerID = $active.attr("rel") - 1;
		var image_reelPosition = triggerID * imageWidth;

		$(".paging a").removeClass('active');
		$active.addClass('active');
		
		$(".image_reel").animate({ 
			left: -image_reelPosition
		}, 500 );
		
	}; 
	
	rotateSwitch = function(){		
		play = setInterval(function(){
			$active = $('.paging a.active').next();
			if ( $active.length === 0) {
				$active = $('.paging a:first');
			}
			rotate();
		}, 7000);
	};
	
	rotateSwitch();
	
	$(".image_reel a").hover(function() {
		clearInterval(play);
	}, function() {
		rotateSwitch();
	});	
	
	$(".paging a").click(function() {	
		$active = $(this);
		clearInterval(play);
		rotate();
		rotateSwitch();
		return false;
	});	
	
});

/*-----------------------------------------------------------------------------------------------------------*/
/*GOOGLE ANALYTCS*/
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-24352951-1']);
_gaq.push(['_trackPageview']);

(function() {
  	var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
   	ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  	var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

/*-----------------------------------------------------------------------------------------------------------*/
/*MENU SUPERIOR*/
$(function() {
	$("ul#menu span").css("opacity","0");
	$("ul#menu span").hover(function () {
		$(this).stop().animate({
			opacity: 5
		}, 'slow');
	},
	function () {
		$(this).stop().animate({
			opacity: 0
		}, 'slow');
	});
});

/*-----------------------------------------------------------------------------------------------------------*/
/*FAQ (ABRIR TEXTOS)*/
function change(id){

	elem = $("#faq" + id);

	if(elem.css("display") == "none")
		$("#faq" + id).slideDown(500);
	else
		$("#faq" + id).slideUp(500);

}

/*-----------------------------------------------------------------------------------------------------------*/
/*FORMATAR CAMPOS E BOTÕES*/
function css_browser_selector(u) {
	var ua=u.toLowerCase(),is=function(t) {
		return ua.indexOf(t)>-1
	},
	g='gecko',
	w='webkit',
	s='safari',
	o='opera',
	m='mobile',
	h=document.documentElement,
	b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3.5')?g+' ff3 ff3_5':is('firefox/3.6')?g+' ff3 ff3_6':is('firefox/3')?g+' ff3':is('gecko/')?g:is('opera')?o+(/version\/(\d+)/.test(ua)?' '+o+RegExp.$1:(/opera(\s|\/)(\d+)/.test(ua)?' '+o+RegExp.$2:'')):is('konqueror')?'konqueror':is('blackberry')?m+' blackberry':is('android')?m+' android':is('chrome')?w+' chrome':is('iron')?w+' iron':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',
	is('j2me')?m+' j2me':is('iphone')?m+' iphone':is('ipod')?m+' ipod':is('ipad')?m+' ipad':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win'+(is('windows nt 6.0')?' vista':''):is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js'];
	c = b.join(' ');
	h.className += ' '+c;
	return c;
};
css_browser_selector(navigator.userAgent);

/*-----------------------------------------------------------------------------------------------------------*/
/*LIGHTBOX*/
$(document).ready(function() {	
	$('a[name=modal]').click(function(e) {
		e.preventDefault();
		
		var id = $(this).attr('href');
	
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
	
		$('#mask').css({'width':maskWidth,'height':maskHeight});

		$('#mask').fadeIn(1000);	
		$('#mask').fadeTo("slow",0.8);	
	
		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();
              
		$(id).css('top',  winH/2-$(id).height()/2);
		$(id).css('left', winW/2-$(id).width()/2);
	
		$(id).fadeIn(2000); 
	
	});
	
	$('.window .close').click(function (e) {
		e.preventDefault();
		
		$('#mask').hide();
		$('.window').hide();
	});		
	
	$('#mask').click(function () {
		$(this).hide();
		$('.window').hide();
	});			
	
});

/*-----------------------------------------------------------------------------------------------------------*/
/*CLIENTES HOME*/
$(window).load(function(){
	jQuery(document).ready(function() {

    var $jc = $.jcarousel;
    $jc.fn.extend({
		startAuto: function(s) {

            if (s !== undefined) {
                this.options.auto = s;
            }

            if (this.options.auto === 0) {
                return this.stopAuto();
            }

            if (this.timer !== null) {
                return;
            }

            this.autoStopped = false;

            var self = this;

            if (this.options.auto < 0) {
                this.timer = window.setTimeout(function() {
                    self.prev();
                }, -this.options.auto * 1000);
            }
			else {
                this.timer = window.setTimeout(function() {
                    self.next();
                }, this.options.auto * 1000);
            }
        }
    });
});

function mycarousel_initCallback(carousel) {
    carousel.buttonNext.bind('click', function() {
        if(carousel.options.auto < 0) {
            carousel.startAuto(-carousel.options.auto);
        }
    });
    carousel.buttonPrev.bind('click', function() {
        if(carousel.options.auto > 0) {
            carousel.startAuto(-carousel.options.auto);
        }
    });
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

jQuery(document).ready(function() {
    jQuery('#mycarousel').jcarousel({
        auto: 2,
        wrap: 'circular',
        initCallback: mycarousel_initCallback
    });
});
});

