// JavaScript Document

$(document).ready(function() {
						   
	
	
	if ($('.usePreview').length > 0) {
		$("a#inline").fancybox({
			//'hideOnContentClick': true
			padding:0,
			showCloseButton: false
			
		});
	
		setTimeout(function(){$("a#inline").trigger('click');}, 500);
		
		$('.formPreview-Yes').click(function(e) {
			$('#formPreviewBox').attr('action', '/preview');
			$('#formPreviewBox').find('[name=_action]').val('');
			$('#formPreviewBox').find('[name=path_info]').val(document.location.pathname);
			$('#formPreviewBox').submit();
		});
		
		$('.formPreview-No').click(function() {
			$.fancybox.close();
		});
	}
	
	$("a[rel=external]").click(function() {
		var w = window.open($(this).attr('href'),'_blank');
		w.focus();
		return false;
	});
	
	// Unobtrusive
	$('#tools').prepend('<a class="print" href="#print">Print page</a>');
	$('#tools a.print').click(function() {
		window.print();
		return false;
	});
  
	$('#sidebar ul li').each(function() {
		var n = $(this).attr('id');
		if (n != '') {
			sidebarHide('#' + n);
		}
	});
	
	$("#form_TenancySart").datepicker( { dateFormat: 'dd-M-yy' } );
	$("#form_CompFormationDate").datepicker( { dateFormat: 'yy-mm-dd',yearRange:"-100:+0",changeYear: true } );
	$("#form_CompanyDateReturns").datepicker( { dateFormat: 'yy-mm-dd' } );
	$("#form_CompanyDateAccounts").datepicker( { dateFormat: 'yy-mm-dd' } );
	
	// Throbber function
	(function($){var defaultOptions={ajax:true,delay:0,image:"throbber.gif",parent:"",wrap:""};$().ajaxStop(function(){_throbberHide($(".throbber_ajax"));});_throbberShow=function(options,jelement){var jparent;if(options.parent){jelement=null;jparent=$(options.parent);}else{jparent=(jelement?jelement.parent():$("body"));}
	if(jparent.find(".throbber").length==0){window.clearTimeout(jparent.data("throbber_timeout"));jparent.data("throbber_timeout",window.setTimeout(function(){var throbber=$('<img src="'+options.image+'" class="throbber" />');if(options.ajax){throbber.addClass("throbber_ajax");}
	if(jelement){throbber.data("throbber_element",jelement);jelement.hide().after(throbber);}else{jparent.children().hide().end().append(throbber);}
	if(options.wrap!=""){throbber.wrap(options.wrap);}},options.delay));}};_throbberHide=function(throbbers){throbbers.each(function(){var throbber=$(this);var jelement=throbber.data("throbber_element");if(jelement){jelement.show();}else{throbber.siblings().show();}
	window.clearTimeout(throbber.parent().data("throbber_timeout"));throbber.remove();});}
	$.fn.throbber=function(event,options){if(typeof event=="undefined"){event="click";options={};}else if(typeof event=="object"){options=event;event="click";}else if(typeof options=="undefined"){options={};}
	options=$.extend({},defaultOptions,options);$(this).each(function(){var jtarget=$(this);jtarget.bind(event,function(){_throbberShow(options,jtarget);});});return $(this);};$.throbberShow=function(options){options=$.extend({},defaultOptions,options);_throbberShow(options,null);return $;};$.throbberHide=function(){_throbberHide($(".throbber"));return $;};})(jQuery);	
	
});

