﻿$(window).load(function() {

if ($('#overlay').length) {
var dl=22000;
var win = jQuery(window);
var h2 = win.height();
var w2 = win.width();
$.browser.msie && $.browser.version<"9.0" ? $("#overlay").height(h2).show() : $("#overlay").delay(500).height(h2).fadeIn(500,"ease");
var w1 = $('#loader').outerWidth();
var h1 = $('#loader').outerHeight();
var x = (w2/2-w1/2) + 'px';
var x1 = (w2/2-w1/2)+960 + 'px';
var y = (h2/2-h1/2)-16 + 'px';
var y1 = (h2/2-h1/2)-24 + 'px';
$('#loader')
.delay(800)
.css({'left':x,'top':y})
.animate({opacity:1})
.show();
$('#fechar')
.delay(800)
.css({'left':x1,'top':y1})
.animate({opacity:1})
.show();
setTimeout( "$('#loader').fadeOut();",dl);
setTimeout( "$('#fechar').fadeOut();",dl);
setTimeout( "$('#overlay').fadeOut();",dl);
}
$('#overlay, #fechar').click(function(e) {
e.preventDefault();
$('#fechar').hide();
$('#loader').fadeOut();
$('#overlay').fadeOut('slow');
});
});

$(document).ready(function() {

var r= Math.floor(Math.random() * 8);
$('#topo').css('background', '#AAA url(./img/img' + r + '.jpg) no-repeat').fadeIn();

$.easing.ease = function (x, t, b, c, d) {
if ((t/=d/2) < 1) return c/2*t*t + b;
return -c/2 * ((--t)*(t-2) - 1) + b;
};

$('#slider li').each(function(){
$(this).click(function(){
window.location=$('a', this).attr('href');
return false
});
});

if ($('#slider').length) {
$('#slider li').hoverIntent(function() {
$('div', this).slideDown(300,'ease')
},
function() {
$('div', this).slideUp(240,'ease');
});
}

var step = 1;
var current = 0;
var max = $('#slider li').size();
var visible = 5;
var speed = 350;
var liSize = 178;
var slider_height = 240;
var ulSize = liSize * max;
var divSize = liSize * visible;

$('#slider').css("width", divSize+"px").css("height", slider_height+"px").css("visibility", "visible").css("overflow", "hidden").css("position", "relative");

$('#slider ul').css("width", ulSize+"px").css("left", -(current * liSize)).css("position", "absolute");

$('#bt_prev').click(function() {
if(current + step < 0 || current + step > max - visible) {
return;
}
else {
current = current + step;
$('#slider ul').stop().animate({left: -(liSize * current)}, speed, 'ease');
}
return false
});

$('#bt_next').click(function() {
if(current - step < 0 || current - step > max - visible) {
return;
}
else {
current = current - step;
$('#slider ul').stop().animate({left: -(liSize * current)}, speed, 'ease');
}
return false
});

$('#sl_wrap span').hover(function() {
$(this).css('background-position','0px -40px');
},
function() {
$(this).css('background-position','0px 0px');
});


});

