$(document).ready(function() {
  
	var quotes={
	speaking : [
			{quote:"Alexander's work in applying business models is true thought leadership.", author:"Richard Hunter, Gartner Inc., USA"},
		{quote:"Do not pass up the chance to work with Alex or attend one of his workshops or keynotes.", author:"Michael Dila, Torch Patnership, Canada"},
			{quote:"Alex has the potential to become a worldwide guru on Business Modelling.", author:"Thomas Beerepoot, Bolster, The Netherlands"},
		{quote:"Alex can help you to change your point of view.", author:"Hans Suter, STZ Advertising Agency, Italy"}

	],
	workshops : [
		{quote:"Alex is a real thought leader in the field of Business Model Innovation, I thoroughly enjoyed participating in a workshop facilitated by him. He is an engaging speaker, excellent storyteller and charismatic person.", author:"Synnøve Stubø Engeskaug, A/S Norske Shell, Norway"},
		{quote:"I would highly recommend Alex and his approach to Business Model Innovation.", author:"Hrridaysh Deshpande, Elephantversity, India"}
	],
	home : [
		{quote:"Business model innovation is about <em>new ways</em> of creating, delivering and capturing <em>value</em>."},
		{quote:"Companies that aren't able to <em>systematically rejuvenate</em> their business model will struggle to survive and thrive."},
		{quote:"Industries will increasingly be characterized by <em>competing business models</em> - if industry boundaries don't disappear altogether."}
	]};
	
	var quoteInterval = 7500;
	
  initializeEmbedControls();  
	
  var quoteCount = 0;

  var animating=false;
  
  var intervalID = setInterval(function(){
    animating = true;
    nextQuote();
  },quoteInterval);
  
	var curPage = $("body").attr("class");
		
	if (curPage=="workshops"){
		$.getJSON("http://api.flickr.com/services/feeds/photoset.gne?set=72157622073042051&nsid=67526850@N00&lang=en-us&format=json&jsoncallback=?", function(data){
			$.each(data.items, function(i,item){
				$("<img/>").attr({"src": item.media.m, "width":190}).appendTo(".workshop-photos").wrap("<a href='" + item.link + "' target='_blank'></a>");
				return (i<4);
			});
		});	
	}

  if (curPage=="home") $('#quote-container blockquote').html("&ldquo;"+quotes.home[quoteCount]["quote"]+"&rdquo;");
  else if (curPage=="speaking") {
		$('#quote-container blockquote').html("&ldquo;"+quotes.speaking[quoteCount]["quote"]+"&rdquo;");
		$('#quote-container .author').html(quotes.speaking[quoteCount]["author"]);
	}
  else if (curPage=="workshops") {
		$('#quote-container blockquote').html("&ldquo;"+quotes.workshops[quoteCount]["quote"]+"&rdquo;");
		$('#quote-container .author').html(quotes.workshops[quoteCount]["author"]);
	}
	
  $('#quote-controls').hover(function(){
    $(this).children('#next-quote, #prev-quote').show();
   clearInterval(intervalID);
  },function(){
    $(this).children('#next-quote, #prev-quote').hide();
    intervalID = setInterval(function(){
      animating = true;
      nextQuote();
    },quoteInterval);
  });
  
  $('#next-quote').click(function(){
    if (!animating) {
      animating = true;
      nextQuote();
    }
  });

  $('#prev-quote').click(function(){
    if (!animating) {
      animating = true;
      prevQuote();
    }
  });
  function nextQuote(){
	  $('#quote-container p.author').hide();
    $('#quote-container blockquote').animate({"left":-630},300,"swing", function(){
      
      if (curPage=="home") {
				if (quoteCount >= quotes.home.length-1) quoteCount = 0;
				else quoteCount++;
				$(this).html("&ldquo;"+quotes.home[quoteCount]["quote"]+"&rdquo;");
			} 
			else if (curPage=="speaking") {
				if (quoteCount >= quotes.speaking.length-1) quoteCount = 0;
				else quoteCount++;
				$(this).html("&ldquo;"+quotes.speaking[quoteCount]["quote"]+"&rdquo;");
				$('#quote-container .author').html(quotes.speaking[quoteCount]["author"]);
			}
			else if (curPage=="workshops") {
				if (quoteCount >= quotes.workshops.length-1) quoteCount = 0;
				else quoteCount++;
				$(this).html("&ldquo;"+quotes.workshops[quoteCount]["quote"]+"&rdquo;");
				$('#quote-container .author').html(quotes.workshops[quoteCount]["author"]);
			}
     
      $(this).css("left",630).show().animate({"left":0},300,"swing",function(){
				$('#quote-container p.author').fadeIn('medium');
        animating = false;
      });
    }); 
  }

  function prevQuote(){
	  $('#quote-container p.author').hide();
    $('#quote-container blockquote').animate({"left":630},300,"swing", function(){

      if (curPage=="home") {
				if (quoteCount <= 0) quoteCount = quotes.home.length-1;
				else quoteCount--;
				$(this).html("&ldquo;"+quotes.home[quoteCount]["quote"]+"&rdquo;");
			} 
			else if (curPage=="speaking") {
				if (quoteCount <= 0) quoteCount = quotes.speaking.length-1;
				else quoteCount--;
				$(this).html("&ldquo;"+quotes.speaking[quoteCount]["quote"]+"&rdquo;");
				$('#quote-container .author').html(quotes.speaking[quoteCount]["author"]);
			}
			else if (curPage=="workshops") {
				if (quoteCount <= 0) quoteCount = quotes.workshops.length-1;
				else quoteCount--;
				$(this).html("&ldquo;"+quotes.workshops[quoteCount]["quote"]+"&rdquo;");
				$('#quote-container .author').html(quotes.workshops[quoteCount]["author"]);
			}

      $(this).css("left",-630).show().animate({"left":0},300,"swing",function(){
				$('#quote-container p.author').fadeIn('medium');
        animating = false;
      });
    });
  }
  
  $('#bmg-button').hover(function(){
    $('#bmg-popup').css('left',$(this).offset().left-0.5*$('#bmg-popup').width()+0.5*$(this).width()).css('top',$(this).offset().top-112).fadeIn('fast')
  },function(){
    $('#bmg-popup').fadeOut('fast');
  });
  
})

