var mensure;
var timeIDstopScroll = null; //usado no evento scroll

window.onload = function(e)
{
	mensure = new unitsWindow();
	mensure.load();

	SA.create();
	SAWait.create();
}

window.onresize = function(e)
{
	try{
		mensure.load();
	}catch(e){}
		

	SA.refresh();
	SAWait.refresh();
	GA.refresh();
};

window.onscroll = function() {
	if (timeIDstopScroll != null) clearTimeout(timeIDstopScroll);
	timeIDstopScroll = setTimeout(onscrollstop, 50);
};
onscrollstop = function() {
	SA.refresh();
	SAWait.refresh();
	GA.refresh();
};

document.onkeydown = function(e) {
	if (!e) var e = window.event;

	var numkey = (is_ie)?e.keyCode:e.which;

	if (numkey == 27 && SA.opened == 1 && SA.ESCClose == 1) {
		SA.close();
		if (window.event) e.returnValue = false;
		else e.preventDefault();
	}
}

/** banner destaque - nivo slider **/

$(window).load(function() {
    $('#slider').nivoSlider({
        effect:'random', // Specify sets like: 'fold,fade,sliceDown'
        slices:10, // For slice animations
        boxCols: 6, // For box animations
        boxRows: 4, // For box animations
        animSpeed:500, // Slide transition speed
        pauseTime:4000, // How long each slide will show
        startSlide:0, // Set starting Slide (0 index)
        directionNav:false, // Next & Prev navigation
        directionNavHide:false, // Only show on hover
        controlNav:false, // 1,2,3... navigation
        controlNavThumbs:false, // Use thumbnails for Control Nav
        controlNavThumbsFromRel:false, // Use image rel for thumbs
        controlNavThumbsSearch: '.jpg', // Replace this with...
        controlNavThumbsReplace: '_thumb.jpg', // ...this in thumb Image src
        keyboardNav:true, // Use left & right arrows
        pauseOnHover:false, // Stop animation while hovering
        manualAdvance:false, // Force manual transitions
        captionOpacity:0.8, // Universal caption opacity
        prevText: 'Prev', // Prev directionNav text
        nextText: 'Next', // Next directionNav text
        beforeChange: function(){}, // Triggers before a slide transition
        afterChange: function(){}, // Triggers after a slide transition
        slideshowEnd: function(){}, // Triggers after all slides have been shown
        lastSlide: function(){}, // Triggers when last slide is shown
        afterLoad: function(){} // Triggers when slider has loaded
    });
});

$(window).load(function() {
	$('#sliderEstrutura').nivoSlider({
		effect:'fade', // Specify sets like: 'fold,fade,sliceDown'
		slices:5, // For slice animations
		boxCols:4, // For box animations
		boxRows:4, // For box animations
		animSpeed:400, // Slide transition speed
		pauseTime:3000, // How long each slide will show
		startSlide:0, // Set starting Slide (0 index)
		directionNav:false, // Next & Prev navigation
		directionNavHide:false, // Only show on hover
		controlNav:false, // 1,2,3... navigation
		controlNavThumbs:false, // Use thumbnails for Control Nav
		controlNavThumbsFromRel:false, // Use image rel for thumbs
		controlNavThumbsSearch: '.jpg', // Replace this with...
		controlNavThumbsReplace: '_thumb.jpg', // ...this in thumb Image src
		keyboardNav:true, // Use left & right arrows
		pauseOnHover:false, // Stop animation while hovering
		manualAdvance:false, // Force manual transitions
		captionOpacity:0.8, // Universal caption opacity
		prevText: 'Prev', // Prev directionNav text
		nextText: 'Next', // Next directionNav text
		beforeChange: function(){}, // Triggers before a slide transition
		afterChange: function(){}, // Triggers after a slide transition
		slideshowEnd: function(){}, // Triggers after all slides have been shown
		lastSlide: function(){}, // Triggers when last slide is shown
		afterLoad: function(){} // Triggers when slider has loaded
	});
});


/*** 
    Simple jQuery Slideshow Script
    Released by Jon Raasch (jonraasch.com) under FreeBSD license: free to use or modify, not responsible for anything, etc.  Please link out to me if you like it :)
***/

function slideSwitch() {
    var $active = $('#listaParceiros ul.active');

    if ( $active.length == 0 ) $active = $('#listaParceiros ul:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#listaParceiros ul:first');

    // uncomment the 3 lines below to pull the images in random order
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );

    $active.addClass('last-active');
	$active.animate({opacity: 0}, 500, function() {
            $active.css('display', 'none');
	});

	$next.css('display', 'block');
    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 500, function() {
            $active.removeClass('active last-active');
        });
}

function centerParceiros() {
	$('#listaParceiros ul').each(function(){
		$(this).css('width',$(this).width());
		$(this).css('left','50%');
		$(this).css('margin-left',-($(this).width()/2));
		if ( $(this).find('li').length == 1 ) {
			$(this).css('min-width','430px');
			$(this).css('margin-left',-($(this).width()/2));
			$(this).find('li').css({
				'width' : '170px',
				'float' : 'none',
				'display' : 'block',
				'margin' : '0 auto'
			});
		}
	});
}
	
$(document).ready(function(){
	
	/** menu fade **/

	$('#containerMenu #Menu ul li:nth-child('+secaoSwf+') a img').stop().fadeTo(500, 0);

	//Set opacity on each span to 0%
	//$('#containerMenu #menu ul li a').css({'opacity':'0'});

	$('#containerMenu #Menu ul li').hover(
		function() {
			if ( secaoSwf-1 != $(this).index() ) {
				$(this).find('a img').stop().fadeTo(250, 0);
			}
		},
		function() {
			if ( secaoSwf-1 != $(this).index() ) {
				$(this).find('a img').stop().fadeTo(250, 1);
			}
		}
	)
	
	$('#menuParceiros li:nth-child('+tipoParceiroSwf+') a').stop().fadeTo(500, 0);
	
	$('#menuParceiros ul li').hover(
		function() {
			if ( tipoParceiroSwf-1 != $(this).index() ) {
				$(this).find('a').stop().fadeTo(200, 0);
			}
		},
		function() {
			if ( tipoParceiroSwf-1 != $(this).index() ) {
				$(this).find('a').stop().fadeTo(200, 1);
			}
		}
	)
	
	var now = new Date();
	var tempo = now.getHours()+""+now.getMinutes()+""+now.getSeconds();
	/*
	jQuery.ajax({
		type: "GET",
		url: "/xmlParceiros?full=0&timer="+tempo,
		dataType: "xml",
		success: function(xml) {
			var uls = [];
			
			$(xml).find('parceiro').each(function(){
				uls[$(this).attr('tipo')] = $('<ul>', { 'class' : 'tipo'+$(this).attr('tipo') });
			});
			
			$(xml).find('parceiro').each(function(){
				var tipo = $(this).attr('tipo');
				var titulo = $(this).attr('titulo');
				var logog = $(this).attr('logog');
				uls[tipo].append('<li><a href="/parceiros?tipoparceiro='+tipo+'"><img src="/media/'+logog+'" /></a></li>');
			});
			
			$(uls).each(function(){
				$('#listaParceiros').append(this);
			});
			
			//$('#listaParceiros ul:first').addClass("active");
		}
	});
	*/
	
	$(function() {
    	setTimeout( "slideSwitch()", 100 );
	});
	
	$(function() {
    	setInterval( "slideSwitch()", 4000 );
	});
	
	
	
	/*
	$(function() {
    	setTimeout( "centerParceiros()", 200 );
	});
	*/
});


