jQuery(document).ready(function($){
	$("a[rel=lightbox]").lightBox();
	$("#main").pngFix();
	$("#footer div.container div:first").css("border","none");
	$("#slider").easySlider({ auto: true, continuous: true, numeric: true});
	$("#pslider").easySlider({ auto: true, continuous: true, numeric: false, controlsShow: false});
	$('div.online-expande> div').hide();
	$('div.online-expande> h3').click(function() {
		var $nextDiv = $(this).next();
		var $visibleSiblings = $nextDiv.siblings('div:visible');
		if ($visibleSiblings.length ) {
			$visibleSiblings.slideUp('slow', function() {
				$nextDiv.slideToggle('slow');
			});
		} else {
			$nextDiv.slideToggle('slow');
		}
	});
	var tabContainers = $('div.tabs > div');
	tabContainers.hide().filter(':first').show();
	$('div.tabs ul.tabNavigation a').click(function () {
			tabContainers.hide();
			tabContainers.filter(this.hash).show();
			$('div.tabs ul.tabNavigation a').removeClass('selected');
			$(this).addClass('selected');
			return false;
	}).filter(':first').click();
	$(".onlineslider").click(function(event){
		event.preventDefault();
		var urlCompleta = this.href;
		var partes = urlCompleta.split("#");
		var destino = partes[1];
		var destinoOffset = $("#"+destino).offset();
		var destinoTop = destinoOffset.top;
		$('html, body').animate({scrollTop:destinoTop}, 2000);
	});
    $('#mycarousel').jcarousel({
        scroll: 1,
		auto: 4,
        wrap: 'last',
        initCallback: mycarousel_initCallback,
        itemLoadCallback: mycarousel_itemLoadCallback
    });
}); //End jQuery.fn($)

/*
 * Alterar o tamanho das fontes
 * versao: 1.3
 * <param name="trgt">Elemnto (ID) CSS que receberá a açao.</param>
 * <param name="inc">Inteiro (signed int) com a variaçao para alterar o tamanho.</param>
 */
var tgs = new Array(  'a', 'abbr', 'address', 'area', 'base', 'basefont', 'bdo', 'blockquote', 'button', 'caption', 'center', 'cite', 'code', 'col', 'colgroup', 'dd', 'div', 'dl', 'dt', 'em', 'fieldset', 'form', 'frame', 'frameset', 'hr', 'i', 'iframe', 'input', 'ins', 'isindex', 'label', 'legend', 'li', 'link', 'map', 'ol', 'optgroup',  'option', 'p', 'param', 'pre', 'q', 's', 'samp', 'select', 'span', 'strike', 'sub', 'sup', 'table', 'tbody', 'td', 'textarea', 'tfoot', 'th', 'tr', 'tt', 'u', 'ul', 'b', 'strong', 'small', 'big', 'h1', 'h2', 'h3', 'h4',  'h5', 'h6', 'small', 'big' );
var szs = new Array( '9px','10px','11px','12px','14px','16px','18px','24px', '36px', '48px' );
var startSz = 3;
function ts( trgt, inc ) {
	if (!document.getElementById) return
	var d = document,cEl = null,sz = startSz,i,j,cTags;
	sz += inc;
	if ( sz < 0 ) sz = 0;
	if ( sz > 9 ) sz = 9;
	startSz = sz;
	if ( !( cEl = d.getElementById( trgt ) ) ) cEl = d.getElementsByTagName( trgt )[ 0 ];
	cEl.style.fontSize = szs[ sz ];
	for ( i = 0; i < tgs.length; i++ ) {
		cTags = cEl.getElementsByTagName( tgs[ i ] );
		for ( j = 0; j < cTags.length; j++ ) cTags[ j ].style.fontSize = szs[ sz ];
	}
}

/*
 * Abrir janelas pop-up
 * versao: 2.0
 * <param name="theURL">URI do destino.</param>
 * <param name="winName">Nome da janela que será aberta.</param>
 * <param name="features">Parâmetros opcionais.</param>
 */
function MM_openBrWindow(theURL,winName,features) {
  window.open(theURL,winName,features);
}

/* 
 * jCarousel
 * versao: 0.2.4 
 */
var mycarousel_tags = '';
function mycarousel_initCallback(carousel, state)
{
    // Do nothing of state is 'reset'
    if (state == 'reset')
        return;

    jQuery('form', carousel.container)
    .bind('submit', function(e) {
        mycarousel_tags = jQuery('input[@type=text]', carousel.container).val();
        carousel.reset();
        return false;
    });
};

function mycarousel_itemLoadCallback(carousel, state)
{
    // Only load items if they don't already exist
    if (carousel.has(carousel.first, carousel.last)) {
        return;
    }

    jQuery.get(
        'dynamic_flickr_feed.php',
        {
            tags: mycarousel_tags
        },
        function(data) {
            mycarousel_itemAddCallback(carousel, carousel.first, carousel.last, data);
        },
        'json'
    );
};

function mycarousel_itemAddCallback(carousel, first, last, data)
{
    if (first == 1) {
        var plural = data.length == 1 ? '' : 's';
        jQuery('.results', carousel.container).html(data.length + ' photo' + plural + ' found');

        // Set size
        if (data.length == 0) {
            // Add a "no results" feedback as first item if data is empty
            carousel.size(1);
            carousel.add(1, '<p>No results</p>');
            return;
        } else {
            carousel.size(data.length);
        }
    }

    for (var i = first; i <= last; i++) {
        if (data[i - 1] == undefined) {
            break;
        }

        carousel.add(i, mycarousel_decodeEntities(data[i - 1].description));
    }
};

function mycarousel_decodeEntities(s)
{
    return s.replace(/&amp;/g,  "&")
            .replace(/&quot;/g, '"')
            .replace(/&#039;/g, "'")
            .replace(/&lt;/g,   "<")
            .replace(/&gt;/g,   ">");
};

function jsonFlickrFeed(o)
{
    return o.items;
};

function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};
