/* The javascripts here run on every page */

jQuery(document).ready(function($) {

	// promo module
	if ($.isFunction($.fn.tabs)) {
		$(".promo").tabs().tabs('rotate', 3000);
	}
	
	// calculator
	if ($.isFunction($.fn.sizingCalculator)) {
		$('#calculator').sizingCalculator();
	}
	
	// add default subject line
	$(':text[name="your-subject"]').val(window.location.search.replace('?subject=','').replace(/\+/g,' '));

	if (!$('#dialog').length) {
		$('<div id="dialog"></div>').appendTo('body');
	}
	
	if ($.isFunction($.fn.dialog)) {
		$('#dialog').dialog({
			bgiframe: true,
			modal: true,
			width: 640,
			autoOpen: false,
			position: ['center', 30]
		});
	}

	$('[rel="videolightbox"]').click(function() {
		var self = $(this);
		var width = 800;
		$('#dialog').dialog('option', {
			title: self[0].title,
			width: width,
			resizable: false,
			open: function(event, ui){
				$(this).append('<a href="'+ self[0].href +'" style="display:block;width:800px;height:295px;" id="player"></a>');
				flowplayer('player', "/wp-content/themes/sage/includes/swf/flowplayer-3.1.3.swf");
			},
			close: function() {
				$(this).empty();
			}
		}).dialog('open');
		
		return false;
	});
	
	if ($('.widget-contactform').length) {
		$('.widget-contactform textarea').bind('focus', function() {
			$(this).closest('.widget-contactform').find('.form-extras:hidden').slideDown();
		});
		$('.widget-contactform').find('.wpcf7-validation-errors').parent().find('.form-extras:hidden').show();
	}
});