/*
Author...: Rainner Lins ( http://rainnerlins.com/ ) 
Date.....: Apr 18 2011 
*/

/*
Common CSS Effects for Rounding and Adding DropShadows
*/

var CSSfx = {
	/* round all 4 edges */
	RoundAll : {
		'border-radius' : '8px',
		'-webkit-border-radius' : '8px',
		'-moz-border-radius' : '8px' 
	}, 
	/* round only top edges */
	RoundTop : {
		'-webkit-border-top-right-radius' : '8px', 
		'-webkit-border-top-left-radius' : '8px', 
		'-moz-border-radius-topright' : '8px', 
		'-moz-border-radius-topleft' : '8px', 
		'border-top-right-radius' : '8px', 
		'border-top-left-radius' : '8px', 
		'border-bottom' : '0' 
	}, 
	/* round only bottom edges */
	RoundBottom : {
		'-webkit-border-bottom-right-radius' : '8px', 
		'-webkit-border-bottom-left-radius' : '8px', 
		'-moz-border-radius-bottomright' : '8px', 
		'-moz-border-radius-bottomleft' : '8px', 
		'border-bottom-right-radius' : '8px', 
		'border-bottom-left-radius' : '8px', 
		'border-top' : '0' 
	}, 
	/* add default dropshadow */
	DropShadow : {
		'box-shadow' : '0 0 2px rgba(0,0,0,0.4)',
		'webkit-box-shadow' : '0 0 2px rgba(0,0,0,0.4)', 
		'-moz-box-shadow' : '0 0 2px rgba(0,0,0,0.4)'
	},
	/* add bigger dropshadow */
	DropShadowBig : {
		'box-shadow' : '0 8px 8px rgba(0,0,0,0.3)',
		'webkit-box-shadow' : '0 8px 8px rgba(0,0,0,0.3)', 
		'-moz-box-shadow' : '0 8px 8px rgba(0,0,0,0.3)'
	} 
}; 

/*
Global site utilities that use jQuery to perform different tasks  
*/

var $utils = ( $utils ) ? $utils : null; 
(function( $ )
{
	if( !$ || $utils !== null ){ return; } 
	$utils = {}; 
	
	/* preset css styles for the current page using this file */ 
	$utils.PreCSS = { backgroundColor:"#fff", color:"#333" }; 
	
	/* jquery fn delay plugin */ 
	$.fn.delay = function( time, callback ) 
	{
		$.fx.step.delay = function(){};
		return this.animate( { delay:1 }, time, callback ); 
	}
	/* checks for a type or get some info */
	$utils.Is = function( w, s ) 
	{ 
		var wht = ( !w || w == '' ) ? '' : w; /* case to check for */
		var str = ( !s || s == '' ) ? '' : s; /* optional value */ 
		var agt = String( navigator.userAgent ).toLowerCase(); 
		var ver = String( navigator.appVersion ).toLowerCase(); 
		var app = String( navigator.appName ).toLowerCase(); 
		switch( wht )
		{
			/* OSes */
			case 'win':     return ( ver.indexOf("win") != -1 ) ? true : false; 
			case 'mac':     return ( ver.indexOf("mac") != -1 ) ? true : false; 
			/* browsers */
			case 'ie6':     return (/(msie 6)/i.test( agt )) ? true : false; 
			case 'firefox': return (/(firefox)/i.test( agt )) ? true : false; 
			case 'safari':  return (/(safari)/i.test( agt )) ? true : false; 
			case 'chrome':  return (/(chrome|google)/i.test( agt )) ? true : false; 
			case 'opera':   return (/(opera)/i.test( agt )) ? true : false; 
			/* strings */
			case 'ip':      return (/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}[[0-9\/]{2,3}]?$/i.test( str )) ? true : false; 
			case 'hex':     return (/^#([0-9a-f]{3}){1,2}$/i.test( str )) ? true : false; 
			case 'phone':   return (/^\d{3}(-| )\d{3}(-| )\d{4}$/.test( str )) ? true : false; 
			case 'email':   return (/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/.test( str )) ? true : false; 
			case 'url':     return (/((http[s]?|ftp):\/\/)(www\.)?([a-zA-Z0-9_-]+)\.([a-z0-9]+)([\b\w.\/&=?\-_~%+=;:,\#]+)?/i.test( str )) ? true : false; 
			case 'class':   return (/^.([a-zA-Z0-9_-]+)$/i.test( str )) ? true : false; 
			case 'id':      return (/^#([a-zA-Z0-9_-]+)$/i.test( str )) ? true : false; 
		}
		return false; 
	}; 
	/* calculate the position for a popup window based on it's size */ 
	$utils.PopPos = function( w, h, s ) 
	{
		var width  = ( w ) ? parseInt( w ) : 780; 
		var height = ( h ) ? parseInt( h ) : 420; 
		var scrl   = ( s ) ? 1 : 0; 
		var props  = { 
			name   : "Win_" + width  +"x" + height + "_px", 
			width  : width, 
			height : height, 
			left   : Math.floor( ( parseInt( $( window ).width() ) - width ) / 2 ), 
			top    : Math.floor( ( parseInt( $( window ).height() ) - height ) / 2 ), 
			params : String( "location=0, status=0, menubar=0, toolbar=0, scrollbars="+ scrl +", width="+ width +", height="+ height ) 
		}; 
		return props; 
	}; 
	/* pop open a new window */ 
	$utils.Pop = function( url, w, h, s ) 
	{
		var p     = $utils.PopPos( w, h, s ); 
		var windw = window.open( url, p.name, p.params ); 
		if( windw ){ windw.moveTo( p.left, p.top ); } 
	}; 
	/* print html object */ 
	$utils.Print = function( o ) 
	{
		var obj = $( o )[0] || null; 
		if( !obj ){ return false; }
		print( obj ); return true; 
	}; 
	/* convert a JSON string to an object */ 
    $utils.ParseJSON = function( str )
	{
		var e = { status:'error', info:'No valid JSON data to parse.' }; 
		if( !str || str === '' ){ return e; } 
		if( typeof str === 'object' ){ return str; } 
		if( typeof str !== 'string' ){ return e; } 
		if( JSON ){ return JSON.parse( str ); } 
		if( $.parseJSON ){ return $.parseJSON( str ); } 
		return e;  
	}	
	/* format a large number with points and commas */
	$utils.NumFormat = function( num )
	{
		if( !num ){ return; } num += ''; 
		x = num.split( '.' ); x1 = x[0]; x2 = x.length > 1 ? '.' + x[1] : ''; 
		var rgx = /(\d+)(\d{3})/;
		while( rgx.test( x1 ) ){ x1 = x1.replace( rgx, '$1' + ',' + '$2' ); } 
		return x1 + x2;
	};
	/* strip all whitespaces from a string */
    $utils.StripWhites = function( str )
	{
		str = str.replace( /\t/g, '' ); 
		str = str.replace( /\n/g, '' ); 
		str = str.replace( /\r/g, '' ); 
		str = str.replace( /\s/g, '' ); 
		return str; 
	}; 
	/* strip html tags from strings */
    $utils.StripTags = function( str )
	{ 
		str = ( !str ) ? '' : str.toString();  
		return $.trim( str.replace(/<\/?[^>]+>/gi, "" ) ); 
	}; 
	/* add a leading zero to numbers < 10 */ 
    $utils.AddZero = function( n ) 
	{
		return ( n < 10 ) ? '0'+n : n; 
	}; 
	/* remove any zeros from the beginning of a number */ 
    $utils.RemZero = function( n ) 
	{
		return n.replace( /^[0]+/, "" ); 
	}; 
	/* keep a number ranged from 0 - 100 */ 
    $utils.NumRange = function( n ) 
	{
		n = ( n > 100 ) ? 100 : n; 
		n = ( n < 0 ) ? 0 : n; 
		return n; 
	}; 
	/* pause script execution for a short time */ 
    $utils.Pause = function( millisecs ) 
	{
		var active = true; 
		var now = new Date();
		var exitTime = now.getTime() + millisecs; 
		while( active ) 
		{
			now = new Date();
			if( now.getTime() > exitTime ){ active = false; } 
		}
	}; 
	/* get a random string or number by specified length */ 
    $utils.RandStr = function( len, n )
	{
		var f = "";
		var nums = "0123456789";
		var alfs = "0123456789_abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ.";
		var n = ( len && len > 2 ) ? ( len - 1 ) : 9; 
		var l = ( n === true ) ? nums.split("") : alfs.split(""); 
		for( var i=0; i < n; i++ ){ f += l[Math.floor(Math.random() * l.length)]; } 
		return String( f ); 
	}; 
	/* get a random hex color */
    $utils.HexStr = function()
	{
		var o = "";
		var k = 0; 
		var a = new Array( "0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F" ); 
		for( var i=0; i < 6; i++ ){ k = Math.round( Math.random() * a.length ) - 1; o += a[k]; }
		return "#" + o; 
	}; 
	/* make a string shorter to a specified length */ 
    $utils.ShortStr = function( str, l ) 
	{
		if( str && str.length > 2 ) 
		{
			str = $utils.StripTags( str ); 
			str = str.replace( /(\n|\s\s)/gi, " ", str ); 
			str = ( l && str.length > l ) ? str.substring( 0, l )+".." : str; 
		}
		return str;
	}; 
	/* convert a title to a key string */ 
    $utils.KeyStr = function( str, l ) 
	{
		if( str && str.length ) 
		{
			str = $utils.StripTags( str ); 
			str = str.toLowerCase(); 
			str = str.replace( /[^a-zA-Z0-9 ]+/g, '' ); 
			str = str.replace( /\n+/g, '' ).replace( /^\s*/, '' ).replace(/\s*$/, '' ).replace( /\s+/g, '-' ); 
			str = ( l && str.length > l ) ? str.substring( 0, l ) : str; 
		}
		return str;
	}; 
	/* get all the dimensions of the window and document */ 
	$utils.GetSizes = function()
	{
		var WIN  = window; 
		var BODY = document.body;
		var DOC  = document.documentElement; 
		var OUT  = {}; 
		OUT.scroll_left = 0; 
		OUT.scroll_top  = 0;  
		OUT.win_width   = 0; 
		OUT.win_height  = 0;  
		OUT.doc_width   = 0; 
		OUT.doc_height  = 0; 
		
		if( WIN && WIN.scrollMaxY > OUT.doc_height ) 
		{
			OUT.scroll_left = parseInt( WIN.pageXOffset ) || 0; 
			OUT.scroll_top  = parseInt( WIN.pageYOffset ) || 0;  
			OUT.win_width   = parseInt( WIN.innerWidth ) || 0;  
			OUT.win_height  = parseInt( WIN.innerHeight ) || 0; 
			OUT.doc_width   = parseInt( WIN.scrollMaxX ) || 0;  
			OUT.doc_height  = parseInt( WIN.scrollMaxY ) || 0;  
		}
		if( BODY && BODY.scrollHeight > OUT.doc_height ) 
		{
			OUT.scroll_left = parseInt( BODY.scrollLeft ) || 0;  
			OUT.scroll_top  = parseInt( BODY.scrollTop ) || 0;  
			OUT.win_width   = parseInt( BODY.clientWidth ) || 0;  
			OUT.win_height  = parseInt( BODY.clientHeight ) || 0;  
			OUT.doc_width   = parseInt( BODY.scrollWidth ) || 0; 
			OUT.doc_height  = parseInt( BODY.scrollHeight ) || 0;  
		}
		if( DOC && DOC.scrollHeight > OUT.doc_height ) 
		{
			OUT.scroll_left = parseInt( DOC.scrollLeft ) || 0;  
			OUT.scroll_top  = parseInt( DOC.scrollTop ) || 0;  
			OUT.win_width   = parseInt( DOC.clientWidth ) || 0;  
			OUT.win_height  = parseInt( DOC.clientHeight ) || 0;  
			OUT.doc_width   = parseInt( DOC.scrollWidth ) || 0;  
			OUT.doc_height  = parseInt( DOC.scrollHeight ) || 0; 
		}
		OUT.max_up   = 0; 
		OUT.max_down = Math.floor( OUT.doc_height - OUT.win_height ); 
		OUT.max_down = ( OUT.max_down < 0 ) ? 0 : OUT.max_down; 
		return OUT; 
	}; 
	/* get the current mouse position */ 
    $utils.GetMouse = function( e ) 
	{
		var f = { x:0, y:0 }; 
		if( !e ){ e = window.event; }
		if( !e || (typeof e.pageX != "number" && typeof e.clientX != "number") ){ return f; } 
		f.x = (typeof e.clientX === "number") ? e.clientX : e.pageX; 
		f.y = (typeof e.clientY === "number") ? e.clientY : e.pageY; 
		if( document.documentElement && ( document.documentElement.scrollTop || document.documentElement.scrollLeft ) ) 
		{
			f.x += document.documentElement.scrollLeft; 
			f.y += document.documentElement.scrollTop;
		} 
		else if( document.body && ( document.body.scrollTop || document.body.scrollLeft ) ) 
		{
			f.x += document.body.scrollLeft; 
			f.y += document.body.scrollTop;
		}
		return f;
	}; 
	/* get object/s by specified string, or keep existing one */ 
	$utils.ObjGet = function( obj ) 
	{ 
		var classes = function( name )
		{
			var a = new Array(); 
			var e = ( document.getElementsByTagName ) ? document.getElementsByTagName( "*" ) : document.all; 
			for( i=0; i < e.length; i++ ){ if( e[i].className === name ){ a.push( e[i] ); } }     
			return a; 
		}
		if( !obj ){ return null; }
		if( typeof obj !== "string" ){ return obj; } /*keep same*/ 
		if( /^\./.test( obj ) ){ obj = obj.replace('.',''); return classes( obj ); } /*class names array*/ 
		if( /^\#/.test( obj ) ){ obj = obj.replace('#',''); return document.getElementById( obj ); } /*id name single*/ 
		if( /^\</.test( obj ) ){ obj = obj.replace('<',''); return document.getElementsByTagName( obj ); } /*tag name array*/ 
		if( /^(body|root|firstchild|doc[ument]?)$/.test( obj ) ){ return document.getElementsByTagName("body")[0]; } /*body tag single*/ 
		obj = document.getElementById( obj ) || null; /*all else*/ 
		return ( obj ) ? obj : null; 
	}; 
	/* creates a new DOM object: ( 'TagName', 'IdName', 'Styles or Class' ) */ 
	$utils.ObjMake = function( tag, id, s ) 
	{
		if( !tag || !id ){ return null; } 
		var elm = null; 
		var obj = document.getElementById( id ); 
		if( obj ){ return obj; } 
		elm = document.createElement( tag ); 
		obj = document.getElementsByTagName( "body" )[0].appendChild( elm ); 
		obj.setAttribute( "id", String( id ) ); 
		if( !obj ){ return null; } 
		if( s && typeof s === "string" ){ obj.className = s; }
		if( s && typeof s === "object"){ $( obj ).css( s ); } 
		return obj; 
	}; 
	/* remove an object */ 
	$utils.ObjRemove = function( obj, fade ) 
	{
		if( !obj ){ return; } 
		if( fade ){ $( obj ).fadeTo( 'slow', 0, function(){ $( this ).remove(); } ); } 
		else{ $( obj ).remove(); } 
	};  
	/* center a floating object on the page */
	$utils.ObjCenter = function( o ) 
	{
		var e = $( o ); 
		if( !e || !e.length ){ return; } 
		var s = $utils.GetSizes(); 
		var w = parseInt( e[0].offsetWidth ) || 0; 
		var h = parseInt( e[0].offsetHeight ) || 0; 
		var x = Math.round( s.scroll_left + ( s.win_width - w ) / 2 ); 
		var y = Math.round( s.scroll_top + ( s.win_height - h ) / 2 ); 
		w = 0 - Math.round( w / 2 ); 
		y = ( y <= 2 ) ? 2 : y; 
		e.css( { 'position':'absolute', 'z-index':'9999', 'left':'50%', 'top':y+'px', 'margin-left':w+'px' } ); 
	};  
	/* change the dimenssions of an object */
	$utils.ObjSize = function( o, w, h, s, c ) 
	{
		var e = $( o )
		if( !e || !e.length || e[0].isMoving ){ return; } 
		if( !w && !h ){ return; } 
		if( e[0].si ){ clearInterval( e[0].si ); } 
		e[0].isMoving = true; 
		e[0].si = setInterval( function()
		{ 
			var oW = parseFloat( e.width() || e[0].offsetWidth ); 
			var oH = parseFloat( e.height() || e[0].offsetHeight );  
			var nW = Math.ceil( oW + (w - oW) / 4 ); 
			var nH = Math.ceil( oH + (h - oH) / 4 ); 
			e.css( { 'overflow':'hidden', 'width':nW+'px', 'height':nH+'px' } ); 
			if( s ){ $utils.ObjCenter( e ); } 
			if( oW == nW && oH == nH )
			{
				clearInterval( e[0].si ); 
				e[0].isMoving = false; 
				if( typeof c === 'function' ){ c( nW, nH ); } 
			}
		}, 30 ); 
	}; 
	/* preview all the objects/methods within an object */ 
	$utils.ObjExpose = function( obj )
	{
		if( !obj || typeof obj !== 'object' ){ return; } 
		var n,f=''; for( n in obj ){ f += n + ': ' + obj[n] + " \n"; } alert( f );
	}; 
	/* dim and block the display state of the page */
	$utils.DimScreen = function( state, clk, cb ) 
	{
		var o = $( $utils.ObjMake( 'div', 'full-screen-dim-div' ) ); 
		var s = $utils.GetSizes(); 
		var h = s.doc_height + "px"; 
		var t = { display:"none", position:"absolute", backgroundColor:"#000", margin:"0", padding:"0", top:"0", left:"0", width:"100%", height:h, opacity:0, zIndex:"998" }; 
		 
		if( !o || !o.length ){ return; } 
		if( /^(show|init|make|dim|block)$/i.test( state ) )
		{ 
			if( o[0].isActive ){ return; } o[0].isActive = true; 
			if( clk ){ o.bind( 'click', function(){ $utils.DimScreen( 'hide', true ); } ); } 
			o.css( t ).css( { display:'block' } ).fadeTo( 400, 0.60, cb ); 
		}
		else
		{ 
			if( clk ){ o.unbind( 'click' ); } 
			o.fadeTo( 800, 0, function(){ o.css( { display:'none' } ) } ); 
			o[0].isActive = false; 
		}
	}; 
	/* dim the page and prevent interactions */
	$utils.PageBlock = function( msg, abort, opt ) 
	{
		var m = ( msg ) ? msg.toString() : '..WORKING..'; 
		var a = ( abort ) ? true : false; 
		var o = $utils.ObjMake( 'div', 'full-screen-dim-warnbox' ); 
		var d = '<div style="padding:10px; text-align:center; font-weight:bold; line-height:normal;">'+m+'<\/div>'; 
		var t = { 
			'display'    : 'block', 
			'position'   : 'fixed', 
			'background' : '#f0f0f0', 
			'color'      : '#202020', 
			'width'      : '200px', 
			'height'     : 'auto', 
			'left'       : '50%', 
			'top'        : '48%', 
			'margin'     : '0 0 0 -100px', 
			'overflow'   : 'hidden', 
			'z-index'    : '999'
		}; 
		if( !o ){ return; } 
		$.extend( t, CSSfx.RoundAll ); 
		$.extend( t, CSSfx.DropShadowBig ); 
		if( typeof opt === 'object' ){ $.extend( t, opt ); } 
		$utils.DimScreen( 'show', a );  
		$( o ).html( d ).css( t );  
	}
	/* scrolls the page to a specified number, string, or object */ 
	$utils.Scroll = function( to, cb )
	{
		var S     = $utils.GetSizes(); 
		var Top   = 0; 
		var Bot   = S.max_down; 
		var Left  = $(window).scrollLeft() || 0; 
		var Cur   = $(document).scrollTop() || 0; 
		var New   = parseInt( to ) || 0; 
		var Dir   = "";  
		// 
		//$utils.ObjExpose( S ); 
		//return; 
		//
		if( typeof to  === 'number' || /^([0-9]+)$/.test( to ) ){ New = Math.round( parseInt( to ) ); } else 
		if( typeof to  === 'object' ){ New = $( to ).offset().top || 0; } else 
		if( typeof to  === 'string' ) 
		{
			if( /^(top|up|first|head[er]?)$/i.test( to ) ){ New = Top; } else 
			if( /^(bottom|down|last|foot[er]?)$/i.test( to ) ){ New = Bot; } else 
			if( /^(middle|center|half)$/i.test( to ) ){ New = Math.round( Bot / 2 ); } 
			else { New = $( document.getElementById( to ) ).offset().top || 0; } 
		}
		New = ( !New ) ? 0 : New; 
		New = ( New < 0 ) ? 0 : New; 
		New = ( New > Bot ) ? Bot : New; 
		Dir = ( New > Cur ) ? "down" : "up"; 
		$( 'html,body' ).stop().animate( { scrollTop:New }, 1000, 'easeInOutExpo' ); 
	}; 
	/* creates a notice bar at the top for displaying messages. */ 
	$utils.Notice = function( a, c, t, s ) 
	{
		var spd     = 400; 
		var dly     = 3000; 
		var act     = ( !a || a === '' ) ? 'hide'    : a; 
		var cls     = ( !c || c === '' ) ? 'default' : c; 
		var txt     = ( !t || t === '' ) ? '&nbsp;'  : t; 
		var bar     = $( $utils.ObjMake( 'div', 'top-notice-bar-div' ) ); 
		var inner   = '<div style="margin:0; padding:10px; font-weight:bold;">' + txt + '<\/div>'; 
		var stl     = { 'display':'block', 'position':'fixed', 'width':'100%', 'top':'-60px', 'text-align':'center', 'z-index':'996' }; 
		var theme   = { 'background':"#666", 'color':"#fff" }; 
		//
		if( /^(red|error|fail[ed]?|deny|denied)$/i.test( cls ) ) { theme = { 'background':"#bb221b", 'color':"#fff" }; }  /* red */
		if( /^(yellow|warn[ing]?|notice|notify)$/i.test( cls ) ) { theme = { 'background':"#ffb20c", 'color':"#111" }; }  /* yellow */
		if( /^(blue|info[rmation]?|about)$/i.test( cls ) )       { theme = { 'background':"#0088d1", 'color':"#fff" }; }  /* blue */
		if( /^(green|ok|success|pass[ed]?)$/i.test( cls ) )      { theme = { 'background':"#83ae00", 'color':"#fff" }; }  /* green */
		if( /^(white|bright)$/i.test( cls ) )                    { theme = { 'background':"#fefefe", 'color':"#111" }; }  /* white */
		if( /^(black|dark)$/i.test( cls ) )                      { theme = { 'background':"#101010", 'color':"#eee" }; }  /* black */
		//
		if( !bar || !bar.length ){ return; }
		if( typeof s === 'object' ){ $.extend( theme, s ); } 
		if( act === 'show' )
		{
			$.extend( theme, CSSfx.RoundBottom );
			$.extend( theme, CSSfx.DropShadowBig );
			bar
			.css( stl )
			.css( theme )
			.html( inner )
			.bind( 'click', function(){ $utils.Notice( 'hide' ); } )
			.stop()
			.animate( { top:"0" }, spd, 'easeOutExpo', function()
			{
				if( bar[0].sto ){ clearTimeout( bar[0].sto ); } 
				bar[0].sto = setTimeout( function(){ $utils.Notice( 'hide' ); }, dly ); 
			}); 
		} 
		else 
		{
			bar.stop().animate( { top:"-60px" }, spd, 'easeInExpo', function()
			{
				if( bar[0].sto ){ clearTimeout( bar[0].sto ); } 
				bar.attr( 'class', 'grey' ).unbind( 'click' ); 
			}); 
		}
	}; 
	/* trigger default browser UI bookmarker */
	$utils.Bookmark = function( u, t ) 
	{
		var app = ( navigator.appName ) ? String( navigator.appName.toString() ) : null; 
		var ver = ( navigator.appVersion ) ? parseInt( navigator.appVersion ) : 0; 
		var url = ( u ) ? u : window.location.href; 
		var ttl = ( t ) ? t : document.title; 
		//
		if( !url || !ttl ){ $utils.Notice( 'show', 'warn', 'Bookmark Error: Could not get page information.' ); return; }
		if( app === "Microsoft Internet Explorer" && ver >= 4 ){ window.external.AddFavorite( url, ttl ); } 
		else if( app === "Netscape" ){ window.sidebar.addPanel( ttl, url, "" ); } 
		else{ $utils.Notice( 'show', 'warn', 'Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark.' ); } 
	}; 
	/* creates a text based ticker on an object from an array */
	$utils.Ticker = function( obj, items, opts ) 
	{
		var conf   = { delay:5, speed:300 }; 
		var target = ( typeof obj === 'string' ) ? document.getElementById( obj ) : obj; 
		var total  = ( items && items.length ) ? items.length : 0; 
		var num    = 0; 
		var fnc    = null; 
		//
		if( !target || !total ){ alert( 'error' ); return; } 
		if( typeof opts === 'object' ){ $.extend( conf, opts ); } 
		// 
		fnc = function()
		{
			if( target.sto ){ clearTimeout( target.sto ); } 
			target.sto = setTimeout( fnc, ( conf.delay * 1000 ) ); 
			var str = items[ num ] + ' ' + ( num + 1 ) + '/' + total;  
			$( target ).css( { opacity:0 } ).html( str ).stop().animate( { opacity:1 }, conf.speed, 'linear' ); 
			num = ( num >= ( total - 1 ) ) ? 0 : ( num + 1 ); 
		}
		fnc(); 
	}; 
	/* show a confirm or alert box with dimmed background and fires a callback function */ 
	$utils.Warn = function( type, str, cb ) 
	{
		var r = false; 
		$utils.DimScreen( 'show' ); 
		if( type == "confirm" ){ r = confirm( str ) ? true : false; } 
		else{ r = true; alert( str ); } 
		$utils.DimScreen( 'hide' ); 
		return r; 
	}; 
	/* change the display class and text for a selected object */ 
	$utils.Txt = function( obj, cls, str )
	{
		if( !obj ){ return; }
		$( obj ).attr( 'class', cls ).text( str ); 
	}; 
	/* calculate the time it took for the page to load */ 
	$utils.LoadTime = function( start, obj )
	{
		if( !start ){ return; } 
		var end    = new Date().getTime(); 
		var total  = ( end - start ) / 1000; 
		var final  = Math.round( total * 100 ) / 100; 
		var target = $utils.ObjGet( obj ); 
		if( target ){ target.innerHTML = final; } 
		else{ alert( 'Page Load Time: ' + final + ' seconds.' ); } 
	}; 
	/* open a pop-up to share a page on twitter or facebook */ 
	$utils.Share = {
		/* on Twitter */
		Twitter: function( url, text )
		{
			var u = ( url )  ? encodeURIComponent( url )  : encodeURIComponent( top.location.href ); 
			var t = ( text ) ? encodeURIComponent( text ) : encodeURIComponent( document.title ); 
			var p = $utils.PopPos( 600, 425 ); 
			var w = window.open( 'http://twitter.com/share?&url='+u+'&text='+t, p.name, p.params ); 
			if( w ){ w.moveTo( p.left, p.top ); }else{ alert( 'Please allow pop-ups for this feature to work.' ); } 
		}, 
		/* on Facebook */
		Facebook: function( url, text )
		{
			var u = ( url )  ? encodeURIComponent( url )  : encodeURIComponent( top.location.href ); 
			var t = ( text ) ? encodeURIComponent( text ) : encodeURIComponent( document.title ); 
			var p = $utils.PopPos( 600, 425 ); 
			var w = window.open( 'http://facebook.com/sharer.php?u='+u+'&t='+t, p.name, p.params ); 
			if( w ){ w.moveTo( p.left, p.top ); }else{ alert( 'Please allow pop-ups for this feature to work.' ); } 
		}, 
	}; 
})( jQuery ); 

/*
Apply different functionalities to form elements
*/

var $forms = ( $forms ) ? $forms : null; 
(function( $ )
{
	if( !$ || !$utils || $forms !== null ){ return; } 
	$forms = {}; 
	
	/* preset css styles for the current page using this file */ 
	$forms.PreCSS = { backgroundColor:"#fff", color:"#333" }; 
	
	/* checks data types of input elements before submission */
	$forms.check = function( type, obj, data ) 
	{
		var host = window.location.hostname; 
		var val = obj.value; 
		var len = obj.value.length; 
		// 
		if( !data && type == "length" )                      { data = 1; } 
		if( !data && type == "text" )                        { data = ""; }  
		if( /^([a-zA-Z0-9\ _-]+)\.{2,3}$/i.test( val ) )     { return false; }
		if( type == "length" &&  len < data )                { obj.focus(); return false; }
		if( type == "text"   &&  val == data )               { obj.focus(); val=""; return false; } 
		if( type == "phone"  && !$utils.Is( type, val ) )    { obj.focus(); return false; }
		if( type == "url"    && !$utils.Is( type, val ) )    { obj.focus(); return false; }
		if( type == "hex"    && !$utils.Is( type, val ) )    { obj.focus(); return false; }
		if( type == "email"  && !$utils.Is( type, val ) )    { obj.focus(); return false; } 
		if( type == "domain" &&  val.indexOf( host ) != -1 ) { obj.focus(); return false; } 
		return true; 
	}; 
	/* insert some html code into a form element */
	$forms.html = function( field, type ) 
	{
		var a = new Array(); 
		var f = ( typeof field === 'string' ) ? document.getElementById( field ) : field; 
		var s = ''; 
		// 
		if( !f || !type ){ return; } 
		s = String( f.value.toString() ); 
		// 
		if( /^(link|url|website|host)$/.test( type ) )
		{
			a['link'] = String( prompt( "Web URL:", "http://" ) || "" ); 
			a['name'] = String( prompt( "Display Name:", a['link'] ) || "" );  
			if( a['link'].length > 7 && a['name'].length > 1 ) 
			{
				f.value = s + '<a href="'+a['link']+'" target="_blank">'+a['name']+'</a>'; 
			}
		}
		if( /^(image|photo|picture)$/.test( type ) )
		{
			a['link'] = String( prompt( "Source File/URL:", "http://" ) || "" ); 
			a['size'] = parseFloat( prompt( "Width Pixels:", "200" ) || "200" );  
			if( a['link'].length > 7 && a['size'] ) 
			{
				f.value = s + '<img src="'+a['link']+'" width="'+a['size']+'" alt="" />'; 
			}
		}
	}
	/* creates a custom drop-down select menu for regular input fields */
	$forms.drop = function( field, list ) 
	{
		var i   = 0; 
		var fld = $( field ) || null; 
		var div = $utils.ObjMake( 'div', 'select-menu-div' ); 
		var pos = { x:0, y:0, w:0, h:0 };  
		var pfx = 'select-drop-link-'; 
		var hgt = ( list.length > 10 ) ? '206px' : 'auto'; 
		var tmp = ''; 
		var boxcss = { 
			'position'    : 'absolute', 
			'margin'      : '0', 
			'padding'     : '0', 
			'left'        : '0', 
			'top'         : '0', 
			'background'  : '#101418', 
			'zIndex'      : '997', 
			'opacity'     : '0' 
		};  
		var lnkcss = { 
			'display'     : 'block',  
			'margin'      : '0 0 1px 0',  
			'padding'     : '4px 6px',  
			'background'  : 'rgba(0,0,0,0.1)',  
			'font-family' : '"Courier New", Courier, monospace', 
			'font-size'   : '11px', 
			'line-height' : 'normal'
		}; 
		//
		if( !fld || !list || !div ){ return; } 
		if( !div.isinit )
		{
			div.isinit = true; 
			$.extend( boxcss, CSSfx.RoundBottom ); 
			$.extend( boxcss, CSSfx.DropShadowBig ); 
			$.extend( boxcss, $forms.PreCSS );  
			$( div ).css( boxcss ); 
		}
		//
		div.p = 12; 
		div.w = ( fld.outerWidth() - div.p ); 
		div.h = fld.outerHeight(); 
		div.x = Math.round( fld.offset().left + ( div.p / 2 ) ); 
		div.y = Math.round( fld.offset().top + div.h ); 
		//
		tmp = '<div style="display:block; margin:0; padding:4px;">'; 
			tmp += '<div id="select-menu-list" style="margin:0; padding:0; height:'+hgt+'; overflow:auto;">'; 
				for( i=0; i < list.length; ++i )
				{ 
					if( String( list[i].innerHTML ).length < 2 ){ continue; } 
					tmp += '<a id="'+pfx+i+'" href="#">'+list[i].innerHTML+'<\/a>'; 
				} 
			tmp += '<\/div>'; 
		tmp += '<\/div>';
		//
		$( div ).html( tmp ).css( { 'left': div.x+'px', 'top': div.y+'px', 'width': div.w+'px' } ).fadeTo( 200, 1 );  
		// 
		for( i=0; i < list.length; ++i )
		{
			$( document.getElementById( pfx + i ) ).attr( 'name', i ).css( lnkcss ).unbind( 'click' ).bind( 'click', function() 
			{ 
				list.selectedIndex = parseInt( this.name ); 
				field.value = this.innerHTML; 
				return false; 
			}); 
		}
		fld.attr( 'readonly','readonly' ).unbind( 'blur' ).bind( 'blur', function()
		{ 
			$( div ).fadeTo( 400, 0, function(){ $( this ).css( { left:'-3000px', top:'0' } ); } ); 
		}); 
	}; 
	/* setup custom form styles and functions based on class or name */
	$.fn.setupforms = function( opt ) 
	{
		return this.each(function() 
		{
			var THIS = $( this ); 
			var cls  = String( THIS.attr( 'class' ) || "" ).toLowerCase(); 
			var nam  = String( THIS.attr( 'name' )  || "" ).toLowerCase(); 
			var dta  = String( THIS.attr( 'value' ) || THIS.html() ); 
			var ckr  = ''; 
			var stl  = {}; 
			// 
			$.extend( stl, CSSfx.RoundAll );
			if( typeof opt === 'object' ) { $.extend( stl, opt ); } 
			THIS.css( stl ); 
			
			// try to detect the type of data required by looking at the field name 
			if( /^([e\-]?mail)$/i.test( nam ) )          { ckr = 'email'; } 
			if( /^([cell]?phone|mobile)$/i.test( nam ) ) { ckr = 'phone'; } 
			if( /^(link|url|[web]?site)$/i.test( nam ) ) { ckr = 'url'; } 
			
			// add clear-on-focus effect to specified fields by className 
			if( cls === 'focus' ) 
			{
				THIS.focus( function(){ if( dta.length > 2 && this.value === dta ){ this.value = ''; } } ); 
				THIS.blur( function(){ if( this.value.length < 1 ){ this.value = dta; } } ); 
			}
			// change plain text to dotted password field 
			if( cls === 'password' ) 
			{
				THIS.focus( function(){ if( this.value.toLowerCase() === 'password' ){ this.value = ''; } this.type = 'password'; } );  
				THIS.blur( function(){ if( this.value.length < 1 ){ this.type = 'text'; this.value = 'Password'; } } ); 
			}
			// keep textareas small to save space unless you click on them 
			if( cls === 'autosize' ) 
			{
				THIS.focus( function(){ $( this ).css( { 'overflow':'auto' } ).stop().animate( { height:'320px' }, 400, 'easeOutExpo' ); } ); 
				THIS.blur( function(){ $( this ).css( { 'overflow':'hidden' } ).stop().animate( { height:'120px' }, 400, 'easeOutExpo' ); } ); 
			}
			// make custom select menu forms engage on focus 
			if( cls === 'select' && typeof( THIS[0].onclick ) === 'function' ) 
			{
				THIS.focus( this.onclick ); 
			}
			// hide the default file inputs and add onChange event 
			if( cls === 'file' || cls === 'browse' ) 
			{
				THIS.css( 'opacity', 0 ); 
				THIS.change(function()
				{ 
					if( this.value.length > 1 )
					{ 
						$( this ).parent().css( { 'background-position' : 'right bottom' } ); 
						$utils.Notice( 'show', 'ok', 'File Selected: ( ' + this.value + ' )' ); 
					} 
				}); 
			}
			// add text color checker to field text onKeyUp 
			if( ckr !== '' )
			{
				THIS.keyup( function( e )
				{
					if( !$forms.check( ckr, this ) ){ $( this ).css( 'color', '#f30' ); } 
					else{ $( this ).css( 'color', '#0f3' ); } 
				}); 
			}
		}); 
	};
})( jQuery ); 

/*
A very simple jQuery plugin for making tooltips
*/

(function( $ )
{
	if( !$ ){ return; } 
	var $tooltip = function() 
	{
		var elm = null; 
		var obj = document.getElementById( "tooltip-div" ) || null; 
		if( obj ){ return obj; } 
		elm = document.createElement( "div" ); 
		obj = document.getElementsByTagName( "body" )[0].appendChild( elm ); 
		$( obj ).attr( "id", "tooltip-div" ); 
		return ( obj ) ? obj : null; 
	}
	$.fn.tooltip = function( opt ) 
	{  
		var doc = document.body; 
		var win = window; 
		var tip = $( $tooltip() ); 
		var stl = { 
			/* basic tooltip setup */
			'position'         : "absolute", 
			'display'          : "inline", 
			'left'             : "1px", 
			'top'              : "1px", 
			'font-family'      : "Courier New, Courier, monospace",  
			'font-size'        : "11px", 
			'line-height'      : "normal", 
			'background-color' : "#000", 
			'border'           : "2px solid #202429", 
			'color'            : "#ffc", 
			'text-align'       : "center", 
			'padding'          : "6px 12px", 
			'margin'           : "0", 
			'z-index'          : "9999",  
			'cursor'           : 'pointer', 
			'opacity'          : 0
		}; 
		$.extend( stl, CSSfx.RoundAll ); 
		$.extend( stl, CSSfx.DropShadowBig );
		if( typeof opt === 'object' ) { $.extend( stl, opt ); } 
		if( !tip || !tip.length ){ alert( "Make sure to initialize the tooltip() function after the page has loaded." ); return; } 
		if( opt ) { $.extend( stl, opt ); } 
		tip.css( stl ); 
		//
		var mov = function( e ) 
		{
			var t = ( e.pageY - $( document ).scrollTop() ); 
			var w = tip.width() + 20; 
			var h = tip.innerHeight() + 10; 
			var x = e.pageX - Math.round( w / 2 ); 
			var y = ( t < 50 ) ? ( e.pageY + h ) : ( e.pageY - h ); 
			tip.css( { left : x+'px', top : y+'px' } ); 
		}
		return this.each( function() 
		{
			var lnk = $( this ); 
			var str = lnk.attr( 'title' ); 
			if( /^(delete|remove|erase)$/i.test( str ) )
			{
				 lnk.bind( 'click', function()
				 { 
					 return confirm( 'Are you sure?' ); 
					 return false; 
				 }); 
			}
			lnk.removeAttr( 'title' ); 
			lnk.mouseover( function( e )
			{
				tip.stop().css( { opacity:0 } ).text( str ).fadeTo( 'fast', 0.86 ); 
				lnk.bind( 'mousemove', mov ); 
			}); 
			lnk.mouseout( function( e )
			{
				/* no fade-outs for snappiness, help with glitches */ 
				tip.text( '' ).css( { opacity : 0, left : '-9000px' } ); 
				lnk.unbind( 'mousemove' ); 
			}); 
		});
	};
})( jQuery ); 


