(function($){
	$.fn.jTruncate = function(options) {
	   
		var defaults = {
			length: 300,
			minTrail: 20,
			moreText: "more",
			lessText: "less",
			ellipsisText: "...",
			moreAni: "",
			lessAni: ""
		};
		
		var options = $.extend(defaults, options);
	   
		return this.each(function() {
			obj = $(this);
			var body = obj.html();
			
			if(body.length > options.length + options.minTrail) {
				var splitLocation = body.indexOf(' ', options.length);
				if(splitLocation != -1) {
					// truncate tip
					var splitLocation = body.indexOf(' ', options.length);
					var str1 = body.substring(0, splitLocation);
					var str2 = body.substring(splitLocation, body.length - 1);
					obj.html(str1 + '<span class="truncate_ellipsis">' + options.ellipsisText + 
						'</span>' + '<span class="truncate_more">' + str2 + '</span>');
					obj.find('.truncate_more').css("display", "none");
					
					// insert more link
					obj.append(
						'<div class="clearboth">' +
							'<a href="#" class="truncate_more_link">' + options.moreText + '</a>' +
						'</div>'
					);

					// set onclick event for more/less link
					var moreLink = $('.truncate_more_link', obj);
					var moreContent = $('.truncate_more', obj);
					var ellipsis = $('.truncate_ellipsis', obj);
					moreLink.click(function() {
						if(moreLink.text() == options.moreText) {
							moreContent.show(options.moreAni);
							moreLink.text(options.lessText);
							ellipsis.css("display", "none");
						} else {
							moreContent.hide(options.lessAni);
							moreLink.text(options.moreText);
							ellipsis.css("display", "inline");
						}
						return false;
				  	});
				}
			} // end if
			
		});
	};
})(jQuery);

// thanks to:  http://blog.nemikor.com/category/jquery-ui/jquery-ui-dialog/
// thanks to:  http://elijahmanor.com/post/jQuery-UI-Dialog-w-Resizable-iFrame.aspx


// Basically works... 
// Need to fix the iframe option 
// I think maybe it is working now....
(function() {
	$.fn.myModal = function(options){
		//$.fx.speeds._default = 1000;
		
		var $loading = $('<img src="/clientsites/app.side-out.org/img/loader_large_blue.gif" class="loading" alt="Loading..." />');


		
		//var docTitle=document;
		
			var defaults = {
				autoOpen: true,
				width: 800,
				height: 500,
				modal: true,
				resizable: false,
				autoResize: false,
				show: '',
				hide: '',
				title: '',
				open: function(event, ui) { $(".ui-dialog-titlebar-close").hide();},  // hide the 'x' close in top right
				//buttons: {'Close': function() {$(this).dialog('close');}},
				buttons: {'Close': function() {$(this).dialog('destroy');$('div').remove('#myModal');}},
				overlay: '',
				speed:0,
				closeOnEscape: false,
				//position: [100,50],
				position: 'center',
				close: '',
				myEvent: 'click',
				myIframe: false,
				myUrl:''
				//option:optionName , [value]
				
			};
			
			var options = $.extend(defaults, options);
			var $dialog = $('<div id="myModal"></div>').append($loading.clone());
			
			$.fx.speeds._default = options.speed;


if(!options.myIframe){
	if(options.myEvent=='click'){
		$(this).each(function() {
			var $link = $(this).click(function(e) {
				e.preventDefault();
				$dialog.load($link.attr('href')).dialog(options);	
				
				$link.click(function() {$dialog.dialog('open');
					return false;
				});
				
				return false;
			});
			
		});
	
	} else {
		$(this).each(function() {
			var $link = $(this).click(function(e) {
				e.preventDefault();
				//return false;
			});
			$dialog.load($link.attr('href')).dialog(defaults);
	
			$link.click(function() {$dialog.dialog('open');
			return false;
			});
			
		});
	} // end if

}else{
		if(options.myIframe){			
			var horizontalPadding = 15;
			var verticalPadding = 30;

			$(this).click(function(e) {
				e.preventDefault();

				$('<iframe id="externalSite" class="externalSite" src="' + this.href + '" />').dialog(options).width(options.width - horizontalPadding).height(options.height - verticalPadding);
			});
			if(options.myEvent=='auto'){
				$('<iframe id="externalSite" class="externalSite" src="' + options.myUrl + '" />').dialog(options).width(options.width - horizontalPadding).height(options.height - verticalPadding);
			}
		}
	};
}
})(jQuery);;




(function() {
	$.fn.myLoading = function(options){
		//$.fx.speeds._default = 1000;
		
		var $loading = $('<img src="/clientsites/app.side-out.org/img/loader_large_blue.gif" class="loading" alt="Loading..." />');


		
		//var docTitle=document;
		
		var defaults = {
			autoOpen: true,
			//autoOpen: false,	// set this to false so we can manually open it
			open: function(event, ui) { $(".ui-dialog-titlebar-close").hide();}, // hide the close 'x' in top right
			dialogClass: "",
			closeOnEscape: false,
			draggable: false,
			width: 460,
			minHeight: 50, 
			modal: true,
			buttons: {},
			resizable: false,
			close: ''
			
		};
		
		var options = $.extend(defaults, options);
		var $dialog = $('<div id="myLoading"><div class="x-dlg-hd">Processing...</div><div class="x-dlg-bd"><div class="x-dlg-tab" title=""><div class="inner-tab" style="font-size:1.25em; font-weight:800;"><img style="margin-right:15px;" src="images/loadingcolors.gif" border="0" />Please wait...</div></div></div></div>')
		//.append($loading.clone());
		
		$.fx.speeds._default = options.speed;

		$dialog.dialog(options);	

	};
})(jQuery);;




/*
Script Name: Javascript Cookie Script
Author: Public Domain, with some modifications
Script Source URI: http://techpatterns.com/downloads/javascript_cookies.php
Version 1.1.2
Last Update: 5 November 2009

Changes:
1.1.2 explicitly declares i in Get_Cookie with var
1.1.1 fixes a problem with Get_Cookie that did not correctly handle case
where cookie is initialized but it has no "=" and thus no value, the 
Get_Cookie function generates a NULL exception. This was pointed out by olivier, thanks
1.1.0 fixes a problem with Get_Cookie that did not correctly handle
cases where multiple cookies might test as the same, like: site1, site
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
*/

// this fixes an issue with the old method, ambiguous values 
// with this test document.cookie.indexOf( name + "=" );

// To use, simple do: Get_Cookie('cookie_name'); 
// replace cookie_name with the real cookie name, '' are required

// function Get_Cookie( check_name ) {
// 	// first we'll split this cookie up into name/value pairs
// 	// note: document.cookie only returns name=value, not the other components
// 	var a_all_cookies = document.cookie.split( ';' );
// 	var a_temp_cookie = '';
// 	var cookie_name = '';
// 	var cookie_value = '';
// 	var b_cookie_found = false; // set boolean t/f default f
// 	var i = '';
// 	
// 	for ( i = 0; i < a_all_cookies.length; i++ )
// 	{
// 		// now we'll split apart each name=value pair
// 		a_temp_cookie = a_all_cookies[i].split( '=' );
// 		
// 		
// 		// and trim left/right whitespace while we're at it
// 		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
// 	
// 		// if the extracted name matches passed check_name
// 		if ( cookie_name == check_name )
// 		{
// 			b_cookie_found = true;
// 			// we need to handle case where cookie has no value but exists (no = sign, that is):
// 			if ( a_temp_cookie.length > 1 )
// 			{
// 				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
// 			}
// 			// note that in cases where cookie is initialized but no value, null is returned
// 			return cookie_value;
// 			break;
// 		}
// 		a_temp_cookie = null;
// 		cookie_name = '';
// 	}
// 	if ( !b_cookie_found ) 
// 	{
// 		return null;
// 	}
// }



/*jslint browser: true */ /*global jQuery: true */

/**
 * jQuery Cookie plugin
 *
 * Copyright (c) 2010 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */

// TODO JsDoc

/**
 * Create a cookie with the given key and value and other optional parameters.
 *
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Set the value of a cookie.
 * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
 * @desc Create a cookie with all available options.
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Create a session cookie.
 * @example $.cookie('the_cookie', null);
 * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
 *       used when the cookie was set.
 *
 * @param String key The key of the cookie.
 * @param String value The value of the cookie.
 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
 *                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
 *                             If set to null or omitted, the cookie will be a session cookie and will not be retained
 *                             when the the browser exits.
 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
 *                        require a secure protocol (like HTTPS).
 * @type undefined
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */

/**
 * Get the value of a cookie with the given key.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String key The key of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
jQuery.cookie = function (key, value, options) {

    // key and value given, set cookie...
    if (arguments.length > 1 && (value === null || typeof value !== "object")) {
        options = jQuery.extend({}, options);

        if (value === null) {
            options.expires = -1;
        }

        if (typeof options.expires === 'number') {
            var days = options.expires, t = options.expires = new Date();
            t.setDate(t.getDate() + days);
        }

        return (document.cookie = [
            encodeURIComponent(key), '=',
            options.raw ? String(value) : encodeURIComponent(String(value)),
            options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
            options.path ? '; path=' + options.path : '',
            options.domain ? '; domain=' + options.domain : '',
            options.secure ? '; secure' : ''
        ].join(''));
    }

    // key and possibly options given, get cookie...
    options = value || {};
    var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
    return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};

// Examples
//   $(function() {
//                 var COOKIE_NAME = 'test_cookie';
//                 var ADDITIONAL_COOKIE_NAME = 'additional';
//                 var options = { path: '/', expires: 10 };
// 
//                 // set cookie by number of days
//                 $('a').eq(0).click(function() {
//                     $.cookie(COOKIE_NAME, 'test', options);
//                     return false;
//                 });
// 
//                 // set cookie by date
//                 $('a').eq(1).click(function() {
//                     var date = new Date();
//                     date.setTime(date.getTime() + (3 * 24 * 60 * 60 * 1000));
//                     $.cookie(COOKIE_NAME, 'test', { path: '/', expires: date });
//                     return false;
//                 });
// 
//                 // get cookie
//                 $('a').eq(2).click(function() {
//                     alert($.cookie(COOKIE_NAME));
//                     return false;
//                 });
// 
//                 // delete cookie
//                 $('a').eq(3).click(function() {
//                     $.cookie(COOKIE_NAME, null, options);
//                     return false;
//                 });
// 
//                 // set a second cookie
//                 $('a').eq(4).click(function() {
//                     $.cookie(ADDITIONAL_COOKIE_NAME, 'äöüß;foo=bar', { expires: 10 });
//                     return false;
//                 });
// 
//                 // get second cookie
//                 $('a').eq(5).click(function() {
//                     alert($.cookie(ADDITIONAL_COOKIE_NAME));
//                     return false;
//                 });
// 
//                 // delete second cookie
//                 $('a').eq(6).click(function() {
//                     $.cookie(ADDITIONAL_COOKIE_NAME, null);
//                     return false;
//                 });
//             });









/* #########################################################################################################################
############################################################################################################################
##########################################################################################################################*/









// 
// // THANKS TO:  http://techpatterns.com/downloads/javascript_cookies.php
// // FOR THIS COOKIE DETECTION SCRIPTD
// /*
// only the first 2 parameters are required, the cookie name, the cookie
// value. Cookie time is in milliseconds, so the below expires will make the 
// number you pass in the Set_Cookie function call the number of days the cookie
// lasts, if you want it to be hours or minutes, just get rid of 24 and 60.
// 
// Generally you don't need to worry about domain, path or secure for most applications
// so unless you need that, leave those parameters blank in the function call.
// */
// function Set_Cookie( name, value, expires, path, domain, secure ) {
// 	// set time, it's in milliseconds
// 	var today = new Date();
// 	today.setTime( today.getTime() );
// 	// if the expires variable is set, make the correct expires time, the
// 	// current script below will set it for x number of days, to make it
// 	// for hours, delete * 24, for minutes, delete * 60 * 24
// 	if ( expires )
// 	{
// 		expires = expires * 1000 * 60 * 60 * 24;
// 	}
// 	//alert( 'today ' + today.toGMTString() );// this is for testing purpose only
// 	var expires_date = new Date( today.getTime() + (expires) );
// 	//alert('expires ' + expires_date.toGMTString());// this is for testing purposes only
// 
// 	document.cookie = name + "=" +escape( value ) +
// 		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + //expires.toGMTString()
// 		( ( path ) ? ";path=" + path : "" ) + 
// 		( ( domain ) ? ";domain=" + domain : "" ) +
// 		( ( secure ) ? ";secure" : "" );
// }
// 
// // this deletes the cookie when called
// function Delete_Cookie( name, path, domain ) {
// 	if ( Get_Cookie( name ) ) document.cookie = name + "=" +
// 			( ( path ) ? ";path=" + path : "") +
// 			( ( domain ) ? ";domain=" + domain : "" ) +
// 			";expires=Thu, 01-Jan-1970 00:00:01 GMT";
// }
// 
// 
// // sample page usage
// /*
// 	<script type="text/javascript">
// 	// remember, these are the possible parameters for Set_Cookie:
// 	// name, value, expires, path, domain, secure
// 	Set_Cookie( 'test', 'it works', '', '/', '', '' );
// 	if ( Get_Cookie( 'test' ) ) alert( Get_Cookie('test'));
// 	// and these are the parameters for Delete_Cookie:
// 	// name, path, domain
// 	// make sure you use the same parameters in Set and Delete Cookie.
// 	Delete_Cookie('test', '/', '');
// 	( Get_Cookie( 'test' ) ) ? alert( Get_Cookie('test')) :
// 	alert( 'it is gone');
// 	</script>
// */	
// 
// 
// //////  End Cookie Detection Script  //////
// 
// 



// 
// // thanks to:  http://github.com/splendeo/jquery.observe_field
// // jquery.observe_field.js
// //
// 
// jQuery.fn.observe_field = function(frequency, callback) {
// 
//   return this.each(function(){
//     var element = $(this);
//     var prev = element.val();
// 
//     var chk = function() {
//       var val = element.val();
//       if(prev != val){
//         prev = val;
//         element.map(callback); // invokes the callback on the element
//       }
//     };
//     chk();
//     frequency = frequency * 1000; // translate to milliseconds
//     var ti = setInterval(chk, frequency);
//     // reset counter after user interaction
//     element.bind('keyup', function() {
//       ti && clearInterval(ti);
//       ti = setInterval(chk, frequency);
//     });
//   });
// 
// };
		// Example of how to use the observe_field
			// 
			//  // When DOM loads, init the page.
			//  //$(document).ready(function(){
			//         $(function() {
			//           // Executes a callback detecting changes with a frequency of 1 second
			//           $("#UserSearch").observe_field(1, function( ) {
			//             //alert('Change observed! new value: ' + this.value );
			//             $.post("<?php echo $html->url('/admin/users/view_users/')?>", { UserSearch: this.value},function(data) {$('#ajax_search').html(data);})
			// 			//$('#ajax_search').html(content);
			//           });
			//         });
			// //});
			// 


// 	/*
// 		Sleep by Mark Hughes
// 		http://www.360Gamer.net/
// 	
// 		Usage:
// 			$.sleep ( 3, function()
// 			{
// 				alert ( "I slept for 3 seconds!" );
// 			});
// 		Use at free will, distribute free of charge
// 	*/
// 	;(function($)
// 	{
// 		var _sleeptimer;
// 		$.sleep = function( time2sleep, callback )
// 		{
// 			$.sleep._sleeptimer = time2sleep;
// 			$.sleep._cback = callback;
// 			$.sleep.timer = setInterval('$.sleep.count()', 1000);
// 		}
// 		$.extend ($.sleep, {
// 			current_i : 1,
// 			_sleeptimer : 0,
// 			_cback : null,
// 			timer : null,
// 			count : function()
// 			{
// 				if ( $.sleep.current_i === $.sleep._sleeptimer )
// 				{
// 					clearInterval($.sleep.timer);
// 					$.sleep._cback.call(this);
// 				}
// 				$.sleep.current_i++;
// 			}
// 		});
// 	})(jQuery);
// 	
// 	
// 	
// 	
// 	
// 	//parent.location.href = parent.location.href;
// 	
// 		// change the value of the first drop down to trigger observeField 
// 		
// 	//	parent.$("#EventEventId").val("11").trigger('change').delay(800);
// 		
// 		// trigger the change (as if the user clicked on the element)
// 		//parent.$('#EventEventId').trigger('change');
// 		
// 	
// 		// change the value of the first drop down to trigger observeField 
// 		
// 	//	parent.$("#TeamId").val("2552");
// 		
// 		// trigger the change (as if the user clicked on the element)
// 		//parent.$('#TeamId').trigger('change');
// 	
// 	
// 	//parent.$.fn.colorbox.close();



// WORKING!!!!
// $().ready(function() { 
// 
// 	$('a.something').myModal({
// 		width:800,
// 		height:500,
// 		show:'',
// 		speed:500,
// 		//open:'',
// 		overlay:'#green'
// 		
// 	});
// 
// 	$('.tip').jTruncate({ 
// 		length: 200, 
// 		minTrail: 0, 
// 		moreText: "[see all]", 
// 		lessText: "[hide extra]", 
// 		ellipsisText: " (truncated)", 
// 		moreAni: "fast", 
// 		lessAni: 2000
// 	}); 
// 	
// 	
// 	
// }); 

