$(function(){
	
	// Tokens
	$('#ping').after($('<input>').attr({'name':'pong','value':$('#ping').val(),'class':'hide'}));
	
	// target="blank"
	$('a[rel="external"], form.form-external').attr({'target':'_blank'});
	
	// Photos
	if ($('#fx').length) {
		var settings = {
			effect: 'sliceDown',
			slices: 5,
			animSpeed: 500,
			pauseTime: 5000,
			directionNav: true,
			directionNavHide: false,
			controlNav: true,
			keyboardNav: false,
			captionOpacity: 1
		};
		
		if ($('#fx').hasClass('no-controls')) {
			settings.directionNav = false;
			settings.controlNav = false;
		}
		
		$('#fx').nivoSlider(settings);
	} else {		
		var title = $('#header .photo img').attr('title');
		
		if (typeof title !== 'undefined' && title !== false && title != '') {
			$('#header .photo').append($('<div class="caption"></div>').html(title));
			$('#header .photo img').removeAttr('title');
		}
		
	}
	
	// Submenu
	$('#header .main-menu li a, #header .main-menu ul').hover(function() {
		$(this).parent().addClass('hover');
	}, function() {
		$(this).parent().removeClass('hover');
	});
	
	// Sign-up form
	$('#header .sign-up .text').addClass('default');
	var defaultValue = $('#header .sign-up .text').val();
	$('#header .sign-up .text').focus(function() {
		if ($(this).val() == defaultValue) $(this).val('').removeClass('default');
	});
	$('#header .sign-up .text').blur(function() {
		if ($(this).val() == '') $(this).val(defaultValue).addClass('default');
	});
	
	// FaceBook Like
	var current_url = $('#content .fb-like').attr("title");
	if (!current_url) {	current_url = window.location.protocol + "//" + window.location.hostname + "/"; }
	$('#content .fb-like').html('<iframe src="http://www.facebook.com/plugins/like.php?href=' +current_url+ '&amp;layout=standard&amp;show_faces=false&amp;width=90&amp;action=like&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" allowTransparency="true" class="facebook-like"></iframe>');
	
	// Colorbox
	$(".colorbox, #content .content .gallery a").colorbox({opacity: 0.7, initialWidth: 109, initialHeight: 81});
	
	// Google Map (40.76052886758016, -73.97950887680054)
	if($("#content .googlemap").length) {
		$("#content .googlemap").gMap({
			markers: [{
				latitude: 40.76052886758016,
	    		longitude: -73.97950887680054,
				html: '<h3>The Terrace Club</h3><p>25 West 51<sup>st</sup> St.<br>New York, NY 10019</p><p><a target="_blank" href="http://maps.google.com/maps?f=d&geocode=&daddr=The Terrace Club 25b West 51st Street New York NY&z=13">Get Driving Directions</a></p>',
				popup: true
		 	}],
			zoom: 16,
			controls: ["GLargeMapControl3D", "GMapTypeControl"],
			scrollwheel: false,
			maptype: G_PHYSICAL_MAP,
			icon:
			    {
			        image:              "images/pointer.png",
			        iconsize:           [38, 42],
			        iconanchor:         [22, 28],
			        infowindowanchor:   [25, 2]
			    }
			
		});
	}
	
	// Datepicker
	if($(".date-pick").length) {
		$('.date-pick').datePicker({'clickInput' : true });
	}
	
	// USA & States (forms)
	var usa_state_handler = function() {
		el = $("#Country");

		if ($(el).val() == 'US' || $(el).val() == 'USA') {
			$('form.form #StateProvince').removeAttr('disabled');
		} else {
			$('form.form #StateProvince').attr('disabled', 'disabled');
			$('form.form #StateProvince').val(''); 
		}
	};

	$('form.form #Country').blur(usa_state_handler);
	$('form.form #Country').change(usa_state_handler);
	usa_state_handler();

});
