$(document).ready(function(){
	
	//Cufon
//	Cufon.replace('#menu li', { hover: 'true' });
//	Cufon.replace('#content h1, #content h2, #content h3', { hover: 'true' });
//	Cufon.replace('a._boton', { hover: 'true' });	
	
	//lightbox	
//	$("a[rel=lightbox]").prettyPhoto();
//	$("a[rel^='lightbox']").prettyPhoto();// {theme:'light_rounded'} );
	
	//hover en pie
	$("#ft ul li").hover(function() {
		$(this).animate({opacity: "1"}, "fast");
	}, function() {
		$(this).animate({opacity: "0.5"}, "fast");
	});
	$("#ft ul li").css({opacity: '0.5'}, 1);
	
	//hover en galerías
	$(".fotoThumb").hover(function() {
		$(this).animate({opacity: "1"}, "fast");
	}, function() {
		$(this).animate({opacity: "0.6"}, "fast");
	});
 	$(".fotoThumb").css({opacity: '0.6'}, 1);
	
	//hover en sponsors
	$(".sponsorThumb").hover(function() {
		$(this).animate({opacity: "1"}, "fast");
	}, function() {
		$(this).animate({opacity: "0.6"}, "fast");
	});
	$(".sponsorThumb").css({opacity: "0.6"}, 1);

	//hover en footer
	$("#ft img").hover(function() {
		$(this).animate({opacity: "1"}, "fast");
	}, function() {
		$(this).animate({opacity: "0.6"}, "fast");
	});
	$("#ft img").css({opacity: "0.6"}, 1);


	var summerFest = new Date( '2011', 8, 18,10,0,0);
	$('#countdown').countdown({
		until: summerFest,
		compact: true, 
	    layout: '<div class="i{d10}"></div><div class="i{d1}"></div>' + 
	        //'<div class="iDay"></div>'*/ + 
	        '<div class="iSpace"></div>' + 
	        '<div class="i{h10}"></div><div class="i{h1}"></div>' + 
	        '<div class="iSep"></div>' + 
	        '<div class="i{m10}"></div><div class="i{m1}"></div>' + 
	        '<div class="iSep"></div>' + 
	        '<div class="i{s10}"></div><div class="i{s1}"></div>'
	});

	//hover en artistas
	$(".artistas li").hover(function() {
		$(this).find('h3').animate({bottom: "0"}, "fast");
	}, function() {
		$(this).find('h3').animate({bottom: 0}, 1000).animate({bottom: "-40px"}, "slow");
	});
	
	
	//Widget Twitter
	twitterWidget.render().start();
	
	//Banner slideshow
	rotateBanners();
});


$('#facebookWidget').html('<fb:like-box href="http://www.facebook.com/matineesummerfestival" header="0" stream="0" connections="5" width="296" height="202" colorscheme="light"></fb:like-box>');


//TWITTER
var twitterWidget = new TWTR.Widget({
	id: 'twitterWidget',
	version: 2,
	type: 'search',
	search: 'matineegroup',
	interval: 2000,
	title: (locale=='es' ? 'El festival del verano' : 'The Festival of the summer'),
	subject: 'Matinée Summer Festival',
	width: 290,
	height: 122,
	theme: {
		shell: {
			background: 'transparent'/*'#280835'*/, color: '#ffffff'
		},
		tweets: {
			background: '#FFF', color: '#7a7a7a', links: '#0090d2'
		}
	},
	features: {
		scrollbar: true,
		loop: true,
		live: true,
		hashtags: true,
		timestamp: true,
		avatars: true,
		toptweets: true,
		behavior: 'default'
	}
});

function rotateBanners() {
	//Set the opacity of all images to 0
	$('div#rotator ul li').css({opacity: 0.0});
	
	//Get the first image and display it (gets set to full opacity)
	$('div#rotator ul li:first').css({opacity: 1.0});
		
	
	var imgs = $('div#rotator ul li').size();
	if(imgs > 1){
       //Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
        setInterval('rotate()',6000);
	}
}

function rotate() {	
	//Get the first image
	var current = ($('div#rotator ul li.show') ?  $('div#rotator ul li.show') : $('div#rotator ul li:first'));

	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#rotator ul li:first') :current.next()) : $('div#rotator ul li:first'));	
	
	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	
};
