$(document).ready( function() {
	$('a[rel=external], .sponsors a, #fb-canvas .diary-ticker a').live('click', function() {
		
		window.open($(this).attr('href'), '_blank');
		return false;
	});
	
	
	$('.share-btn .share-img').live('click', function() {
		
		
		if(!$(this).parent('.share-btn').find('.addthis_toolbox').hasClass('open')) {
			$('.addthis_toolbox.open .close').trigger('click');
			if($.support.opacity) {
				$(this).parent('.share-btn').find('.addthis_toolbox').fadeIn(500);
			} else {
				$(this).parent('.share-btn').find('.addthis_toolbox').css('display', 'block');
			}
			$(this).parent('.share-btn').find('.addthis_toolbox').addClass('open');
		} else {
			$(this).parent('.share-btn').find('.close').trigger('click');
		}
		return false;
	});
			
	$('.share-btn .close').live('click', function() {
		
		if($.support.opacity) {
			$(this).parent('.addthis_toolbox').fadeOut(500);
		} else {
			$(this).parent('.addthis_toolbox').fadeOut(500).css('display', 'none');
		}
		
		$(this).parent('.addthis_toolbox').removeClass('open');
		return false;
	});
	
	
	
	$('a.yt').fancybox({
	
        //'title'     : this.title,
        'titleShow'		: false,
        'width'     : 853,
        'height'	: 510,
        'type'      : 'iframe'
    });
    
    $('.press-gallery ul li a').fancybox({
    });
    
    $('img.yt').parent('a').fancybox({
	
        //'title'     : this.title,
        'titleShow'		: false,
        'width'     : 560,
        'height'	: 349,
        'type'      : 'iframe'
    });
    
    $('#press-navigation li').each(function() {
    	
    	$(this).find('.press-navigation-arrow').css('left', ($(this).width()/2-7)+'px');
    });
    
    $('#press-navigation li a').click(function() {
    	$('#press-navigation li').removeClass('active');
    	$(this).parent('li').addClass('active');
    	$('#press-ajax').fadeOut(200);
    	$('#press-ajax').load($(this).attr('href')+' #press-ajax-container', function() {
    		$('#press-ajax').fadeIn(200);
    	});
    	
    	$(this).blur();
    	
   		return false;
    });
    
    if($('#header-video').length > 0) {
    	$('#header-video').fadeIn(200);
    }
    
    $('#header-video-close-btn').click(function() {
    	$('#header-video').fadeOut(200);
    });
    
    $('#ticker li a img').animate({ opacity: 0.5 }, 0);
    
	$('#ticker li a').mouseover(function() {
		$(this).find('img').animate({ opacity: 1 }, 100);
	});
	
	$('#ticker li a').mouseleave(function() {
		$(this).find('img').animate({ opacity: 0.5 }, 100);
	});
	
	$('#fb-canvas .overlay').click(function() {
		$('#fb-canvas #canvas-video').append($('<iframe width="520" height="'+$(this).parent('div').height()+'" src="'+$(this).attr('href')+'?autoplay=1" frameborder="0" allowfullscreen></iframe>'));
		
		$(this).fadeOut(200);
		return false;
	});
	
	$('#fb-canvas .fb-kiters .small-label img').load(function() {
		$(this).parents('.small-label').css('left', (122/2-$(this).parents('.small-label').width()/2)+'px');
	});
    
});
