// JavaScript Document

$(function() {
	sliderInit();
	calltoAction();
	twitterFeedInit();
	newsFeedInit();
	flickrPluginInit();
	/*
	$('img').load(function() {
		
		var sliderImages = $('div.sliderImage');
	
		$(sliderImages).each(function(index) {
			console.log(this);
			var sliderDivWidth = $(this).width();
			var sliderDivHeight = $(this).height();
			var sliderImg = $(this).find('img');
			var imgWidth = $(sliderImg).width();
			var imgHeight = $(sliderImg).height();
			
			console.log(sliderDivWidth + ' ' + sliderDivHeight + ' ' + sliderImg + ' ' + imgWidth + ' ' + imgHeight);
			
			sideMargins = (sliderDivWidth - imgWidth)/2;
			topMargins = (sliderDivHeight - imgHeight)/2;
		
			inputMargins = topMargins + 'px ' + sideMargins + 'px';
			console.log(inputMargins);
			$(sliderImg).css('margin', inputMargins);
		});
		
	});*/
		
});

function sliderInit() {
	
	$('#slider').cycle({ 
							fx:     'fade', 
							speed:  500, 
							timeout: 6000, 
							pager:  '#sliderNav',
							pause: 1 
						});
	
	var moreLinks = $('div#sliderContent').find('div.moreBtn');
	moreLinks.click(function(e) {
		e.stopPropagation();
		var destination = $(this).find('a').attr('href');
		window.location.href = destination;
	});
	
}


function calltoAction() {
	var ctaLinks = $('div#left_column').children('div.calltoaction');
	
	$(ctaLinks).click(function(e) {
		e.stopPropagation();
		var destination = $(this).find('a').attr('href');
		window.location.href = destination;
	});
	
}

function twitterFeedInit() {
	
	
}

function newsFeedInit() {
	var newsTabs = $('div#newsNav ul').children('li.tab');
	
	$(newsTabs).click(function(e) {
		e.stopPropagation();
		e.preventDefault();
		var btnID = $(this).attr('id');
		//console.log(btnID);
		switch(btnID) {
			case 'stories' :
				$('div#newsContent div.newsevents').css('display', 'none');
				$('div#newsContent div#stories_entries').fadeIn('fast');
				break;
				
			case 'releases' :
				$('div#newsContent div.newsevents').css('display', 'none');
				$('div#newsContent div#releases_entries').fadeIn('fast');
				break;
				
			case 'updates' :
				$('div#newsContent div.newsevents').css('display', 'none');
				$('div#newsContent div#updates_entries').fadeIn('fast');
				break;
		}
		
		$(this).addClass('active').parent().find('li.tab').not(jQuery(this)).removeClass('active');
		
	});
	
}

function flickrPluginInit() {
	
	
}
