/* Paginacao */
jQuery(function($){ $('.Destaques ul').easyPaginate({
step:1, nextprev:false, auto:true, pause:9000, clickstop:false, controls:'Paginacao', current:'Atual'
}); });

(function($) {
		  
	$.fn.easyPaginate = function(options){

		var defaults = {				
			step: 4,
			delay: 100,
			numeric: true,
			nextprev: true,
			auto:false,
			pause:4000,
			clickstop:true,
			controls: 'pagination',
			current: 'current' 
		}; 
		
		var options = $.extend(defaults, options); 
		var step = options.step;
		var lower, upper;
		var children = $(this).children();
		var count = children.length;
		var obj, next, prev;		
		var page = 1;
		var timeout;
		var clicked = false;
		
		function show(){
			clearTimeout(timeout);
			lower = ((page-1) * step);
			upper = lower+step;
			$(children).each(function(i){
				var child = $(this);
				child.hide();
				if(i>=lower && i<upper){ setTimeout(function(){ child.fadeIn('fast') }, ( i-( Math.floor(i/step) * step) )*options.delay ); }
				if(options.nextprev){
					if(upper >= count) { next.fadeOut('fast'); } else { next.fadeIn('fast'); };
					if(lower >= 1) { prev.fadeIn('fast'); } else { prev.fadeOut('fast'); };
				};
			});	
			$('li','#'+ options.controls).removeClass(options.current);
			$('li[data-index="'+page+'"]','#'+ options.controls).addClass(options.current);
			if(upper >= count) { page = 0;	}
			
			if(options.auto){
				if(options.clickstop && clicked){}else{ timeout = setTimeout(auto,options.pause); };
			};
		};
		
		function auto(){
			if(upper <= count){ page++; show(); }			
		};
		
		this.each(function(){ 
			
			obj = this;
			
			if(count>step){
				
				var pages = Math.floor(count/step);
				if((count/step) > pages) pages++;
				
				var ol = $('<ol id="'+ options.controls +'"></ol>').insertAfter(obj);
				
				if(options.nextprev){
					prev = $('<li class="prev">Previous</li>')
						.hide()
						.appendTo(ol)
						.click(function(){
							clicked = true;
							page--;
							show();
						});
				};
				
				if(options.numeric){
					for(var i=1;i<=pages;i++){
					$('<li data-index="'+ i +'">'+ i +'</li>')
						.appendTo(ol)
						.click(function(){	
							clicked = true;
							page = $(this).attr('data-index');
							show();
						});					
					};				
				};
				
				if(options.nextprev){
					next = $('<li class="next">Next</li>')
						.hide()
						.appendTo(ol)
						.click(function(){
							clicked = true;			
							page++;
							show();
						});
				};
			
				show();
			};
		});	
		
	};	

})(jQuery);

(function($){
$.fn.pageSlide = function(options) {

var settings = $.extend({
width:          "500px", // Accepts fixed widths
duration:       450, // Accepts standard jQuery effects speeds (i.e. fast, normal or milliseconds)
direction:      "right", // default direction is left.
modal:          true, // if true, the only way to close the pageslide is to define an explicit close class. 
_identifier: $(this)
}, options);

// these are the minimum css requirements for the pageslide elements introduced in this plugin.

var pageslide_slide_wrap_css = {
position: 'fixed',
width: '0',
top: '0',
height: '100%',
zIndex:'999'};

var pageslide_body_wrap_css = {
position: 'relative',
zIndex: '0'};

var pageslide_blanket_css = { 
position: 'fixed',
top: '0px',
left: '0px',
height: '100%',
width: '100%', 
opacity: '0.0',
backgroundColor: '#111',
zIndex: '1',
display: 'none'};

function _initialize(anchor) {

// Create and prepare elements for pageSlide
if ($("#pageslide-body-wrap, #pageslide-content, #pageslide-slide-wrap").size() == 0) {

var psBodyWrap = document.createElement("div");
$(psBodyWrap).css(pageslide_body_wrap_css);
$(psBodyWrap).attr("id","pageslide-body-wrap").width( $("body").width() );
$("body").contents().wrapAll( psBodyWrap );

var psSlideContent = document.createElement("div");
$(psSlideContent).attr("id","pageslide-content").width( settings.width );

var psSlideWrap = document.createElement("div");
$(psSlideWrap).css(pageslide_slide_wrap_css);
$(psSlideWrap).attr("id","pageslide-slide-wrap").append( psSlideContent );
$("body").append( psSlideWrap );

}

// introduce the blanket if modal option is set to true.
if ($("#pageslide-blanket").size() == 0 && settings.modal == true) {
var psSlideBlanket = document.createElement("div");
$(psSlideBlanket).css(pageslide_blanket_css);
$(psSlideBlanket).attr("id","pageslide-blanket");
$("body").append( psSlideBlanket );
$("#pageslide-blanket").click(function(){ return false; });
}

// Callback events for window resizing
$(window).resize(function(){
$("#pageslide-body-wrap").width( $("body").width() );
});

// mark the anchor!
$(anchor).attr("rel","pageslide");

};

function _openSlide(elm) {
if($("#pageslide-slide-wrap").width() != 0) return false;
_showBlanket();
// decide on a direction
if (settings.direction == "right") {
direction = {right:"-"+settings.width};
$("#pageslide-slide-wrap").css({left:0});
_overflowFixAdd();
} 
else {
direction = {left:"-"+settings.width};
$("#pageslide-slide-wrap").css({right:0});
}
$("#pageslide-slide-wrap").animate({width: settings.width}, settings.duration);
$("#pageslide-body-wrap").animate(direction, settings.duration, function() {
$.ajax({
type: "GET",
url: $(elm).attr("href"),
success: function(data){
$("#pageslide-content").css("width",settings.width).html(data)
.queue(function(){
$(this).dequeue();

// add hook for a close button
$(this).find('.pageslide-close').unbind('click').click(function(elm){
_closeSlide(elm);
$(this).find('pageslide-close').unbind('click');
});
});
}
});
});
};

function _closeSlide(event) {
if ($(event)[0].button != 2 && $("#pageslide-slide-wrap").css('width') != "0px") { // if not right click.
$.fn.pageSlideClose(settings);
}
};

// this is used to activate the modal blanket, if the modal setting is defined as true.
function _showBlanket() {
if(settings.modal == true) {
$("#pageslide-blanket").toggle().animate({opacity:'0.3'}, 'fast','linear');
}
};

// fixes an annoying horizontal scrollbar.
function _overflowFixAdd(){($.browser.msie) ? $("body, html").css({overflowX:'hidden'}) : $("body").css({overflowX:'hidden'});}

// Initalize pageslide, if it hasn't already been done.
_initialize(this);
return this.each(function(){
$(this).unbind("click").bind("click", function(){
_openSlide(this);
$("#pageslide-slide-wrap").unbind('click').click(function(e){ if(e.target.tagName != "A") return false; });	  
if (settings.modal != true) {
$(document).unbind('click').click(function(e) { if(e.target.tagName != "A"){ _closeSlide(e); return false } });
}
return false;
});	
});

};
})(jQuery);

// pageSlideClose allows the system to automatically close any pageslide that is currently open in the view.
(function($){
$.fn.pageSlideClose = function(options) {

var settings = $.extend({
width:          "300px", // Accepts fixed widths
duration:       "normal", // Accepts standard jQuery effects speeds (i.e. fast, normal or milliseconds)
direction:      "left", // default direction is left.
modal:          false, // if true, the only way to close the pageslide is to define an explicit close class. 
_identifier: $(this)
}, options);

function _hideBlanket() { if(settings.modal == true && $("#pageslide-blanket").is(":visible")) {
$("#pageslide-blanket").animate({opacity:'0.0'}, 'fast','linear',function(){$(this).hide();});
}}

function _overflowFixRemove(){($.browser.msie) ? $("body, html").css({overflowX:''}) : $("body").css({overflowX:''});}

_hideBlanket();
direction = ($("#pageslide-slide-wrap").css("left") != "0px") ? {left: "0"} : {right: "0"};
$("#pageslide-body-wrap").animate(direction, settings.duration);
$("#pageslide-slide-wrap").animate({width: "0"}, settings.duration, function() {
// clear bug
$("#pageslide-content").css("width","0px").empty();
$('#pageslide-body-wrap, #pageslide-slide-wrap').css('left','');
$('#pageslide-body-wrap, #pageslide-slide-wrap').css('right','');
_overflowFixRemove();
});

}
})(jQuery);

// this adds the ability to close pageSlide with the 'escape' key, if not modal.
(function($){
$(document).ready(function(){
$(document).keyup(function(event){
if (!$("#pageslide-blanket").is(":visible") && event.keyCode == 27) $.fn.pageSlideClose();
});
});
})(jQuery);

jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend( jQuery.easing,
{
def: 'easeOutQuad',
swing: function (x, t, b, c, d) {
//alert(jQuery.easing.default);
return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
},
easeInQuad: function (x, t, b, c, d) {
return c*(t/=d)*t + b;
},
easeOutQuad: function (x, t, b, c, d) {
return -c *(t/=d)*(t-2) + b;
},
easeInOutQuad: 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;
},
easeInCubic: function (x, t, b, c, d) {
return c*(t/=d)*t*t + b;
},
easeOutCubic: function (x, t, b, c, d) {
return c*((t=t/d-1)*t*t + 1) + b;
},
easeInOutCubic: function (x, t, b, c, d) {
if ((t/=d/2) < 1) return c/2*t*t*t + b;
return c/2*((t-=2)*t*t + 2) + b;
},
easeInQuart: function (x, t, b, c, d) {
return c*(t/=d)*t*t*t + b;
},
easeOutQuart: function (x, t, b, c, d) {
return -c * ((t=t/d-1)*t*t*t - 1) + b;
},
easeInOutQuart: function (x, t, b, c, d) {
if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
return -c/2 * ((t-=2)*t*t*t - 2) + b;
},
easeInQuint: function (x, t, b, c, d) {
return c*(t/=d)*t*t*t*t + b;
},
easeOutQuint: function (x, t, b, c, d) {
return c*((t=t/d-1)*t*t*t*t + 1) + b;
},
easeInOutQuint: function (x, t, b, c, d) {
if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
return c/2*((t-=2)*t*t*t*t + 2) + b;
},
easeInSine: function (x, t, b, c, d) {
return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
},
easeOutSine: function (x, t, b, c, d) {
return c * Math.sin(t/d * (Math.PI/2)) + b;
},
easeInOutSine: function (x, t, b, c, d) {
return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
},
easeInExpo: function (x, t, b, c, d) {
return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
},
easeOutExpo: function (x, t, b, c, d) {
return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
},
easeInOutExpo: function (x, t, b, c, d) {
if (t==0) return b;
if (t==d) return b+c;
if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
},
easeInCirc: function (x, t, b, c, d) {
return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
},
easeOutCirc: function (x, t, b, c, d) {
return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
},
easeInOutCirc: function (x, t, b, c, d) {
if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
},
easeInElastic: function (x, t, b, c, d) {
var s=1.70158;var p=0;var a=c;
if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
if (a < Math.abs(c)) { a=c; var s=p/4; }
else var s = p/(2*Math.PI) * Math.asin (c/a);
return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
},
easeOutElastic: function (x, t, b, c, d) {
var s=1.70158;var p=0;var a=c;
if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
if (a < Math.abs(c)) { a=c; var s=p/4; }
else var s = p/(2*Math.PI) * Math.asin (c/a);
return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
},
easeInOutElastic: function (x, t, b, c, d) {
var s=1.70158;var p=0;var a=c;
if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
if (a < Math.abs(c)) { a=c; var s=p/4; }
else var s = p/(2*Math.PI) * Math.asin (c/a);
if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
},
easeInBack: function (x, t, b, c, d, s) {
if (s == undefined) s = 1.70158;
return c*(t/=d)*t*((s+1)*t - s) + b;
},
easeOutBack: function (x, t, b, c, d, s) {
if (s == undefined) s = 1.70158;
return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
},
easeInOutBack: function (x, t, b, c, d, s) {
if (s == undefined) s = 1.70158; 
if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
},
easeInBounce: function (x, t, b, c, d) {
return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
},
easeOutBounce: function (x, t, b, c, d) {
if ((t/=d) < (1/2.75)) {
return c*(7.5625*t*t) + b;
} else if (t < (2/2.75)) {
return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
} else if (t < (2.5/2.75)) {
return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
} else {
return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
}
},
easeInOutBounce: function (x, t, b, c, d) {
if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
}
});

$(function() {
$('a').bind('click',function(event){
var $anchor = $(this);
$('html, body').stop().animate({
scrollTop: $($anchor.attr('href')).offset().top
}, 2000,'easeInOutExpo');
event.preventDefault();
});
});
