jQuery.fn.center = function () {
    this.css("position","absolute");
    this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
    this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
    return this;
}

$(document).ready(function(){

	$('#videoslideplaceholder').hide();
	
	if($(window).height() <= 700){
		$('#footer').css({
			position: 'absolute',
			bottom: 0,
			left: 0
		});
		$('#footerlayer').css({
			position: 'absolute',
			bottom: 0,
			left: 0
		});
	}else{
		$('#footer').css('position','fixed');
		$('#footerlayer').css('position','fixed');
	}
	
	// menu mouseover
	$('#top-menu li').bind('mouseenter',function(){
		$(this).addClass('visible');
		$('.submenu',this).show();
	}).bind('mouseleave',function(){
		$('.submenu',this).hide();
		$(this).removeClass('visible');
	});
	
	// agrega clase al ultimo li
	$('li:last-child').addClass('last-child');
	
	
	// Tabs en el contenido
	// Calculo el tamanio del contenedor wide
	var tabWidth = 537;
	var tabCount = $('.tab').length;
	var tabsWideW = tabWidth*tabCount;
	
	$('.it-wide').width(tabsWideW);
	
	$('.it-nav li a').bind('click',function(){
		if(!$(this).hasClass('link')){
			$('.it-nav li').removeClass('activo');
			$(this).parent().addClass('activo');
			
			var divId = $(this).attr('href');
			var divPos = $(divId).position();
				
			$('.int-tabs .tabs').animate({
				right: divPos.left
			});
			
			return false;	
		}
	})
	
	$(document).keyup(function(e){
		if ( e.which == 27 ) { 
			$('#playerContainer').fadeOut();
			$("#playeroverlay").fadeOut();
		}
	});
	
	$('.playerclose').bind('click',function(){
		$('#playerContainer').fadeOut();
		$("#playeroverlay").fadeOut();
	});

	$('#sliders').cycle({
		pager: '#mc-nav',
		delay: 15000,
		pause: 1
	});

	$('.videoslideclick').live('click',function(){
		$('#videoslideplaceholder').html('<iframe width="550" height="377" src="http://www.youtube.com/embed/BtUuwbif3O0?autoplay=1&rel=0" frameborder="0" allowfullscreen></iframe>');
		$('#videoslideplaceholder').show();

		$(this).hide();

		$('#slidevidtxt').hide();

		$('#sliders').cycle('destroy');

		setTimeout(function(){
			$('#videoslideplaceholder').hide();
			$('.videoslideclick').show();
			
			$('#sliders').cycle({
				pager: '#mc-nav',
				delay: 15000,
				pause: 1
			});

		},120000)

	});

});
