$(function() {

	/* Set Main Nav active link */
	var activePage = 'blog'; //set default
	if($("#content").attr("data-page") !== undefined) {
		activePage = $("#content").attr("data-page");
		$("header nav ol li#"+activePage).addClass("active");
	}
	
	/* Bit of a hack to remove the href from the '1 day ago' links on the 
			Tweets on the homepage */
	$("span.time-meta a").removeAttr("href");
	
	/* Search box - hide text on focus - replaces expander script below */
	$("#search_query").focus(function() {
		if ($(this).val() == 'Search...') {
			$(this).val("");
		}
	});
	$("#search_query").blur(function() {
		if($(this).val() == '') {
			$(this).val('Search...');
		}
	});

	/* Search box expander script */
	/*
	var searchQCss = []
		searchQCss['grow'] = 37;
		searchQCss['backgroundPosition'] = '147px 4px';
		searchQCss['backgroundColor'] = $("#search_query").css("background-color");
		searchQCss['width'] = $("#search_query").css("width");
		searchQCss['color'] = $("#search_query").css("color");
		searchQCss['borderColor'] = $("#search_query").css("border-top-color");

		searchQCss['backgroundPositions'] = [147, 4];
		var newBPos = (searchQCss['backgroundPositions'][0]+searchQCss['grow'])+"px "+(searchQCss['backgroundPositions'][1]-28)+"px";
		var newWidth = parseInt(searchQCss['width']) + parseInt(searchQCss['grow']);

	$("#search_query").focus(function() {
		$(this).val("");
		$(this).animate({
				backgroundColor: "#fff",
				width: newWidth + "px",
				color: "#737373",
				borderColor: "#666"
		}, 150, 'linear', function() {
				this.style.backgroundPosition = newBPos
				$(this).css({
					"-moz-box-shadow": "inset 0 0 4px 2px rgba(0,0,0,0.2)",
					"-webkit-box-shadow": "inset 0 0 2px 1px rgba(0,0,0,0.2)",
					"-box-shadow": "inset 0 0 2px 1px rgba(0,0,0,0.2)"
				});
		});
	});

	$("#search_query").blur(function() {
		$(this).animate({
				backgroundColor: "transparent",
				width: searchQCss['width'],
				color: searchQCss['color'],
				borderColor: searchQCss['borderColor']
		}, 150, 'linear', function() { 
				this.style.backgroundColor='transparent'; 
				this.style.backgroundPosition = searchQCss['backgroundPosition']
				$(this).css({
					"-moz-box-shadow": "none",
					"-webkit-box-shadow": "none",
					"-box-shadow": "none"
				});
				if($(this).val() == '') {
					$(this).val('Search...');
				}
		});
	});
	*/
	
	$(".footer_comment").each(function() {
		$(this).mouseenter(function(){
			$(this).addClass("hover");
		});
		$(this).mouseleave(function(){
			$(this).removeClass("hover");
		});
		$(this).click(function() {
			var link = $(this).attr("data-link");
			window.location.href = link;
		});
	});
});

/* @group per-page execution logic */

BDA.pages = {  
  
  'common': function() {
  },
 
 'home': function() {    
    new BDA.featureSlideshow('home', '#slider .slides', 'li', '.slider_pagination', '.home-prev', '.home-next', ".slide_caption");
    new BDA.featureSlideshow('team', '#team_slider .team_slides', 'li', '', '.team-prev', '.team-next', ".team_slide_caption");
    
    var VimeoEmbed = {};
/*
    //Called on document ready
    VimeoEmbed.init = function(e)
    {
        //Listen to the load event for all the iframes on the page
        $('iframe').each(function(index, iframe){
            iframe.addEvent('onLoad', VimeoEmbed.vimeo_player_loaded);
        });
    };

    VimeoEmbed.vimeo_player_loaded = function(player_id)
    {
        // add pause event to the PREV and NEXT arrows on the slider
        $('.home-prev, .home-next').bind('click', {'player_id': player_id}, function(e){
            var iframe = $('#'+e.data.player_id).get(0);
            iframe.api( 'api_pause', null );
        });
     }; 
     
     //On document ready
     $(document).ready(VimeoEmbed.init); 
        */
  },
  
 'about': function() { 
    new BDA.featureSlideshow('team', '#team_slider .team_slides', 'li', '', '.team-prev', '.team-next', ".team_slide_caption");
  } 
  
};

/* GO GO GO */

UTIL = {
  exec: function(page) {
    var ns = BDA.pages;

    if ( page !== "" && ns[page] && typeof( ns[page] ) == "function" ) {ns[page]();}
  },

  init: function() {
    var page = $("div#content").attr("data-page");
      
    
    //UTIL.exec( "common" );
    UTIL.exec( page );

  }
};

$(document).ready( UTIL.init );

