
/* Copyright 2009+ by SmallerPage.com */


function gb(el) {
	el.style.minHeight = '1em';
	var sp = el.id.split(':');
	 var a = sp[0].split('-');
	  var otype = a[0];
	  var idnum = a[1];
	 var b = sp[1];
	  var fname = b;
	el.gb = {
		otype: otype.toLowerCase(),
		idnum: idnum,
		fname: fname.toLowerCase(),
		edit_mode: 0,
		val_curr: '',
		val_ed: ''
	}
	$(el).html('<div id="gb-player:' + el.id + '">' + $(el).html() + '</div><div id="gb-editor:' + el.id + '" style="display:none; padding:3px; padding-top:1.6em; background:#ffffd0;"></div>');
	  el.player = $(el).children('div:first')[0];
	  el.editor = $(el).children('div:last')[0];
	el.gbe = document.createElement('a');
	  el.gbe.id = 'gbe:' + el.id;
	  el.gbe.style.display = 'none';
	  el.gbe.style.position = 'absolute';
	  el.gbe.style.left = '0.36em';
	  el.gbe.style.top = '0.12em';
	  el.gbe.style.padding = '2px';
	  el.gbe.style.zIndex = '9999';
	  el.gbe.href = 'http://' + document.domain + '/' + el.gb.otype + '-' + el.gb.idnum + ':' + el.gb.fname;
	  el.gbe.innerHTML = '<img src="http://' + document.domain + '/?&f=photo-266&picwidth=32" border="0" style="height:1em; width:auto !important;">';
	 el.appendChild(el.gbe);
		el.gbe_cancel = document.createElement('a');
		  el.gbe_cancel.title = 'Cancel';
		  el.gbe_cancel.id = 'gbe-save:' + el.id;
		  el.gbe_cancel.style.display = 'none';
		  el.gbe_cancel.style.position = 'absolute';
		  el.gbe_cancel.style.left = '0.36em';
		  el.gbe_cancel.style.top = '0.12em';
		  el.gbe_cancel.style.padding = '2px';
		  el.gbe_cancel.style.zIndex = '9999';
		  el.gbe_cancel.href = 'http://' + document.domain + '/' + el.gb.otype + '-' + el.gb.idnum + ':' + el.gb.fname;
		  el.gbe_cancel.innerHTML = '<img src="http://' + document.domain + '/?&f=photo-265&picwidth=32" border="0" style="height:1em; width:auto !important;">';
		 el.appendChild(el.gbe_cancel);
		el.gbe_thinker = document.createElement('a');
		  el.gbe_thinker.title = 'Cancel';
		  el.gbe_thinker.id = 'gbe-thinker:' + el.id;
		  el.gbe_thinker.style.display = 'none';
		  el.gbe_thinker.style.position = 'absolute';
		  el.gbe_thinker.style.left = '1.7em';
		  el.gbe_thinker.style.top = '0.12em';
		  el.gbe_thinker.style.padding = '2px';
		  el.gbe_thinker.style.zIndex = '9999';
		  el.gbe_thinker.href = 'http://' + document.domain + '/' + el.gb.otype + '-' + el.gb.idnum + ':' + el.gb.fname;
		  el.gbe_thinker.innerHTML = '<img src="http://' + document.domain + '/?&f=routine-2615" border="0" style="height:1em; width:auto !important;">';
		 el.appendChild(el.gbe_thinker);
		el.gbe_save = document.createElement('a');
		  el.gbe_save.title = 'Save';
		  el.gbe_save.id = 'gbe-save:' + el.id;
		  el.gbe_save.style.display = 'none';
		  el.gbe_save.style.position = 'absolute';
		  el.gbe_save.style.left = '1.7em';
		  el.gbe_save.style.top = '0.12em';
		  el.gbe_save.style.padding = '2px';
		  el.gbe_save.style.zIndex = '9999';
		  el.gbe_save.href = 'http://' + document.domain + '/' + el.gb.otype + '-' + el.gb.idnum + ':' + el.gb.fname;
		  el.gbe_save.innerHTML = '<img src="http://' + document.domain + '/?&f=photo-264&picwidth=32" border="0" style="height:1em; width:auto !important;">';
		 el.appendChild(el.gbe_save);
	$(el).hover(
		function() { if (this.gb.edit_mode !== 1) { $(this.gbe).fadeIn(120); } else { $(this.gbe).hide(); } },
		function() { if (this.gb.edit_mode !== 1) { $(this.gbe).fadeOut(120); } else { $(this.gbe).hide(); } }
	);
	  $(el.gbe).hover(
		function() { $(this).css('background-color','#ffffaa'); },
		function() { $(this).css('background-color',''); }
	  );
	$(el.gbe).click(function() {
		var that = this.parentNode;
		if (that.gb.edit_mode == 1) {
			gb_play(that);
		}
		else {
			gb_edit(that);
		}
		$(this).blur();
		return false;
	});
		$(el.gbe_cancel).click(function() { // cancel behaves like edit btn
			var that = this.parentNode;
			if (that.gb.edit_mode == 1) {
				gb_play(that);
			}
			else {
				gb_edit(that);
			}
			$(this).blur();
			return false;
		});
		$(el.gbe_save).click(function() { // save - does not apply to file fields
			var that = this.parentNode;
			gb_edit_save(that);
			$(this).blur();
			return false;
		});
	// what goes in the editor?
	gb_init_editor(el);
}
	function gb_init_editor(el) {
		// what's the initial value?
		if (el.gb.fname == 'file') {
			el.gb.val_curr = $(el.player).find('img')[0].src;
			 if (el.gb.val_curr.indexOf('?') == -1) {
				el.gb.val_curr = el.gb.val_curr + '?';
			 }
			 if (el.gb.val_curr.indexOf('noCache') == -1) {
				el.gb.val_curr = el.gb.val_curr + '&noCache=1';
			 }
		}
		else {
			el.gb.val_curr = gb_toMarkup($(el.player).html());
		}
		// what goes in the editor?
		var _usplit = el.gb.fname.split('_');
		  var _ulast = _usplit[_usplit.length-1];
		if (el.gb.fname == 'file') {
			// it's a file - we need ajaxupload.
			$(el.editor).html('<div><button id="gb-editor-btn:' + el.editor.id + '" style="cursor:pointer !important;">New File...</button></div>');
			el.editor.gb = new AjaxUpload('gb-editor-btn:' + el.editor.id, {
				action:'http://' + document.domain + '/index.cfm?&siteformat=xml',
				name:'1_file',
				data: {
					"1_posttype": 'UPDATE',
					"1_orb": el.gb.otype,
					"1_where": el.gb.otype + '.id=' + el.gb.idnum
				},
				autoSubmit:true,
				responseType:'text/xml',
				onChange: function() {
					// alert('change');
					gb_edit_think(this.el);
				},
				onSubmit: function() {
					// :)
				},
				onComplete: function(file,response) {
					gb_edit_unthink(this.el);
					var status = '1';
					try {
					  var status = $(response.getElementsByTagName('post_n')[0].getElementsByTagName('n1')[0].getElementsByTagName('status')[0]).text();
					} catch(err) {}
					if (status == '1') {
						this.el.gb.val_ed = this.el.gb.val_ed.replace(/(&gbrando=[0-9\.]+)/,'') + '&gbrando=' + Math.random();
						gb_edit_good(this.el);
					}
					else {
						gb_edit_bad(this.el);
					}
				}
			});
			el.editor.gb.el = el;
		}
		else if (el.gb.fname == 'title' || el.gb.fname == 'name' || el.gb.fname == 'domain' || el.gb.fname == 'user_key_id' || ( _usplit.length > 1 && (_ulast == 'unsignedint' || _ulast == 'int' || _ulast == 'double') )) {
			$(el.editor).html('<div><input type="text" id="gb-editor-btn:' + el.editor.id + '"></div>');
			el.imp = $(el.editor).children('div:first').children('input:first')[0];
			 el.imp.el = el;
			if ( _usplit.length > 1 && (_ulast == 'unsignedint' || _ulast == 'int' || _ulast == 'double')) {
				$(el.imp).keydown(function(e) {
					if (e.keyCode == 13) {
						gb_edit_save(this.el);
						return false;
					}
				});
				$(el.imp).keyup(function(e) {
					if (e.keyCode == 13) {
						return false;
					}
					else if (this.value.match(/[^0-9\.]/)) {
						this.value = this.value.replace(/[^0-9\.]/g,'');
						return false;
					}
				});
			}
			else {
				$(el.imp).keydown(function(e) {
					if (e.keyCode == 13) {
						gb_edit_save(this.el);
						return false;
					}
				});
			}
		}
		else if (el.gb.fname == 'gutitle') {
			$(el.editor).html('<div><input type="text" id="gb-editor-btn:' + el.editor.id + '"></div>');
			el.imp = $(el.editor).children('div:first').children('input:first')[0];
			 el.imp.el = el;
			$(el.imp).keydown(function(e) {
				if (e.keyCode == 13) {
					gb_edit_save(this.el);
					return false;
				}
			});
		}
		else { // default to textarea
			$(el.editor).html('<div><textarea id="gb-editor-btn:' + el.editor.id + '" style="width:80%; height:5em;"></textarea></div>');
		}
	}
  function gb_edit(el) {
	el.gb.val_ed = jQuery.trim(el.gb.val_curr);
	el.gb.edit_mode = 1;
	$(el.player).hide(120);
	$(el.editor).show(120);
	el.gbe.title = '(hide)';
	$(el.gbe).hide();
	$(el.gbe_cancel).show();
	if (el.gb.fname == 'file') {
		// do nothing
	}
	else {
		$(el.editor).children('div:first').children('input:first,textarea:first').val(el.gb.val_ed);
		$(el.gbe_save).show();
	}
  }
	function gb_edit_save(el) { // file never uses this
		el.gb.val_ed = $(el.editor).children('div:first').children('input:first,textarea:first').val();
		  if (el.gb.fname == 'gutitle') {
			// validate string
			var str = el.gb.val_ed;
			if (jQuery.trim(str) !== '') {
				// well-formed?
				var retfalse = 0;
				if (str.match(/[^a-z_]/i)) {
				  alert('Unique titles may contain only letters and underscores.');
				  var retfalse = 1;
				}
				else if (str.indexOf('__') > -1) {
				  alert('You may not use adjacent underscores (like "__") in unique titles.');
				  var retfalse = 1;
				}
				else if (str.substr(0,1) == '_' || str.substr(0,str.length-1) == '_') {
				  alert('Please do not begin or end unique titles with underscores.');
				  var retfalse = 1;
				}
				if (retfalse == 1) {
				  try {
				       
				  } catch(err) { }
				  return false;
				}
			}
		  }
		eval("var props = {'1_posttype': 'UPDATE', '1_orb': el.gb.otype, '1_where': el.gb.otype + '.id=' + el.gb.idnum, '1_" + el.gb.fname + "': el.gb.val_ed }");
		gb_edit_think(el);
		$.post('http://' + document.domain + '/?&o=476&siteformat=xml&elId=' + encodeURIComponent(el.id), props,
		  gb_edit_save2, "xml");
	}
	  function gb_edit_save2(data) {
		var _s = this.url.split('=');
		var elId = decodeURIComponent(_s[_s.length-1]);
		var el = document.getElementById(elId);
		gb_edit_unthink(el);
		var status = jQuery.trim($($(data).find('post_status')[0]).text());
		if (status.toString() == '1') {
			gb_edit_good(el);
		}
		else {
			gb_edit_bad(el);
		}
	  }
	function gb_edit_think(el) { el.gbe_save.prev_disp = el.gbe_save.style.display; el.gbe_save.style.display = 'none'; $(el.gbe_thinker).fadeIn(180); }
	function gb_edit_unthink(el) { el.gbe_save.style.display = el.gbe_save.prev_disp; $(el.gbe_thinker).fadeOut(90); }
	function gb_edit_good(el) {
		el.gb.val_curr = gb_toMarkup(el.gb.val_ed);
		gb_play(el);
	}
	function gb_edit_bad(el) {
		if (el.gb.fname == 'gutitle') {
			alert('Unable to save.  The title is not unique.');
		}
		else {
			alert('Unable to save.  Please try again.');
		}
	}
  function gb_play(el) {
  	if (el.gb.fname == 'file') {
		$($(el.player).find('img')[0]).attr('src',el.gb.val_curr);
  	}
  	else {
  		$(el.player).html(gb_noMarkup(el.gb.val_curr));
  	}
	el.gb.edit_mode = 0;
	$(el.editor).hide(120);
	$(el.player).show(120);
	el.gbe.title = 'Edit...';
	$(el.gbe_save).hide();
	$(el.gbe_cancel).hide();
  }


if (typeof AjaxUpload == 'undefined') {
	/**
 * Ajax upload
 * Project page - http://valums.com/ajax-upload/
 * Copyright (c) 2008 Andris Valums, http://valums.com
 * Licensed under the MIT license (http://valums.com/mit-license/)
 * Version 3.5 (23.06.2009)
 */

/**
 * Changes from the previous version:
 * 1. Added better JSON handling that allows to use 'application/javascript' as a response
 * 2. Added demo for usage with jQuery UI dialog
 * 3. Fixed IE "mixed content" issue when used with secure connections
 * 
 * For the full changelog please visit: 
 * http://valums.com/ajax-upload-changelog/
 */

(function(){
	
var d = document, w = window;

/**
 * Get element by id
 */	
function get(element){
	if (typeof element == "string")
		element = d.getElementById(element);
	return element;
}

/**
 * Attaches event to a dom element
 */
function addEvent(el, type, fn){
	if (w.addEventListener){
		el.addEventListener(type, fn, false);
	} else if (w.attachEvent){
		var f = function(){
		  fn.call(el, w.event);
		};			
		el.attachEvent('on' + type, f)
	}
}


/**
 * Creates and returns element from html chunk
 */
var toElement = function(){
	var div = d.createElement('div');
	return function(html){
		div.innerHTML = html;
		var el = div.childNodes[0];
		div.removeChild(el);
		return el;
	}
}();

function hasClass(ele,cls){
	return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}
function addClass(ele,cls) {
	if (!hasClass(ele,cls)) ele.className += " "+cls;
}
function removeClass(ele,cls) {
	var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
	ele.className=ele.className.replace(reg,' ');
}

// getOffset function copied from jQuery lib (http://jquery.com/)
if (document.documentElement["getBoundingClientRect"]){
	// Get Offset using getBoundingClientRect
	// http://ejohn.org/blog/getboundingclientrect-is-awesome/
	var getOffset = function(el){
		var box = el.getBoundingClientRect(),
		doc = el.ownerDocument,
		body = doc.body,
		docElem = doc.documentElement,
		
		// for ie 
		clientTop = docElem.clientTop || body.clientTop || 0,
		clientLeft = docElem.clientLeft || body.clientLeft || 0,
		
		// In Internet Explorer 7 getBoundingClientRect property is treated as physical,
		// while others are logical. Make all logical, like in IE8.
		
		
		zoom = 1;
		if (body.getBoundingClientRect) {
			var bound = body.getBoundingClientRect();
			zoom = (bound.right - bound.left)/body.clientWidth;
		}
		if (zoom > 1){
			clientTop = 0;
			clientLeft = 0;
		}
		var top = box.top/zoom + (window.pageYOffset || docElem && docElem.scrollTop/zoom || body.scrollTop/zoom) - clientTop,
		left = box.left/zoom + (window.pageXOffset|| docElem && docElem.scrollLeft/zoom || body.scrollLeft/zoom) - clientLeft;
				
		return {
			top: top,
			left: left
		};
	}
	
} else {
	// Get offset adding all offsets 
	var getOffset = function(el){
		if (w.jQuery){
			return jQuery(el).offset();
		}		
			
		var top = 0, left = 0;
		do {
			top += el.offsetTop || 0;
			left += el.offsetLeft || 0;
		}
		while (el = el.offsetParent);
		
		return {
			left: left,
			top: top
		};
	}
}

function getBox(el){
	var left, right, top, bottom;	
	var offset = getOffset(el);
	left = offset.left;
	top = offset.top;
						
	right = left + el.offsetWidth;
	bottom = top + el.offsetHeight;		
		
	return {
		left: left,
		right: right,
		top: top,
		bottom: bottom
	};
}

/**
 * Crossbrowser mouse coordinates
 */
function getMouseCoords(e){		
	// pageX/Y is not supported in IE
	// http://www.quirksmode.org/dom/w3c_cssom.html			
	if (!e.pageX && e.clientX){
		// In Internet Explorer 7 some properties (mouse coordinates) are treated as physical,
		// while others are logical (offset).
		var zoom = 1;	
		var body = document.body;
		
		if (body.getBoundingClientRect) {
			var bound = body.getBoundingClientRect();
			zoom = (bound.right - bound.left)/body.clientWidth;
		}

		return {
			x: e.clientX / zoom + d.body.scrollLeft + d.documentElement.scrollLeft,
			y: e.clientY / zoom + d.body.scrollTop + d.documentElement.scrollTop
		};
	}
	
	return {
		x: e.pageX,
		y: e.pageY
	};		

}
/**
 * Function generates unique id
 */		
var getUID = function(){
	var id = 0;
	return function(){
		return 'ValumsAjaxUpload' + id++;
	}
}();

function fileFromPath(file){
	return file.replace(/.*(\/|\\)/, "");			
}

function getExt(file){
	return (/[.]/.exec(file)) ? /[^.]+$/.exec(file.toLowerCase()) : '';
}			

// Please use AjaxUpload , Ajax_upload will be removed in the next version
Ajax_upload = AjaxUpload = function(button, options){
	if (button.jquery){
		// jquery object was passed
		button = button[0];
	} else if (typeof button == "string" && /^#.*/.test(button)){					
		button = button.slice(1);				
	}
	button = get(button);	
	
	this._input = null;
	this._button = button;
	this._disabled = false;
	this._submitting = false;
	// Variable changes to true if the button was clicked
	// 3 seconds ago (requred to fix Safari on Mac error)
	this._justClicked = false;
	this._parentDialog = d.body;
	
	if (window.jQuery && jQuery.ui && jQuery.ui.dialog){
		var parentDialog = jQuery(this._button).parents('.ui-dialog');
		if (parentDialog.length){
			this._parentDialog = parentDialog[0];
		}
	}			
					
	this._settings = {
		// Location of the server-side upload script
		action: 'upload.php',			
		// File upload name
		name: 'userfile',
		// Additional data to send
		data: {},
		// Submit file as soon as it's selected
		autoSubmit: true,
		// The type of data that you're expecting back from the server.
		// Html and xml are detected automatically.
		// Only useful when you are using json data as a response.
		// Set to "json" in that case. 
		responseType: false,
		// When user selects a file, useful with autoSubmit disabled			
		onChange: function(file, extension){},					
		// Callback to fire before file is uploaded
		// You can return false to cancel upload
		onSubmit: function(file, extension){},
		// Fired when file upload is completed
		// WARNING! DO NOT USE "FALSE" STRING AS A RESPONSE!
		onComplete: function(file, response) {}
	};

	// Merge the users options with our defaults
	for (var i in options) {
		this._settings[i] = options[i];
	}
	
	this._createInput();
	this._rerouteClicks();
}
			
// assigning methods to our class
AjaxUpload.prototype = {
	setData : function(data){
		this._settings.data = data;
	},
	disable : function(){
		this._disabled = true;
	},
	enable : function(){
		this._disabled = false;
	},
	// removes ajaxupload
	destroy : function(){
		if(this._input){
			if(this._input.parentNode){
				this._input.parentNode.removeChild(this._input);
			}
			this._input = null;
		}
	},				
	/**
	 * Creates invisible file input above the button 
	 */
	_createInput : function(){
		var self = this;
		var input = d.createElement("input");
		input.setAttribute('type', 'file');
		input.setAttribute('name', this._settings.name);
		var styles = {
			'position' : 'absolute'
			,'margin': '-5px 0 0 -175px'
			,'padding': 0
			,'width': '220px'
			,'height': '30px'
			,'fontSize': '14px'								
			,'opacity': 0
			,'cursor': 'pointer'
			,'display' : 'none'
			,'zIndex' :  2147483583 //Max zIndex supported by Opera 9.0-9.2x 
			// Strange, I expected 2147483647					
		};
		for (var i in styles){
			input.style[i] = styles[i];
		}
		
		// Make sure that element opacity exists
		// (IE uses filter instead)
		if ( ! (input.style.opacity === "0")){
			input.style.filter = "alpha(opacity=0)";
		}
							
		this._parentDialog.appendChild(input);

		addEvent(input, 'change', function(){
			// get filename from input
			var file = fileFromPath(this.value);	
			if(self._settings.onChange.call(self, file, getExt(file)) == false ){
				return;				
			}														
			// Submit form when value is changed
			if (self._settings.autoSubmit){
				self.submit();						
			}						
		});
		
		// Fixing problem with Safari
		// The problem is that if you leave input before the file select dialog opens
		// it does not upload the file.
		// As dialog opens slowly (it is a sheet dialog which takes some time to open)
		// there is some time while you can leave the button.
		// So we should not change display to none immediately
		addEvent(input, 'click', function(){
			self.justClicked = true;
			setTimeout(function(){
				// we will wait 3 seconds for dialog to open
				self.justClicked = false;
			}, 3000);			
		});		
		
		this._input = input;
	},
	_rerouteClicks : function (){
		var self = this;
	
		// IE displays 'access denied' error when using this method
		// other browsers just ignore click()
		// addEvent(this._button, 'click', function(e){
		//   self._input.click();
		// });
				
		var box, dialogOffset = {top:0, left:0}, over = false;							
		addEvent(self._button, 'mouseover', function(e){
			if (!self._input || over) return;
			over = true;
			box = getBox(self._button);
					
			if (self._parentDialog != d.body){
				dialogOffset = getOffset(self._parentDialog);
			}	
		});
		
	
		// we can't use mouseout on the button,
		// because invisible input is over it
		addEvent(document, 'mousemove', function(e){
			var input = self._input;			
			if (!input || !over) return;
			
			if (self._disabled){
				removeClass(self._button, 'hover');
				input.style.display = 'none';
				return;
			}	
										
			var c = getMouseCoords(e);

			if ((c.x >= box.left) && (c.x <= box.right) && 
			(c.y >= box.top) && (c.y <= box.bottom)){			
				input.style.top = c.y - dialogOffset.top + 'px';
				input.style.left = c.x - dialogOffset.left + 'px';
				input.style.display = 'block';
				addClass(self._button, 'hover');				
			} else {		
				// mouse left the button
				over = false;
				if (!self.justClicked){
					input.style.display = 'none';
				}
				removeClass(self._button, 'hover');
			}			
		});			
			
	},
	/**
	 * Creates iframe with unique name
	 */
	_createIframe : function(){
		// unique name
		// We cannot use getTime, because it sometimes return
		// same value in safari :(
		var id = getUID();
		
		// Remove ie6 "This page contains both secure and nonsecure items" prompt 
		// http://tinyurl.com/77w9wh
		var iframe = toElement('<iframe src="javascript:false;" name="' + id + '" />');
		iframe.id = id;
		iframe.style.display = 'none';
		d.body.appendChild(iframe);			
		return iframe;						
	},
	/**
	 * Upload file without refreshing the page
	 */
	submit : function(){
		var self = this, settings = this._settings;	
					
		if (this._input.value === ''){
			// there is no file
			return;
		}
										
		// get filename from input
		var file = fileFromPath(this._input.value);			

		// execute user event
		if (! (settings.onSubmit.call(this, file, getExt(file)) == false)) {
			// Create new iframe for this submission
			var iframe = this._createIframe();
			
			// Do not submit if user function returns false										
			var form = this._createForm(iframe);
			form.appendChild(this._input);
			
			form.submit();
			
			d.body.removeChild(form);				
			form = null;
			this._input = null;
			
			// create new input
			this._createInput();
			
			var toDeleteFlag = false;
			
			addEvent(iframe, 'load', function(e){
					
				if (// For Safari
					iframe.src == "javascript:'%3Chtml%3E%3C/html%3E';" ||
					// For FF, IE
					iframe.src == "javascript:'<html></html>';"){						
					
					// First time around, do not delete.
					if( toDeleteFlag ){
						// Fix busy state in FF3
						setTimeout( function() {
							d.body.removeChild(iframe);
						}, 0);
					}
					return;
				}				
				
				var doc = iframe.contentDocument ? iframe.contentDocument : frames[iframe.id].document;

				// fixing Opera 9.26
				if (doc.readyState && doc.readyState != 'complete'){
					// Opera fires load event multiple times
					// Even when the DOM is not ready yet
					// this fix should not affect other browsers
					return;
				}
				
				// fixing Opera 9.64
				if (doc.body && doc.body.innerHTML == "false"){
					// In Opera 9.64 event was fired second time
					// when body.innerHTML changed from false 
					// to server response approx. after 1 sec
					return;				
				}
				
				var response;
									
				if (doc.XMLDocument){
					// response is a xml document IE property
					response = doc.XMLDocument;
				} else if (doc.body){
					// response is html document or plain text
					response = doc.body.innerHTML;
					if (settings.responseType && settings.responseType.toLowerCase() == 'json'){
						// If the document was sent as 'application/javascript' or
						// 'text/javascript', then the browser wraps the text in a <pre>
						// tag and performs html encoding on the contents.  In this case,
						// we need to pull the original text content from the text node's
						// nodeValue property to retrieve the unmangled content.
						// Note that IE6 only understands text/html
						if (doc.body.firstChild && doc.body.firstChild.nodeName.toUpperCase() == 'PRE'){
							response = doc.body.firstChild.firstChild.nodeValue;
						}
						if (response) {
							response = window["eval"]("(" + response + ")");
						} else {
							response = {};
						}
					}
				} else {
					// response is a xml document
					var response = doc;
				}
																			
				settings.onComplete.call(self, file, response);
						
				// Reload blank page, so that reloading main page
				// does not re-submit the post. Also, remember to
				// delete the frame
				toDeleteFlag = true;
				
				// Fix IE mixed content issue
				iframe.src = "javascript:'<html></html>';";		 								
			});
	
		} else {
			// clear input to allow user to select same file
			// Doesn't work in IE6
			// this._input.value = '';
			d.body.removeChild(this._input);				
			this._input = null;
			
			// create new input
			this._createInput();						
		}
	},		
	/**
	 * Creates form, that will be submitted to iframe
	 */
	_createForm : function(iframe){
		var settings = this._settings;
		
		// method, enctype must be specified here
		// because changing this attr on the fly is not allowed in IE 6/7		
		var form = toElement('<form method="post" enctype="multipart/form-data"></form>');
		form.style.display = 'none';
		form.action = settings.action;
		form.target = iframe.name;
		d.body.appendChild(form);
		
		// Create hidden input element for each data key
		for (var prop in settings.data){
			var el = d.createElement("input");
			el.type = 'hidden';
			el.name = prop;
			el.value = settings.data[prop];
			form.appendChild(el);
		}			
		return form;
	}	
};
})(); 
}

if (typeof gb_noMarkup == 'undefined') {
	function gb_noMarkup(str) {
		return str.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;');
	}
}
if (typeof gb_toMarkup == 'undefined') {
	function gb_toMarkup(str) {
		return str.replace(/(&quot;)/g,'"').replace(/(&gt;)/g,'>').replace(/(&lt;)/g,'<').replace(/(&amp;)/g,'&');
	}
} 


if (typeof ARROWS_OK == 'undefined') { ARROWS_OK = 1; }

function fklr(cmd) { // on the right
	if (typeof cmd == 'undefined') { var cmd = ''; }
	if (cmd == 'people') {
		// new ppl
		$('.sp_rcol').hide();
		$.get('http://' + document.domain + '/sp_user_people_suggest?&max=1', function(data) {
			$('.sp_rcol').html(data);
			$('.sp_rcol').fadeIn(360);
		});
	}
	else if (cmd == 'random_pages') {
		// new ppl
		$('.sp_rcol').hide();
		$.get('http://' + document.domain + '/sp_user_page_suggest?&max=3&random=1', function(data) {
			$('.sp_rcol').html(data);
			$('.sp_rcol').fadeIn(360);
		});
	}
}
function fkll(cmd) { // on the left
	if (typeof cmd == 'undefined') { var cmd = ''; }
	if (cmd == 'pages') {
		// new ppl
		$('.sp_lcol').hide();
		$.get('http://' + document.domain + '/sp_user_page_suggest?&max=2', function(data) {
			$('.sp_lcol').html(data);
			$('.sp_lcol').fadeIn(360);
		});
	}
	else if (cmd == 'user_pages') {
		// new ppl
		$('.sp_lcol').hide();
		$.get('http://' + document.domain + '/sp_user_page_suggest?&max=3&user_id=' + USER_ID + '&name=' + SP_FKL_NAME, function(data) {
			$('.sp_lcol').html(data);
			$('.sp_lcol').fadeIn(360);
		});
	}
}

function sp_navmenu_fill(txt) {
	$('.sp_navmenu_out').html(txt);
	$('.sp_navmenu_out').show(140);
}

function sp_blink(elId) { // "blinks" an element
	var el = document.getElementById(elId);
	el.blink_orig_bg = el.style.background;
	el.style.background = '#ffffaa';
	setTimeout("document.getElementById('" + el.id + "').style.background = document.getElementById('" + el.id + "').blink_orig_bg;",1000);
}

function smaller_tabs() {
	TABORDER = 1;
	$('input,textarea,select,button').each(function() {
		this.tabIndex = TABORDER;
		TABORDER = TABORDER + 1;
	});
	$('a').not('.nobo').each(function() {
		if ($(this).find('img').length == 0 && this.innerHTML !== '' && this.is_tabme !== 1) {
			$(this).addClass('tabme');
			if (this.is_tabme !== 1) {
				this.orig_borderWidth = this.style.borderWidth;
				this.orig_padding = this.style.padding;
				this.orig_outline = this.style.outline;
			}
			this.tabIndex = TABORDER;
			TABORDER = TABORDER + 1;
			this.is_tabme = 1;
		}
	});
	$('.tabme').not('.tabme_assigned').mousedown(function(e) { // make them go on mousedown, otherwise you get weird "non-clicks" cuz of focus
		if (e.which) rightclick = (e.which == 3);
		else if (e.button) rightclick = (e.button == 2);
		if ($(this).attr('target').toLowerCase() !== '_blank' && e.ctrlKey == false && rightclick == false) { this.nogo = 1; window.location = this.href; return false; }
	});
		$('.tabme').not('.tabme_assigned').click(function() { // make them go on mousedown, otherwise you get weird "non-clicks" cuz of focus
			if ($(this).attr('target').toLowerCase() !== '_blank') { if (this.nogo == 1) { return false; } }
		});
	$('.tabme').not('.tabme_assigned').focus(function() {
		$('.tabme').not(this).blur();
		this.is_focused = 1;
		this.style.borderWidth = '2px';
		this.style.padding = '3px';
		this.style.outline = 0;
	});
	$('.tabme').not('.tabme_assigned').blur(function() {
		this.is_focused = 0;
		this.style.borderWidth = this.orig_borderWidth;
		this.style.padding = this.orig_padding;
		this.style.outline = this.orig_outline;
	});
	$('.tabme').not('.tabme_assigned').each(function() { $(this).addClass('tabme_assigned'); });
}

function plush_radio() {
  $('.plush_radio').each(function() {
	if (this.is_plush_radio == 1) {
		// already did it!
	}
	else {
	  this.is_plush_radio = 1;
	  this.style.cursor = 'pointer';
	  var rads = this.getElementsByTagName('input');
	  if (rads.length > 0) {
		var rad = rads[0];
		this.rad = rad;
		 this.rad.that = this;
		  $(this).mousedown(function() {
			if (this.rad.checked == true) {
				// do nothing
			}
			else {
				rad.checked = true;
				 plush_radio_on(this);
				 $(rad).change();
			}
		  });
		  $(rad).bind('mouseup change',function() {
		  	if (this.checked == true) {
		  		plush_radio_on(this.that);
		  	}
		  	else {
		  		plush_radio_off(this.that);
		  	}
		  });
		  rad.style.cursor = 'pointer';
		// init bg?
		if (this.rad.checked == true) {
			plush_radio_on(this);
		}
		else {
			plush_radio_off(this);
		}
	  }
	}
  });
}
	function plush_radio_on(that) { // make it look "on"
		$('.plush_radio').not(that).each(function() {
			plush_radio_off(this);
		});
		that.style.backgroundImage = 'url(http://bigpinky.com/?&f=photo-248)';
		that.style.backgroundColor = '#fff777';
		that.style.borderTop = '1px solid #3372ff';
		that.style.border = '1px solid #3372ff';
	}
	function plush_radio_off(that) { // make it look "on"
		that.style.backgroundImage = '';
		that.style.backgroundColor = '';
		that.style.border = '0px solid white';
		 that.style.borderTop = '1px solid #ccc';
	}

function gutitle_fields() {
	$('.gutitle_field').each(function() {
		var str = this.id;
		  var split_1 = str.split(':');
		  var split_2 = split_1[0].split('-');
		  var otype = split_2[0];
		  var idnum = split_2[1];
		this.otype = otype;
		this.idnum = idnum;
		var pNode = $(this).parents()[0];
		this.pNode = pNode;
		this.thinker = document.createElement('div');
		 this.thinker.id = this.id + ':thinker';
		 this.thinker.style.position = 'absolute';
		  this.thinker.style.right = '5px';
		 this.thinker.style.zIndex = '10';
		 this.thinker.style.display = 'none';
		 this.thinker.style.padding = '10px';
		 this.thinker.style.marginTop = '5px';
		 this.thinker.innerHTML = ' <img src="http://bigpinky.com/?&o=476&f=routine-2615" border="0" style="height:1em;; "> ';
		this.good = document.createElement('div');
		 this.good.id = this.id + ':good';
		 this.good.style.position = 'absolute';
		  this.good.style.right = '5px';
		 this.good.style.zIndex = '10';
		 this.good.style.display = 'none';
		 this.good.style.padding = '10px';
		 this.good.style.marginTop = '5px';
		 this.good.style.background = '#fff777';
		 this.good.innerHTML = '<b>It\'s Available!</b>';
		this.tick = document.createElement('div');
		 this.tick.id = this.id + ':tick';
		 this.tick.style.position = 'absolute';
		  this.tick.style.right = '5px';
		 this.tick.style.zIndex = '10';
		 this.tick.style.display = 'none';
		 this.tick.style.padding = '10px';
		 this.tick.style.marginTop = '5px';
		 this.tick.style.background = '#fff777';
		 this.tick.innerHTML = ' <img src="http://bigpinky.com/get_7o_file.cfm?&path=icons/Fugue/icons/tick.png" border="0" style="height:1em;" class="" id=""> ';
		this.bad = document.createElement('div');
		 this.bad.id = this.id + ':bad';
		 this.bad.style.position = 'absolute';
		  this.bad.style.right = '5px';
		 this.bad.style.zIndex = '10';
		 this.bad.style.display = 'none';
		 this.bad.style.padding = '10px';
		 this.bad.style.marginTop = '5px';
		 this.bad.style.color = '#800000';
		 this.bad.style.background = 'white';
		 this.bad.innerHTML = '<b>Unavailable - try another.</b>';
		this.pNode.appendChild(this.thinker);
		this.pNode.appendChild(this.good);
		this.pNode.appendChild(this.tick);
		this.pNode.appendChild(this.bad);
		this.old_value = this.value;
		this.fail = function() {
			$(this.tick).hide();
			$(this).css('background','#800000');
			$(this).css('color','white');
			$(this.good).hide();
			$(this.bad).slideDown(240);
			setTimeout("document.getElementById('" + this.id + "').hide_fail()",1800);
		}
		  this.hide_fail = function() {
			$(this.bad).slideUp(240);
		  }
		this.success = function() {
			$(this.bad).hide();
			$(this.good).slideDown(240);
			setTimeout("document.getElementById('" + this.id + "').hide_success()",1800);
		}
		  this.hide_success = function() {
			$(this.good).slideUp(240);
			$(this.tick).fadeIn(180);
		  }
		$(this).keydown(function(e) {
			$(this).css('background','');
			$(this).css('color','');
			$(this.tick).hide();
			if (e.keyCode == 13) {
				setTimeout("$(document.getElementById('" + this.id + "')).blur()",100);
				return false;
			}
		});
		$(this).keyup(function() { // validate
			if (this.value.search(/[^a-z_]/i) > -1) {
				this.value = this.value.replace(/[^a-z_]+/gi,'');
			}
			if (this.value.indexOf('__') > -1) {
				this.value = this.value.replace(/[_]+/gi,'_');
			}
			// begin/end underscores are dealt with on "enter"
		});
		$(this).focus(function() {
			$(this).css('background','');
			$(this).css('color','');
			$(this.tick).hide();
		});
		$(this).blur(function() {
			if (this.value.indexOf('_') == 0) {
				this.value = this.value.replace('_','');
			}
			if (this.value.substr(this.value.length-1,1) == '_') {
				this.value = this.value.substr(0,this.value.length-1);
			}
			var str = jQuery.trim(this.value);
			if (str !== '') {
				if (str == this.old_value) { return true; }
				$(this.tick).hide();
				$(this).css('background','');
				$(this).css('color','');
				this.old_value = this.value;
				$(this).select();
				$(this.thinker).slideDown(240);
				$(this.bad).hide();
				$(this.good).hide();
				var qstring = 'http://' + document.domain + '/?';
				  var qstring = qstring + '&rando=' + Math.random();
				$.get(qstring,
				  {
					check_gutitle:1,
					gutitle:str,
					orb:this.otype,
					'id':this.idnum,
					elId:this.id
				  },
				  function(data) {
				  	// i put the element id at the end of the url.
				  	var _split = this.url.split('=');
				  	var elId = decodeURIComponent(_split[_split.length-1]);
				  	var that = document.getElementById(elId);
					$(that.thinker).slideUp(240);
					if (data.toString() !== '1') {
						that.fail();
				  	}
				  	else {
						that.success();
				  	}
				  }
				,"text","abcdefg");
			}
		});
	});
}

function color_pickers() {
  if (document.getElementById('1_color') !== null) {
	try {
		$('#1_color').ColorPicker({
			eventName:'focus',
			flat:false,
			livePreview:true,
			onChange: function(hsb,hex,rgb) {
				$('#1_color').val('#' + hex);
				$('#1_color').css('background','#' + hex);
				$('.sp_body').css('border-color','#' + hex);
				$('.sp_tab_active').css('background','#' + hex);
				$('.sp_tabs').css('border-color','#' + hex);
				$('a').css('color','#' + hex);
				$('.color_example').css('color','#' + hex);
				 $('.color_example').css('padding','1px');
				 $('.color_example').css('background','white');
			}
		});
		$('#1_color').ColorPickerSetColor(document.getElementById('1_color').value);
	} catch(err) {}
  }
  if (document.getElementById('1_bgcolor') !== null) {
	try {
		$('#1_bgcolor').ColorPicker({
			eventName:'focus',
			flat:false,
			livePreview:true,
			onChange: function(hsb,hex,rgb) {
				$('#1_bgcolor').val('#' + hex);
				$(document.body).css('background-color','#' + hex);
				$('.bgcolor_example').css('background-color','#' + hex);
				$('.strict_bgcolor_example').css('background','#' + hex);
				 $('.strict_bgcolor_example').css('border-left-width','0px');
				 $('.strict_bgcolor_example').css('border-right-width','0px');
			}
		});
		$('#1_bgcolor').ColorPickerSetColor(document.getElementById('1_bgcolor').value);
	} catch(err) {}
  }
}




$(document).ready(function() {

$('.more').hide();

$('.editfadein').css('opacity','0');
window.onmousemove = function() {
	setTimeout("$('.editfadein').animate({'opacity':1},360);",20);
	setTimeout("window.onmousemove=null",500);
}



// make ".sp_success_slide" divs slide up
  setTimeout("try{$('.sp_success_slide').slideUp(440)} catch(err){}",2700);

// awesome pay button behavior.  important.
  $('.paybutton').mousedown(function() {
	$(this).css('border-style','inset');
  });
  $('.paybutton').mouseup(function() {
	$(this).css('border-style','outset');
  });

// if any input element is focused, arrows are *not* okay
  $('input,select,textarea,button').focus(function() {
	ARROWS_OK = 0;
  });
  $('input,select,textarea,button').blur(function() {
	ARROWS_OK = 1;
  });



// make tabbing through a page suck less
  smaller_tabs();

// plush radio behavior
  plush_radio();

// unqique title helpers
  gutitle_fields();

// color pickers
  color_pickers();

// select on ready fields
  $('.select_on_ready').select();

// focus focusme fields
  $('.focusme').focus();



// sortable pages
$('#page_list').sortable({
	update: function() {
		var _list = '';
		var _pcount = 1;
		$('#page_list').children('div').each(function() {
			_list = _list + ',' + this.id;
			$(this).find('a').attr('href','http://' + document.domain + '/' + _pcount);
			_pcount = _pcount + 1;
		});
		var _list = _list + ',';
		$.post('http://' + document.domain + '/?&siteformat=xml',{
			'1_posttype': "update",
			'1_orb': "site",
			'1_where': "site.id = " + SITE_ID,
			'1_pageidlist': _list
		});
	}
});
$('#page_list').children('div').each(function() {
	$(this).css('cursor','move');
});

// sortable people
$('.short_list').sortable({
	update: function() {
		var _list = '';
		var _idnum = this.id.split('-')[1];
		$(this).children('.user').each(function() {
			_list = _list + ',' + this.id;
		});
		var _list = _list + ',';
		$.post('http://' + document.domain + '/?&siteformat=xml',{
			'1_posttype': "update",
			'1_orb': "plist",
			'1_where': "plist.id = " + _idnum,
			'1_notes': _list
		});
	}
});
$('.short_list').children('div').each(function() {
	$(this).css('cursor','move');
});

// amanda's site nav idea
if (PAGE_COUNT > 0 && NO_FOOT !== 1 && (typeof NO_NAVMENU == 'undefined' || NO_NAVMENU !== 1)) {
  $('.sp_navmenu').each(function() {
	this.style.cursor = 'pointer';
	this.style.padding = '3px';
	this.style.fontWeight = 'bold';
	this.style.background = '#f5f5ff';
	this.innerHTML = '&nbsp;+&nbsp;';
	this.is_open = 0;
	this.got = 0;
	$(this).mousedown(function() {
		if (this.is_open == 1) { // close it
			$('.sp_navmenu_out').hide(180);
			this.innerHTML = '&nbsp;+&nbsp;';
			this.is_open = 0;
		}
		else { // open it
			this.innerHTML = '&nbsp;-&nbsp;';
			if (this.got !== 1) { // create output element, get pages
				$(this.parentNode).append('<div class="sp_navmenu_out" style="display:none;"> <img src="http://bigpinky.com/?&o=476&f=routine-2134" border="0" style="height:1em;; "> </div>');
				$.get('http://' + document.domain + '/pages?&naked=2&curr_page=' + PAGE_ID + '&sp_exclude=' + SP_EXCLUDE, sp_navmenu_fill );
				this.got = 1;
			}
			else {
				$('.sp_navmenu_out').show(140);
			}
			this.is_open = 1;
		}
	});
  });
}

// fklrs
if (SP_FKLR !== '') {
	setTimeout("fklr(SP_FKLR)",SP_FKLR_MS);
}
if (SP_FKLL !== '') {
	setTimeout("fkll(SP_FKLL)",SP_FKLL_MS);
}

// gbf
$('.gb').each(function() {
	gb(this);
});

if ($('.more').length == 1) {
	setTimeout("bigger()",1000);
}

});

function bigger() {
	var P = $('.sp_container')[0];
	// P starts with the same width as a; then it animates to its full width (960).
	$(P).append('<div id="sub" class="sp_sub" align="left" style="width:400px; padding-right:10px;"></div>');
	var c = $('.sp_sub')[0];
	var a = $('.sp_site')[0];
	var b = $('.more')[0];
	 $(a).css('z-index','2');
	 $(b).css('z-index','1');
	$(c).append(a);
	$(a).css('float','left'); $(a).css('clear','none');
	$(c).animate({'width':'960px'},640);
	setTimeout("bigger2()",720);
}
function bigger2() {
	var a = $('.sp_site')[0];
	$(a).animate({'width':'340px'},180);
	setTimeout("bigger3()",240);
}
function bigger3() {
	var c = $('.sp_sub')[0];
	var a = $('.sp_site')[0];
	var b = $('.more')[0];
	$(c).append('<div id="sp_spacer_b" style="height:1.54em">&nbsp;</div><div id="sp_more_container" class="b_container" style="border-top:1px solid #3372ff; display:none;"></div>');
	var d = $('.b_container')[0];
	$(d).css('float','left');
	$(d).css('clear','none');
	$(d).css('width','580px');
	$(d).css('margin-left','20px');
	$(d).css('padding','9px');
	$(d).css('background','#eaeaea');
	$(d).append(b);
	$(b).show();
	$(d).show(360);
}  