// JavaScript Document

	$(document).ready(function () {

	corre(1);
		
	/*	$('#carousel').jcarousel({
			vertical: true,
			initCallback: corre(1)
	   	});  */
 
	//Front page Carousel - Initial Setup
   	$('div#slideshow-carousel a img').css({'opacity': '1.0'});
   	$('div#slideshow-carousel a img:first').css({'opacity': '0.5'});
   	$('div#slideshow-carousel li a:first').append('<span class="arrow"></span>'); 
 
  
  	//Combine jCarousel with Image Display
    $('div#slideshow-carousel li a').hover(
       	function () {
        		
       		if (!$(this).has('span').length) {
        		$('div#slideshow-carousel li a img').stop(true, true).css({'opacity': '1.0'});
   	    		$(this).stop(true, true).children('img').css({'opacity': '0.5'});
				//alert(this);
       		}		
       	},
       	function () {
        		
       		$('div#slideshow-carousel li a img').stop(true, true).css({'opacity': '1.0'});
       		$('div#slideshow-carousel li a').each(function () {
 
       			if ($(this).has('span').length) $(this).children('img').css({'opacity': '0.5'});
 
       		});
        		
       	}
	).click(function () {
 
	    $('span.arrow').remove();        
		$(this).append('<span class="arrow"></span>');
       	$('div#slideshow-main li').removeClass('active'); 
		$('div#slideshow-main li').removeClass('video'); 
       	$('div#slideshow-main li.' + $(this).attr('rel')).addClass('active');	
        	
       	return false;
	});
 
 
});
 
 
//Carousel Tweaking

function voltaVideo(tela)
{
	$('div#slideshow-main li.p' + tela).removeClass('video');
}

function mostraVideo(tela)
{
	$('div#slideshow-main li.p' + tela).addClass('video');
	setTimeout("corre(2)",tempo);
}

function corre(cod)
{
	$('span.arrow').remove();
	
	var tempo = 8000;
	
	var div1 = $("div#slideshow-main li.p1").attr("class");
	var div2 = $("div#slideshow-main li.p2").attr("class");
	var div3 = $("div#slideshow-main li.p3").attr("class");
	
	if ( cod == 1 )
	{
		
		if ( div1 == "p1 active" )
		{
			transicao(1, 2);
		}
		else if ( div2 == "p2 active" )
		{
			transicao(2, 3);
		}
		else if ( div3 == "p3 active" )
		{
			transicao(3, 1);
		}
	
	setTimeout("corre(1)",tempo);
	}
	else
	{
		
	}
}

function transicao(antiga, nova)
{
	$('span.arrow').remove();$(".p" + antiga).append('<span class="arrow"></span>');
	$('div#slideshow-main li').removeClass('active');
	$('div#slideshow-main li.p' + nova).addClass('active');
	
	$('div#slideshow-carousel li a img').stop(true, true).css({'opacity': '1.0'});
   	$('#p' + nova).stop(true, true).children('img').css({'opacity': '0.5'});
}


 
function mycarousel_initCallback(carousel) {
	
	// Pause autoscrolling if the user moves with the cursor over the clip.
	carousel.clip.hover(function() {
		carousel.stopAuto();
	}, function() {
		carousel.startAuto();
	});
}


/* FUNÇÃO PARA O FLICKR */
function flickr(user){
	$.getJSON('http://api.flickr.com/services/feeds/photos_public.gne?id='+user+'&format=json&jsoncallback=?', function(data){
		for(i=0; i<9; i++){
			$("<img />").attr("src", data.items[i].media.m).appendTo("#flickr").wrap("<div class='imgBox'><a href='" + data.items[i].link + "' title='" + data.items[i].title + "' target='_blank'><\/a></div>");
		}
	});
}
