(function( $ ){

	var methods = {
		init : function( options ) { 
			initSlides();
			initTips(false);
		},
		update : function( ) { 
			initHandlers();
		}
	};
	
	
	var initHandlers = function () {
		var a = Sys.WebForms.PageRequestManager.getInstance(); 
		a.add_endRequest( function() { initSlides(); initTips(true); } );
	};

	
	
	var initSlides = function () {
		var slide = false;
		var height = $('#footer_content').height();
		$('#footer_button').click(function() {
			var docHeight = $(document).height();
			var windowHeight = $(window).height();
			var scrollPos = docHeight - windowHeight + height;
			$('#footer_content').animate({ height: "toggle"}, 1000);
			if(slide == false) {
				if($.browser.opera) {
					$('html').animate({scrollTop: scrollPos+'px'}, 1000);
				} else {
					$('html, body').animate({scrollTop: scrollPos+'px'}, 1000);
				}
				slide = true;
			} else {
				slide = false;
			}
		});
	};
	
	
	var initTips = function (forform) {
		$('div.content a').tipsy(
			{
				gravity: 's', // nw | n | ne | w | e | sw | s | se
				fade: true
			});

		if ($('form').length !== 0) {
			$('input, select, textarea').tipsy(
				{
					gravity: 'w', // nw | n | ne | w | e | sw | s | se
					fade: true,
					trigger: 'focus',
					title: function () { if ($(this).parent().children('small', 0).html() === null) { return ''; } else { return $(this).parent().children('small', 0).html(); } },
					fallback: ''
				});

			$('input[type=submit]').tipsy('show', 
				{
					gravity: 'w', // nw | n | ne | w | e | sw | s | se
					fade: true,
					trigger: 'manual',
					title: function () { if ($(this).parent().children('small', 0).html() === null) { return ''; } else { return $(this).parent().children('small', 0).html(); } },
					fallback: ''
				});
		}
	};

	

	$.fn.uConnect = function (method) {

		// method calling logic
		if ( methods[method] ) {
			return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
		} else if ( typeof method === 'object' || ! method ) {
			return methods.init.apply( this, arguments );
		} else {
		  $.error( 'Method ' +  method + ' does not exist on jQuery.uConnect' );
		}
	};


})( jQuery );






