$( document ).ready(function() {
  if (typeof stirhash != 'undefined')
	if (stirhash !='')
	  	window.location.hash=stirhash;
  $('#logo').flash({
    swf: "http://stirstuff.com/flash/small_logo.swf",
    width: 87,
    height: 125
  });

  // Check for FB like button
  if ($('#fb-root').length)
  {
  	  var fbhref=getFBhashurl();
	  $('#fb-root').html('<fb:like href="' + getFBhashurl() + '" layout="button_count" show_faces="false" width="100" action="like" font="segoe ui" colorscheme="light" />');  	  
	  $('#tw-button').html('<a href="https://twitter.com/share" class="twitter-share-button" data-url="'+ fbhref +'" data-count="none" data-via="stirology">Tweet</a>');            
	  $(window).hashchange( function(){
			var fbhref=getFBhashurl();
			if (typeof FB !='undefined')
			{
				$('#fb-root').html('<fb:like href="' + fbhref + '" layout="button_count" show_faces="false" width="100" action="like" font="segoe ui" colorscheme="light" />');
				FB.XFBML.parse(document.getElementById('fb-root'));
			}
			if (typeof twttr !='undefined')
			{
				$('#tw-button').html('<a href="https://twitter.com/share" class="twitter-share-button" data-url="'+ fbhref +'" data-count="none" data-via="stirology">Tweet</a>');            
				twttr.widgets.load();
			}

			return false;

	  })
  }
});

/* Used to compose the FB url for portolio items. Hashtags are not transmitted via HTTP and also FB strips them
   So we convert to query string param to handle it
*/   
function getFBhashurl() {
	if (window.location.hash!='')
		return location.protocol + '//' + location.hostname + location.pathname + '?p=' + window.location.hash.split('#/').pop();
	else
		return window.location.href;
}
