// Feature news toggler on home page
function toggleShutter (e,w) {
	var eid = $(e).attr('id');
	// Fade out the excerpts and footers
	$('.home .news .item .excerpt, .home .news .item .footer').fadeOut(500);
	// Reset all news item widths to their collapsed values
	$('.home .news .item, .home .news .item .header').animate({ width: 188 },1000);
	// Run if clicked element is collapsing
	if (w > 188) {
		$(e).animate({ width: 188 },1000);
		$(e).find('.header').animate({ width: 188 },1000);
		$(e).find('.excerpt, .footer').fadeOut(3000);
	// Run if clicked element is expanding
	} else {
		if (eid == 'news_item_1' || eid == 'news_item_2') {
			$('#news_item_5').animate({ width: 0 },1000);
			$('#news_item_4').animate({ width: 0 },1000);
		}
		if (eid == 'news_item_3') {
			$('#news_item_1').animate({ width: 0 },1000);
			$('#news_item_5').animate({ width: 0 },1000);
		}
		if (eid == 'news_item_4' || eid == 'news_item_5') {
			$('#news_item_2').animate({ width: 0 },1000);
			$('#news_item_1').animate({ width: 0 },1000);
		}
		$(e).animate({ width: 564 },1000);
		$(e).find('.header').animate({ width: 367 }, 100, function(){ $(e).find('.excerpt, .footer').fadeIn(500); });
	}
}

$(document).ready(function(){
	// Make the army dropdown work on click/touch
	$('#header .nav .army ul').hide();
	$('#header .nav .army > a').click(function(){
		$('#header .nav .army ul').slideToggle('fast');
		return false;
	});
	
	$('#copyright').append('<a href="http://www.maccosmetics.com/" class="sponsor"><img src="/clients/blackveilbrides/img/sponsor-mac.png" alt="Make-up provided by MAC" /></a>')
	if(jQuery().social) {
	
		// Twitter accounts for home page
		$('.home #andy').social({
			network:'twitter',
			user:'andybvb',
			count:1,
			loadingText:'<p>Loading transmission &hellip;</p>',
			twitter:{output:'<span class="tweet">{text}</span> <span class="time">Posted <a href="{tweet_url}">{time}</a></span> <span class="username">Follow <a href="http://twitter.com/andybvb">@andybvb</a></span>'}
		});
	
		$('.home #jinxx').social({
			network:'twitter',
			user:'jinxxbvb',
			count:1,
			loadingText:'<p>Loading transmission &hellip;</p>',
			twitter:{output:'<span class="tweet">{text}</span> <span class="time">Posted <a href="{tweet_url}">{time}</a></span> <span class="username">Follow <a href="http://twitter.com/{user}">@{user}</a></span>'}
		});
	
		$('.home #ashley').social({
			network:'twitter',
			user:'ashleypurdy',
			count:1,
			loadingText:'<p>Loading transmission &hellip;</p>',
			twitter:{output:'<span class="tweet">{text}</span> <span class="time">Posted <a href="{tweet_url}">{time}</a></span> <span class="username">Follow <a href="http://twitter.com/{user}">@{user}</a></span>'}
		});
	
		$('.home #christian').social({
			network:'twitter',
			user:'ccbvb',
			count:1,
			loadingText:'<p>Loading transmission &hellip;</p>',
			twitter:{output:'<span class="tweet">{text}</span> <span class="time">Posted <a href="{tweet_url}">{time}</a></span> <span class="username">Follow <a href="http://twitter.com/{user}">@{user}</a></span>'}
		});
	
		$('.home #jake').social({
			network:'twitter',
			user:'jakepittsbvb',
			count:1,
			loadingText:'<p>Loading transmission &hellip;</p>',
			twitter:{output:'<span class="tweet">{text}</span> <span class="time">Posted <a href="{tweet_url}">{time}</a></span> <span class="username">Follow <a href="http://twitter.com/{user}">@{user}</a></span>'}
		});
	
		$('.home #bvb').social({
			network:'twitter',
			user:'OfficialBVB',
			count:1,
			loadingText:'<p>Loading transmission &hellip;</p>',
			twitter:{output:'<span class="tweet">{text}</span> <span class="time">Posted <a href="{tweet_url}">{time}</a></span> <span class="username">Follow <a href="http://twitter.com/{user}">@{user}</a></span>'}
		});
	
		$('.home .twitter .content > div').click(function(){
			$(this).find('.listing').slideToggle('fast');
			$(this).find('.item').toggle('fast');
		});
	
	}
	
	// Append separator graphic to news widgets.
	$('.home .news.featured').append('<img src="/clients/blackveilbrides/img/shutter-separator-right.png" alt="" class="separator" />');
	$('.news .story .article .figure').prepend('<img src="/clients/blackveilbrides/img/shutter-separator-left.png" alt="" class="separator" />');
	
	// Animate the news widget on click
	$('.home .news .item').click(function(){
		var w = $(this).width();
		var e = $(this);
		toggleShutter(e,w);
	});
	
	// Automatically scroll the page down a bit on interior pages
	$("body[class!='home']").scrollTo('330px');
	
	// Fade in the prev and next medial links on hover
	$('.media .asset .prev, .media .asset .next').fadeOut('slow');
	$('.media .asset').hover(
		function(){
			$('.media .asset .prev, .media .asset .next').fadeIn('fast');
		},
		function(){
			$('.media .asset .prev, .media .asset .next').fadeOut('fast');
		}
	);
	
	// Ouiji mouse
	$("#footer").append('<div id="ouiji"><img src="/clients/blackveilbrides/img/pointer-black.png" alt="pointer" id="pointer" /></div>');
	$("#ouiji").hover(function(e){
		$("#pointer").css({'left': e.pageX+'px','top': e.pageY+'px'});
		var center = $(window).width()/2;
		$("#pointer").animate({
			left: center + 'px',
			top: e.pageY + 100 + 'px'
		},2000);
	});
});

