$(document).ready(function() {

	$('#middle').hide();

	$("#contato").click(function(){
		$('#middle').slideToggle(600);
		return false
	});

	$("#mute").click(function(){
		if ($(this).hasClass('videoMute')) {
			;ytplayer.unMute();
			$(this).removeClass('videoMute');
		} else {
			ytplayer.mute()
			$(this).addClass('videoMute');
		}
		return false;
	});

	$(".logo").hover(function(){
		$(this).stop(true, true).animate({
			paddingBottom:'+=10px'
		}, 500);
	},function(){
		$(this).stop(true, true).animate({
			paddingBottom:'-=10px'
		}, 500);
	});

	$("ul").each(function(){
		$(this).find("li:first").addClass('first');
		$(this).find("li:even").addClass('even');
		$(this).find("li:odd").addClass('odd');
		$(this).find("li:last").addClass('last');
	});

	$('#bg').height($(window).height());
	$('#player').tubular('1A6HN6L8CpQ','wrapper');

});

$(window).resize(function() {
	$('#bg').height($(window).height());
	resizePlayer();
});

$(window).load(function() {
	$('#nav li a').hoverwords({delay:50});
});

(function($){$.browserTest=function(a,z){var u='unknown',x='X',m=function(r,h){for(var i=0;i<h.length;i=i+1){r=r.replace(h[i][0],h[i][1]);}return r;},c=function(i,a,b,c){var r={name:m((a.exec(i)||[u,u])[1],b)};r[r.name]=true;r.version=(c.exec(i)||[x,x,x,x])[3];if(r.name.match(/safari/)&&r.version>400){r.version='2.0';}if(r.name==='presto'){r.version=($.browser.version>9.27)?'futhark':'linear_b';}r.versionNumber=parseFloat(r.version,10)||0;r.versionX=(r.version!==x)?(r.version+'').substr(0,1):x;r.className=r.name+r.versionX;return r;};a=(a.match(/Opera|Navigator|Minefield|KHTML|Chrome/)?m(a,[[/(Firefox|MSIE|KHTML,\slike\sGecko|Konqueror)/,''],['Chrome Safari','Chrome'],['KHTML','Konqueror'],['Minefield','Firefox'],['Navigator','Netscape']]):a).toLowerCase();$.browser=$.extend((!z)?$.browser:{},c(a,/(camino|chrome|firefox|netscape|konqueror|lynx|msie|opera|safari)/,[],/(camino|chrome|firefox|netscape|netscape6|opera|version|konqueror|lynx|msie|safari)(\/|\s)([a-z0-9\.\+]*?)(\;|dev|rel|\s|$)/));$.layout=c(a,/(gecko|konqueror|msie|opera|webkit)/,[['konqueror','khtml'],['msie','trident'],['opera','presto']],/(applewebkit|rv|konqueror|msie)(\:|\/|\s)([a-z0-9\.]*?)(\;|\)|\s)/);$.os={name:(/(win|mac|linux|sunos|solaris|iphone)/.exec(navigator.platform.toLowerCase())||[u])[0].replace('sunos','solaris')};if(!z){$('html').addClass([$.os.name,$.browser.name,$.browser.className,$.layout.name,$.layout.className].join(' '));}};$.browserTest(navigator.userAgent);})(jQuery);

/* jQuery tubular plugin
|* by Sean McCambridge custom by Lucas Sanchez
|* http://www.seanmccambridge.com/tubular
|* Copyright 2010
|* licensed under the MIT License
|* Do not remove this copyright notice
|* Enjoy.
|* 
|* Thanks,
|* Sean */


// set params
var videoWidth = $(window).width();
var videoRatio = 16/9; // either 4/3 or 16/9


jQuery.fn.tubular = function(videoId,wrapperId) {
	t = setTimeout("resizePlayer()",1000);
	jQuery('#player').prepend('<div id="yt-container" style="overflow: hidden; position: fixed; z-index: 1;"><div id="ytapiplayer">You need Flash player 8+ and JavaScript enabled to view this video.</div></div><div id="video-cover" style="position: fixed; width: 100%; height: 100%; z-index: 2;"></div>');
	jQuery('#' + wrapperId).css({position: 'relative', 'z-index': 99});
	
	// initiailize vars
	var ytplayer = 0;
	var pageWidth = 0;
	var pageHeight = 0;
	var videoHeight = (videoWidth / videoRatio) + 27;
	var duration;
	
	// swfobject embed yt player
	var params = { allowScriptAccess: "always", wmode: "transparent" };
	var atts = { id: "myytplayer" };
	swfobject.embedSWF("http://www.youtube.com/v/" + videoId + "?enablejsapi=1&playerapiid=ytplayer&loop=1", "ytapiplayer", videoWidth, videoHeight, "8", null, null, params, atts);
	
	return this;
}


// player calls this function on ready
function onYouTubePlayerReady(playerId) {
	ytplayer = document.getElementById("myytplayer");
	ytplayer.setPlaybackQuality('medium');
	//ytplayer.mute();
}


function resizePlayer() {
	var newWidth = jQuery(window).width(); // original page width
	var newHeight = jQuery(window).height() + 27; // original page height
	jQuery('#yt-container, #video-cover').width(newWidth).height(newHeight);
	if (newHeight > newWidth / videoRatio) { // if window ratio becomes taller than video
		newWidth = newHeight * videoRatio; // overflow video to sides instead of bottom
	}
	jQuery('#myytplayer').width(newWidth).height(newWidth/videoRatio);
}


