$(document).ready(function(){
	$('div.ajax').ajaxLink();
	$('a.ajax').ajaxLink();
	$('form.ajax').ajaxForm();
});// document.ready

//------ functions -------//
jQuery.fn.ajaxForm = function(){
	if ($.browser.msie) {
			$(".submit", this).live('click',function() {
			$(this).submit();
			return false;
		});
	}//end if
	$(this).live('submit',function(){
		$.post( $(this).attr('action'), $(this).serialize() );
		return false;
		} //function
	);// click
	}// end ajaxForm

jQuery.fn.ajaxLink = function(){
	this.die('click');
	this.live('click',
		function(){
			$.get( $(this).attr('href') );
			return false;
		} //function
	);// click
	}// end ajaxLink

jQuery.fn.heightOfChildren = function(){
	element = this;
	var $heights = 0 ;
	$(element).children().each(function(){
	$heights = $heights + $(this).heightOfElement();
	});
	return $heights;
	}// end heightOfChildren

jQuery.fn.heightOfElement = function(){
	element = this;
	$h = 0;
	$h = $h + parseInt( $(element).height() ); // gets height of content
	$h = $h + $(element).heightOfPerimeter(); // adds height of box model
	return $h;
	}//end fn.heightOfElement

jQuery.fn.widthOfElement = function(){
	element = this;
	$w = 0;
	$w = $h + parseInt( $(element).width() ); // gets width of content
	$w = $h + $(element).widthOfPerimeter(); // adds width of box model
	return $w;
	}//end fn.heightOfElement

jQuery.fn.heightOfPerimeter = function(){
	$p = 0;
	$p = $p + parseInt( $(this).css("margin-top") ); // adds height of box model
	$p = $p + parseInt( $(this).css("margin-bottom") );
	$p = $p + parseInt( $(this).css("border-top-width") );
	$p = $p + parseInt( $(this).css("border-bottom-width") );
	$p = $p + parseInt( $(this).css("padding-top") );
	$p = $p + parseInt( $(this).css("padding-bottom") );
	return $p;
	} //end fn.heightOfPerimeter

jQuery.fn.widthOfPerimeter = function(){
	$p = 0;
	$p = $p + parseInt( $(this).css("margin-left") ); // adds height of box model
	$p = $p + parseInt( $(this).css("margin-right") );
	$p = $p + parseInt( $(this).css("border-left-width") );
	$p = $p + parseInt( $(this).css("border-right-width") );
	$p = $p + parseInt( $(this).css("padding-left") );
	$p = $p + parseInt( $(this).css("padding-right") );
	return $p;
	} //end fn.heightOfPerimeter

jQuery.fn.expandY = function($offSet){
	var element = this[0] ;
	var parentInnerHeight = $(element).parent().innerHeight();
	parentInnerHeight = parentInnerHeight - parseInt( $(element).parent().css('padding-top') );
	parentInnerHeight = parentInnerHeight - parseInt( $(element).parent().css('padding-bottom') );
	var childNewHeight = parentInnerHeight - $(element).heightOfPerimeter();
	if( !isNaN($offSet) ) childNewHeight = childNewHeight + $offSet ;
	$(element).css({'height': childNewHeight + 'px'});
	}; // end fn.expandY

//- * - * -// 
jQuery.fn.getWindowCenterHeight = function () {
	return $(window).height() / 2  ;
	}

jQuery.fn.getWindowCenterWidth = function () {
	return $(window).width() / 2 ; 
	}

jQuery.fn.center = function () {
	var $perimeterHeight = this.heightOfPerimeter();
	var $perimeterWidth = this.widthOfPerimeter();
	this.parent().css("position","relative");
	this.parent().css("top","0px");
	this.parent().css("left","0px");
	this.css("position","absolute");	
	this.css('left', ( ( $(window).width() - this.width()  -  $perimeterWidth ) / 2 ) + 'px');
	this.css('top' , ( ( $(window).height() - this.height() - $perimeterHeight ) / 2 ) + 'px');
    return this;
	}// end center

//- * - * -// 

// :contains -> case insensative
jQuery.expr[':'].contains = function(a,i,m){
    return jQuery(a).text().toUpperCase().indexOf(m[3].toUpperCase())>=0;
};
	
//------ time ------//
jQuery.fn.XXXwait = function(time, type) {
    time = time || 1000;
    type = type || "fx";
    return this.queue(type, function() {
        var self = this;
        setTimeout(function() {
            $(self).dequeue();
        }, time);
    });
};//end fn.wait

//------ wait plugin ------//
//http://www.inet411.com/articles/jquery/wait-plugin.html
(function($) {
    $.fn.wait = function(option, options) {
        milli = 1000; 
        if (option && (typeof option == 'function' || isNaN(option)) ) { 
            options = option;
        } else if (option) { 
            milli = option;
        }
        // set defaults
        var defaults = {
            msec: milli,
            onEnd: options
        },
        settings = $.extend({},defaults, options);
        if(typeof settings.onEnd == 'function') {
            this.each(function() {
                setTimeout(settings.onEnd, settings.msec);
            });
            return this;
        } else {
            return this.queue('fx',
            function() {
                var self = this;
                setTimeout(function() { $.dequeue(self); },settings.msec);
            });
        }
    }
})(jQuery);


/*!
* jQuery.hook v1.0
*
* Copyright (c) 2009 Aaron Heckmann
*/
/**
* Provides the ability to hook into any jQuery.fn[method]
* with onbeforeMETHOD, onMETHOD, and onafterMETHOD. 
*
* Pass in a string or array of method names you want 
* to hook with onbefore, on, or onafter. 
*
* Example: 
* 	jQuery.hook('show');
*	jQuery(selector).bind('onbeforeshow', function (e) { alert(e.type);});
*   jQuery(selector).show() -> alerts 'onbeforeshow'
*
*   jQuery.hook(['show','hide']);
*   jQuery(selector)
*       .bind('onbeforeshow', function (e) { alert(e.type);})
*       .bind('onshow', function (e) { alert(e.type);})
*       .bind('onaftershow', function (e) { alert(e.type);})
*       .bind('onafterhide', function (e) { alert("The element is now hidden.");});
*   jQuery(selector).show().hide()
*        -> alerts 'onbeforeshow' then alerts 'onshow', then alerts 'onaftershow',
*             then after the element is hidden alerts 'The element is now hidden.'

* You can also unhook what you've hooked into by calling jQuery.unhook() passing
* in your string or array of method names to unhook.
*
*/
;(function($){
	$.hook = function (fns) {
		fns = typeof fns === 'string' ? 
			fns.split(' ') : 
			$.makeArray(fns)
		;
		
		jQuery.each( fns, function (i, method) {
			var old = $.fn[ method ];
			
			if ( old && !old.__hookold ) {
				
				$.fn[ method ] = function () {
					this.triggerHandler('onbefore'+method);
					this.triggerHandler('on'+method);
					var ret = old.apply(this, arguments);
					this.triggerHandler('onafter'+method);
					return ret;
				};
				
				$.fn[ method ].__hookold = old;
				
			}
		});	
			
	};
	
	$.unhook = function (fns) {
		fns = typeof fns === 'string' ? 
			fns.split(' ') : 
			$.makeArray(fns)
		;
		
		jQuery.each( $.makeArray(fns), function (i, method) {
			var cur = $.fn[ method ];
			
			if ( cur && cur.__hookold ) {				
				$.fn[ method ] = cur.__hookold;			
			}
		});
		
	};
})(jQuery);








