
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* 
 *
 *	====================================		
 *     JQUERY TOOLBOX LIBRARY
 *	====================================		
 *
 *		This is a library of common & useful jquery functions that can be easily used in your website.
 *		
 *					....And how!
 *
 *
 *		Insert the following code at the bottom of your page but before the closing body tab ( </body> )
 *	
 *		<script type="text/javascript">
 *			$(document).ready(function() {
 *
 *				// *** CALL FUNCIONS HERE
 *
 *			});
 * 	 	</script>
 *
 *					....But wait! there's more!....
 * 
 *
 *		FUNCTIONS
 *	====================================	
 *	
 *		1) inputBoxText(str, inputBoxClass)
 *		2) newWindow(hrefClass)
 *		3) print(divClass)
 *		4) confirmBox(message, hrefClass)
 */
	
	
// ------------------------------------------
	
	function inputBoxText(str, inputBoxClass)
	/*  #1
	 *	Author:		Michael "Face disgusts me" Dowling	 	  
	 *	Date: 
	 *	Purpose: 	Sets the default in a input box . eg, 'search...' in a search box
	 *				It also clears the box when the user clicks in it ...H0t!
	 *	Params: 	str: 			The text to display  
	 *				inputBoxClass: 	The class of the input box
	 *	Example: 	
	 *		HTML code: 	 	<input type="text" class="search_field" value="keyword (s)" />	   	   	
	 *		Function call: 	inputBoxText('keyword (s)', 'search_field');	
	 *
	 */
	{
		$('.'+inputBoxClass).focus(function () {
		    var text = $(this).val();
		    if (text == str) {
		        $(this).val('');
		    }
		});

		$('.'+inputBoxClass).blur(function () {
		    var text = $(this).val();
		    if (text == '') {
		        $(this).val(str);
		    }
		});
	}


// ------------------------------------------

	function newWindow(hrefClass)
	/*	#2
	 *	Author:			 	  
	 *	Date: 
	 *	Purpose: 	Opens a page in a new window... the validating way
	 *	Params: 	hrefClass: 	The href class of the link you want to open in a new window   			  
	 *	Example: 	
	 *		HTML code: 	   <a href="www.oberto.co.nz" class="new_window">link</a>	
	 *		Function call: newWindow('new_window');		
	 *
	 */
	{
		$(document).ready(function() {
			$('.'+hrefClass).click(function() {
				window.open($(this).attr('href'));
				return false;
			});	
		});	
	}

// ------------------------------------------

	function print(anyElementClass)
	/*	#3			UNTESTED
	 *	Author:			 	  
	 *	Date: 
	 *	Purpose: 	Prints.
	 *	Params: 	divClass: 	The class if the div you want to print   			  
	 *	Example: 	
	 */
	{
		$(document).ready(function() {	
			$('.'+anyElementClass).click(function() {
				window.print();
			});	
		});
	}	
	
// ------------------------------------------

	function confirmBox(message)
	/*	#4
	 *	Author: 	Jarrod Oberto
	 *	Date: 		
	 *	Purpose: 	Confirmation box
	 *	Params: 	message: 	Message to display on box
	 *				hrefClass: 	The href class of the link you want to open in a new window   			  
	 *	Example: 	
	 *		HTML code: 	   <a href="http://www.oberto.co.nz" class="confirm">link</a>	
	 *		Function call: confirmBox('Are you sure your want to open in a new window', 'confirm');		
	 *
	 */
	{
		
		$('.'+hrefClass).click(function(){
		  var anser = false;		
		  var answer = confirm(message);
		  return answer // answer is a boolean
		});
		
	

		
	}
	


/*

Site:
http://www.kriesi.at/archives/create-simple-tooltips-with-css-and-jquery

Example:
<a href="#" title="This is a small Tooltip with the Classname 'Tooltip'">Link</a>

Requires a newer version of jQuery. 1.2.2 was TOO old and would result in empty tool tip boes on anything that was a link
1.2.6 works a dream

.tooltip{
    position:absolute;
    z-index:999;
    left:-9999px;
    background-color:#dedede;
    padding:5px;
    border:1px solid #fff;
    width:250px; 
}

.tooltip p{
    margin:0;
    padding:0;
    color:#fff;
    background-color:#222;
    padding:2px 7px;
}


MORE EXAMPLES:

display image in tooltip
<div class="jtooltip">
 <a href="#" title="Display image in tooltip: <img src='/admin/_images/icons/info.gif'/>"> TEST </a>
</div>

NOTES: You don't have to use divs. Span, P should all work, too

*/

	function simple_tooltip(target_items, name){
	 $(target_items).each(function(i){
			$("body").append("<div class='"+name+"' id='"+name+i+"'><p>"+$(this).attr('title')+"</p></div>");
			var my_tooltip = $("#"+name+i);

			if($(this).attr("title") != ""){ // checks if there is a title

			$(this).removeAttr("title").mouseover(function(){
					my_tooltip.css({opacity:0.8, display:"none"}).fadeIn(400);
			}).mousemove(function(kmouse){
					my_tooltip.css({left:kmouse.pageX+15, top:kmouse.pageY+15});
			}).mouseout(function(){
					my_tooltip.fadeOut(400);
			});

			}
		});
	}

	$(document).ready(function(){
		// simple_tooltip(".magic a","tooltip");
		 simple_tooltip(".jtooltip a","tooltip");
	});

