(function($){
	
// Create scrollLeft and scrollTop methods
$.each( ['Left', 'Top'], function(i, name) {
	$.fn[ 'scroll' + name ] = function(val) {
		if (!this[0]) return;
		
		return val != undefined ?
		
			// Set the scroll offset
			this.each(function() {
				this == window || this == document ?
					window.scrollTo( 
						name == 'Left' ? val : $(window)[ 'scrollLeft' ](),
						name == 'Top'  ? val : $(window)[ 'scrollTop'  ]()
					) :
					this[ 'scroll' + name ] = val;
			}) :
			
			// Return the scroll offset
			this[0] == window || this[0] == document ?
				self[ (name == 'Left' ? 'pageXOffset' : 'pageYOffset') ] ||
					$.boxModel && document.documentElement[ 'scroll' + name ] ||
					document.body[ 'scroll' + name ] :
				this[0][ 'scroll' + name ];
	};
});

$.fn.extend({
	position: function() {
		var left = 0, top = 0, elem = this[0], offset, parentOffset, offsetParent, results;
		
		if (elem) {
			// Get *real* offsetParent
			offsetParent = this.offsetParent();
			
			// Get correct offsets
			offset       = this.offset();
			parentOffset = offsetParent.offset();
			
			// Subtract element margins
			offset.top  -= num(elem, 'marginTop');
			offset.left -= num(elem, 'marginLeft');
			
			// Add offsetParent borders
			parentOffset.top  += num(offsetParent, 'borderTopWidth');
			parentOffset.left += num(offsetParent, 'borderLeftWidth');
			
			// Subtract the two offsets
			results = {
				top:  offset.top  - parentOffset.top,
				left: offset.left - parentOffset.left
			};
		}
		
		return results;
	},
	
	offsetParent: function() {
		var offsetParent = this[0].offsetParent;
		while ( offsetParent && (!/^body|html$/i.test(offsetParent.tagName) && $.css(offsetParent, 'position') == 'static') )
			offsetParent = offsetParent.offsetParent;
		return $(offsetParent);
	}
});

function num(el, prop) {
	return parseInt($.css(el.jquery?el[0]:el,prop))||0;
};

})(jQuery);

;(function($) {
	
// If the UI scope is not available, add it
$.ui = $.ui || {};

$.fn.extend({
	accordion: function(options, data) {
		var args = Array.prototype.slice.call(arguments, 1);

		return this.each(function() {
			if (typeof options == "string") {
				var accordion = $.data(this, "ui-accordion");
				accordion[options].apply(accordion, args);
			// INIT with optional options
			} else if (!$(this).is(".ui-accordion"))
				$.data(this, "ui-accordion", new $.ui.accordion(this, options));
		});
	},
	// deprecated, use accordion("activate", index) instead
	activate: function(index) {
		return this.accordion("activate", index);
	}
});

$.ui.accordion = function(container, options) {
	
	// setup configuration
	this.options = options = $.extend({}, $.ui.accordion.defaults, options);
	this.element = container;
	
	$(container).addClass("ui-accordion");
	
	if ( options.navigation ) {
		var current = $(container).find("a").filter(options.navigationFilter);
		if ( current.length ) {
			if ( current.filter(options.header).length ) {
				options.active = current;
			} else {
				options.active = current.parent().parent().prev();
				current.addClass("current");
			}
		}
	}
	
	// calculate active if not specified, using the first header
	options.headers = $(container).find(options.header);
	options.active = findActive(options.headers, options.active);

	if ( options.fillSpace ) {
		var maxHeight = $(container).parent().height();
		options.headers.each(function() {
			maxHeight -= $(this).outerHeight();
		});
		var maxPadding = 0;
		options.headers.next().each(function() {
			maxPadding = Math.max(maxPadding, $(this).innerHeight() - $(this).height());
		}).height(maxHeight - maxPadding);
	} else if ( options.autoheight ) {
		var maxHeight = 0;
		options.headers.next().each(function() {
			maxHeight = Math.max(maxHeight, $(this).outerHeight());
		}).height(maxHeight);
	}

	options.headers
		.not(options.active || "")
		.next()
		.hide();
	options.active.parent().andSelf().addClass(options.selectedClass);
	
	if (options.event)
		$(container).bind((options.event) + ".ui-accordion", clickHandler);
};

$.ui.accordion.prototype = {
	activate: function(index) {
		// call clickHandler with custom event
		clickHandler.call(this.element, {
			target: findActive( this.options.headers, index )[0]
		});
	},
	
	enable: function() {
		this.options.disabled = false;
	},
	disable: function() {
		this.options.disabled = true;
	},
	destroy: function() {
		this.options.headers.next().css("display", "");
		if ( this.options.fillSpace || this.options.autoheight ) {
			this.options.headers.next().css("height", "");
		}
		$.removeData(this.element, "ui-accordion");
		$(this.element).removeClass("ui-accordion").unbind(".ui-accordion");
	}
}

function scopeCallback(callback, scope) {
	return function() {
		return callback.apply(scope, arguments);
	};
}

function completed(cancel) {
	// if removed while animated data can be empty
	if (!$.data(this, "ui-accordion"))
		return;
	var instance = $.data(this, "ui-accordion");
	var options = instance.options;
	options.running = cancel ? 0 : --options.running;
	if ( options.running )
		return;
	if ( options.clearStyle ) {
		options.toShow.add(options.toHide).css({
			height: "",
			overflow: ""
		});
	}
	$(this).triggerHandler("change.ui-accordion", [options.data], options.change);
}

function toggle(toShow, toHide, data, clickedActive, down) {
	var options = $.data(this, "ui-accordion").options;
	options.toShow = toShow;
	options.toHide = toHide;
	options.data = data;
	var complete = scopeCallback(completed, this);
	
	// count elements to animate
	options.running = toHide.size() == 0 ? toShow.size() : toHide.size();
	
	if ( options.animated ) {
		if ( !options.alwaysOpen && clickedActive ) {
			$.ui.accordion.animations[options.animated]({
				toShow: jQuery([]),
				toHide: toHide,
				complete: complete,
				down: down,
				autoheight: options.autoheight
			});
		} else {
			$.ui.accordion.animations[options.animated]({
				toShow: toShow,
				toHide: toHide,
				complete: complete,
				down: down,
				autoheight: options.autoheight
			});
		}
	} else {
		if ( !options.alwaysOpen && clickedActive ) {
			toShow.toggle();
		} else {
			toHide.hide();
			toShow.show();
		}
		complete(true);
	}
}

function clickHandler(event) {
	var options = $.data(this, "ui-accordion").options;
	if (options.disabled)
		return false;
	
	// called only when using activate(false) to close all parts programmatically
	if ( !event.target && !options.alwaysOpen ) {
		options.active.parent().andSelf().toggleClass(options.selectedClass);
		var toHide = options.active.next(),
			data = {
				instance: this,
				options: options,
				newHeader: jQuery([]),
				oldHeader: options.active,
				newContent: jQuery([]),
				oldContent: toHide
			},
			toShow = options.active = $([]);
		toggle.call(this, toShow, toHide, data );
		return false;
	}
	// get the click target
	var clicked = $(event.target);
	
	// due to the event delegation model, we have to check if one
	// of the parent elements is our actual header, and find that
	if ( clicked.parents(options.header).length )
		while ( !clicked.is(options.header) )
			clicked = clicked.parent();
	
	var clickedActive = clicked[0] == options.active[0];
	
	// if animations are still active, or the active header is the target, ignore click
	if (options.running || (options.alwaysOpen && clickedActive))
		return false;
	if (!clicked.is(options.header))
		return;

	// switch classes
	options.active.parent().andSelf().toggleClass(options.selectedClass);
	if ( !clickedActive ) {
		clicked.parent().andSelf().addClass(options.selectedClass);
	}

	// find elements to show and hide
	var toShow = clicked.next(),
		toHide = options.active.next(),
		//data = [clicked, options.active, toShow, toHide],
		data = {
			instance: this,
			options: options,
			newHeader: clicked,
			oldHeader: options.active,
			newContent: toShow,
			oldContent: toHide
		},
		down = options.headers.index( options.active[0] ) > options.headers.index( clicked[0] );
	
	options.active = clickedActive ? $([]) : clicked;
	toggle.call(this, toShow, toHide, data, clickedActive, down );

	return false;
};

function findActive(headers, selector) {
	return selector != undefined
		? typeof selector == "number"
			? headers.filter(":eq(" + selector + ")")
			: headers.not(headers.not(selector))
		: selector === false
			? $([])
			: headers.filter(":eq(0)");
}

$.extend($.ui.accordion, {
	defaults: {
		selectedClass: "selected",
		alwaysOpen: true,
		animated: 'slide',
		event: "click",
		header: "a",
		autoheight: true,
		running: 0,
		navigationFilter: function() {
			return this.href.toLowerCase() == location.href.toLowerCase();
		}
	},
	animations: {
		slide: function(options, additions) {
			options = $.extend({
				easing: "swing",
				duration: 300
			}, options, additions);
			if ( !options.toHide.size() ) {
				options.toShow.animate({height: "show"}, options);
				return;
			}
			var hideHeight = options.toHide.height(),
				showHeight = options.toShow.height(),
				difference = showHeight / hideHeight;
			options.toShow.css({ height: 0, overflow: 'hidden' }).show();
			options.toHide.filter(":hidden").each(options.complete).end().filter(":visible").animate({height:"hide"},{
				step: function(now) {
					var current = (hideHeight - now) * difference;
					if ($.browser.msie || $.browser.opera) {
						current = Math.ceil(current);
					}
					options.toShow.height( current );
				},
				duration: options.duration,
				easing: options.easing,
				complete: function() {
					if ( !options.autoheight ) {
						options.toShow.css("height", "auto");
					}
					options.complete();
				}
			});
		},
		bounceslide: function(options) {
			this.slide(options, {
				easing: options.down ? "bounceout" : "swing",
				duration: options.down ? 1000 : 200
			});
		},
		easeslide: function(options) {
			this.slide(options, {
				easing: "easeinout",
				duration: 700
			})
		}
	}
});

})(jQuery);


// esconder div

function showhidee(id){
   if (document.getElementById){
   obj = document.getElementById(id);
   if (obj.style.display == "none"){
     obj.style.display = "";
   } else {
     obj.style.display = "none";
   }
 }
}

// paginacao comentario
function ajax(url)
{

req = null;

if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
req.onreadystatechange = processReqChange;
req.open("GET",url,true);
req.send(null);

} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {

req.onreadystatechange = processReqChange;
req.open("GET",url,true);

req.send();
}
}
}

function processReqChange()
{
if (req.readyState == 1) {
document.getElementById('pagina').innerHTML = 'Carregando, por favor aguarde...';
}


else if (req.readyState == 4) {


if (req.status ==200) {
document.getElementById('pagina').innerHTML = req.responseText;
} else {
alert("Houve um problema ao obter os dados:n" + req.statusText);
}
}
}


// fim paginacao comentario

var $ = jQuery.noConflict();

$(window).load(function() {
						

    // ***************** FOR DEVELOPMENT VERSION ONLY
    var string = "";

    string = ""
    $('head').append(string);
      
    string = ""

    $('#top').prepend(string);

    /******************************************
        STYLESHEET TOGGLER
    ******************************************/
    /*Stylesheet toggle variation on styleswitch stylesheet switcher.
    Built on jQuery.
    Under an CC Attribution, Share Alike License.
    By Kelvin Luck ( http://www.kelvinluck.com/ )*/
    (function($){
        $(document).ready(function(){
				$.featureList(
				$("#tabs li a"),
				$("#output li"), {
					start_item	:	0
				}
				);				   
								   
            $('.styleswitch').click(function(){
                switchStylestyle(this.getAttribute("rel"));
                loadCufonNivo();
                return false
            });
            var c=readCookie('style');
            if(c)switchStylestyle(c)
        });
        function switchStylestyle(styleName){
            $('link[@rel*=style][title]').each(function(i){
                this.disabled=true;
                if(this.getAttribute('title')==styleName)this.disabled=false
            });
            createCookie('style',styleName,365)
        }
    })(jQuery);
    function createCookie(name,value,days){
        if(days){
            var date=new Date();
            date.setTime(date.getTime()+(days*24*60*60*1000));
            var expires="; expires="+date.toGMTString()
        }else var expires="";
        document.cookie=name+"="+value+expires+"; path=/"
    }
    function readCookie(name){
        var nameEQ=name+"=";
        var ca=document.cookie.split(';');
        for(var i=0;i<ca.length;i++){
            var c=ca[i];
            while(c.charAt(0)==' ')c=c.substring(1,c.length);
            if(c.indexOf(nameEQ)==0)return c.substring(nameEQ.length,c.length)
        }
        return null
    }
    function eraseCookie(name){
        createCookie(name,"",-1)
    }
    
    /***********************************************************************************************
     ************************************************************************************************/

    /******************************************
    ELEMENTS APPENDING
    ******************************************/

    /******************************************
    BACKGROUND FOR THE SCORLLABLE COMPONENT
     ******************************************/
   // $('.scrollable_widget').append("<span class='scrollable_body'><img alt='' src='img/layout/scrollable_body.png'/></span>");

    /******************************************
    BORDER FOR THE FEATURED SLIDER
    ******************************************/
    $('#featured .wrap').append("<span class='slider_border_bottom'/>");

    /******************************************
    CLASS FOR THE CAPTION HEADERS
     ******************************************/
    $('.caption h1, .caption h2, .caption h3, .caption h4, .caption h5, .caption h6').addClass('caption_title');

    /******************************************
    CLEARING DIVS
     ******************************************/
    $('ul.post_list li').append("<div class='clear'></div>");
    $('ul.comment_list li').append("<div class='clear'></div>");
    $('ul.advertising_list').append("<div class='clear'></div>");
    $('.tabs').after("<div class='clear'></div>");

    /******************************************
    DIVIDERS
     ******************************************/
    $('#teaser .scrollable_widget').after("<div class='hr blank'></div>")
    $('.post_entry').after('<!-- DIVIDER --><div class="hr blank"></div>');
    $('.paging').before('<!-- DIVIDER --><div class="hr"></div>');
    $('#main .wrap').append('<!-- DIVIDER --><div class="hr"></div>');
 
   
    /******************************************
    VERTICAL SCROLLER NAV BUTTONS
    ******************************************/
    string= "<!-- NAV BUTTON FOR THE SCROLLER -->" +
    "<div class='actions'>" +
    "<a class='prev'></a>" +
    "<a class='next'></a>" +
    "</div><!-- End .actions -->";
    $('.scrollable_vertical').before(string);

    
    /******************************************
             TABS
     *****************************************/
    //Add new effect('show') to the tabs (FOR IE)
    $.tools.tabs.addEffect("show", function(i, done) {
        this.getPanes().hide();
        this.getPanes().eq(i).show();
        done.call();
    });
    //If not IE...
    if ($.support.opacity){
        $("ul.tabs").tabs("div.panes > div", {
            effect: 'fade'
        });
    } else {
        $("ul.tabs").tabs("div.panes > div", {
            effect: 'show'
        });
    }
    $("#social.has_tooltips img[title]").tooltip({
        // name of the class
        tipClass: 'small_tooltip',
        // tweak the position
        offset: [-2, 4],
        // use the "slide" effect
        effect: 'slide'
    });
   
    $("div.scrollable").scrollable({
        speed: 500
    });

    
    $("div.scrollable_vertical:not(.tweets)").scrollable({
        vertical: true,
        //support for mousewheel
        mousewheel: false
    }).autoscroll({
        autoplay: false,
        interval: 3000
    });

     var no_items = $('ul#nav > li').size();
     $('ul#nav').css({'width':no_items*82})

    $('a[href=#topo]').click(function(){
        //If Safari or Chrome...
        if ($.browser.webkit) {
            $('body').animate({
                scrollTop:0
            }, 'slow');
            return false;
        } else {
            $('html').animate({
                scrollTop:0
            }, 'slow');
            return false;
        }
    });
});
