// remap jQuery to $
(function($){})(window.jQuery);

$(window).load(function() {

	// Push at least as tall as the sidebar
	if ($("#sidebar").length > 0){
	$("#main").css("min-height",$("#sidebar").outerHeight());
	$("#sidebar").css("min-height",$("#main").outerHeight());
	}
	
	if ($("#sidebar-in").length > 0){
	$("#main").css("min-height",$("#sidebar-in").outerHeight());
	$("#sidebar-in").css("min-height",$("#main").outerHeight());
	}
	// rel='external' opens in new window
	$("a[rel=external]").click(function() {
		window.open(this.href);
		return false;
	})

});

/* PSEUDO DROPDOWNS */

// Replace spans with pseudo dropdowns in forms
$(".pseudo-dropdown").live("click",function() {
	// Vars
	var dropdownID = $(this).attr("id");
	var offsetTop = $(this).offset().top;
	var linkHeight = $(this).height();
	var offsetLeft = $(this).offset().left;
	var linkWidth = $(this).width();
	var intID = 0;
	
	var arrOptions = new Array(0,1,2,3,4,5);
	
	// Print options
	if ($('#'+dropdownID+'-select').length < 1) {
		$('<div class="pseudo-dropdown-links" id="'+dropdownID+'-select" style="position: absolute; z-index: 999; line-height: '+linkHeight+'px; background-color: #e4e4e4; top: '+(offsetTop+linkHeight)+'px; left: '+offsetLeft+'px;" />').prependTo('body');
		$(arrOptions).each(function() {
			intID=intID+1;
			$('<a href="javascript:void(0);" style="display: block; padding: 0 15px;">'+this+'</a>').appendTo('#'+dropdownID+'-select');
		});
	}
	
	// Retrieve what they clicked
	$("#"+dropdownID+"-select a").live("click",function() {
		$("#"+dropdownID+" span").text($(this).text());
		$("#"+dropdownID+"-select").remove();
	});
	
	// Bind clicking outside
	$('body').bind("click",function() {
		$("#"+dropdownID+"-select").remove();
	});
});

/**
 * ASYNC SHARE BUTTONS
 * SEPT 2011
 */

// Facebook "Like"

  // prevent jQuery from appending cache busting string to the end of the FeatureLoader URL
  var cache = jQuery.ajaxSettings.cache;
  jQuery.ajaxSettings.cache = true;
  // Load FeatureLoader asynchronously. Once loaded, we execute Facebook init 

  jQuery.getScript('http://connect.facebook.net/en_US/all.js', function() {
    FB.init({status: true, cookie: true, xfbml: true});
  });
  // just Restore jQuery caching setting
  jQuery.ajaxSettings.cache = cache;

// Twitter "Tweet"

	// async script
	(function() {
	var s = document.createElement('SCRIPT');
	var c = document.getElementsByTagName('script')[0];
	s.type = 'text/javascript';
	s.async = true;
	s.src = 'http://platform.twitter.com/widgets.js';
	c.parentNode.insertBefore(s, c);
	})();

// Google "+1"

  // async script
  (function() {
    var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
    po.src = 'https://apis.google.com/js/plusone.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
  })();

/**
 * Stylish Select
 */
$(function(){
	$('#header-book-a-room select').sSelect();
});
