th.ui.isBrowser = {
	
	chrome: function() {
		
		if ($.browser.name == 'chrome') return true; else return false;
//		if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1) return true; else return false;
		
	}
	
}

th.ui.browserOk = 
		function() {
	
			th.log($.browser);

			if($.browser.name == 'msie') {
				if($.browser.versionX < 7) {
					th.log('Unsupported Browser');
					return false;
				}
			}
	
			th.log('Supported Browser');
			return true;
	
		};
/**
 * 
 * trimable class for trimming large contents of <p> / <div> / <span> tags
 * 
 * @author 		Robert Kararic robert1@kronomy.com
 * @since  		13.10.2009
 * 
 * th.ui.trimable
 *	  
 * There must be a <p>, <div> or <span> tag around the trimable content with
 * a class which has to be passed to the initialization. initial_state, when true
 * the contentet is trimmed at begining. num_chars_trimmed are the number of chars
 * that are shown when content is trimmed.
 * 
 * Usage:
 * 
 * $(document).ready( function() {
 * 
 * 		th.ui.trimable.init(class_target, num_chars_trimmed, inital_state);
 * 
 * }
 * 
 * 
 */
th.ui.trimable = {
	
	_text_enlarge:			'[show more >>]',
	_text_trim:				'[<< trim text]',
	
	_class_enlarge_link:	'.enlarge_link',
	_class_trim_link:		'.trim_link',
	_class_content:			'.trim_content',

	_link_enlarge:			'<a class="enlarge_link" style="display: none;" href="">##link_split##</a>',
	_link_trim:				'<a class="trim_link" style="display: none;" href="">##link_split##</a>',

	_num_chars_trimmed:		200,

	_class_target:			'.trimable',
	_class_trimmed:			'.trimmed',
	
	_text_follows:			'...',

	_initial_state:			true,
	
/**
 * 
 * th.ui.trimable.enlarge(target);
 * 
 * shows the wohle content with a trim link
 * 
 * @param string target		target tag from click eventhandler
 * 
 */
	enlarge: function (target) {
		
		if ($(target).hasClass(this._class_trimmed.split('.')[1])) $(target).removeClass(this._class_trimmed.split('.')[1]);
		
		var tmp_content = $(target).data('Content');
		
		$(target).children().filter(this._class_content).html(tmp_content);
		
		$(target).children().filter(this._class_trim_link).css({'display' : 'inline'});
		$(target).children().filter(this._class_enlarge_link).css({'display' : 'none'});
		
	},
	
/**
 * 
 * th.ui.trimable.enlarge(target);
 * 
 * shows the trimmed content with an enlarge link
 * 
 * @param string target		target tag from click eventhandler
 * 
 */
	trim: function (target) {
		
		$(target).addClass(this._class_trimmed.split('.')[1]);
		
		var tmp_content = $(target).data('Content').substring(0, this._num_chars_trimmed) + this._text_follows;
		
		$(target).children().filter(this._class_content).html(tmp_content);
		
		$(target).children().filter(this._class_trim_link).css({'display' : 'none'});
		$(target).children().filter(this._class_enlarge_link).css({'display' : 'inline'});
		
	},

/**
 * 
 * th.ui.trimable.init(class_target, num_chars_trimmed, inital_state);
 * 
 * initializes the trimable functionality. Mostly called in $(document).ready() event.
 * 
 * @param string 		class_target		class name for the tag which wraps the trim-content
 * @param int 			num_chars_trimmed	number of shown chars in trimmed state
 * @param boolean  		initial_state		true for trimmed content
 * @param string 		text_enlarge		text in enlarging link when translating	
 * @param string 		text_trim			text in trimming link when translating	
 * 
 */
	init: function (class_target, num_chars_trimmed, inital_state, text_enlarge, text_trim) {
		
		// check parameters and existence of class_target_group
		if (typeof class_target != 'undefined' && class_target != '') this._class_target = '.' + class_target;
		if (typeof num_chars_trimmed != 'undefined' && num_chars_trimmed != '') this._num_chars_trimmed = num_chars_trimmed;
		if (typeof text_enlarge != 'undefined' && text_enlarge != '') this._text_enlarge = '.' + text_enlarge;
		if (typeof text_trim != 'undefined' && text_trim != '') this._text_trim = '.' + text_trim;
		if (typeof inital_state != 'undefined') this._inital_state = inital_state;
		
		// set the link text (for translation???)
		var tmp_arr = this._link_enlarge.split('##link_split##');
		this._link_enlarge = tmp_arr[0] + this._text_enlarge + tmp_arr[1]; 

		tmp_arr = this._link_trim.split('##link_split##');
		this._link_trim = tmp_arr[0] + this._text_trim + tmp_arr[1]; 
		
		// check if class_target exists
		if ($(this._class_target).length < 1) return false;

		var this_tmp = this;
		var initial_state_tmp = this_tmp._inital_state;

		// assign to each class_target_group member a data value with the whole innerText
		$(this._class_target).each( function (_index) {
			
			var this_target = this;
			
			// memorize the content
			$(this).data('Content', $(this).html());
			
			// wrap the content
			var tmp_content = $(this).html();
			var tmp_prepend = '<div style="display: inline" class="' + this_tmp._class_content.split('.')[1] + '">';
			var tmp_append = '</div>';	
			var tmp_newcontent = tmp_prepend + tmp_content + tmp_append;
			
			$(this).html(tmp_newcontent);
			
			// add the trim/enlarge links
			tmp_content = $(this).html();
			tmp_append = this_tmp._link_enlarge + this_tmp._link_trim;
			tmp_newcontent = tmp_content + tmp_append;
	
			$(this).html(tmp_newcontent);
			
			// trigger the initial state
			if (initial_state_tmp) this_tmp.trim(this);
			else this_tmp.enlarge(this);
			
			// click bindings to the links
			$(this).children().filter(this_tmp._class_trim_link).click( function(event) {

				// deactivate href link
				event.preventDefault();
				
				// switch through showing and hiding clicked box
				this_tmp.trim(this_target);
				
				// deactivate href link
				return false;
				
			});

			$(this).children().filter(this_tmp._class_enlarge_link).click( function(event) {

				// deactivate href link
				event.preventDefault();
				
				// switch through showing and hiding clicked box
				this_tmp.enlarge(this_target);
				
				// deactivate href link
				return false;
				
			});	
			
		});

	}
	
}

/**
 * 
 * extendable class for showing and hiding info-boxes with the open/close icon
 * 
 * @author 		Robert Kararic robert1@kronomy.com
 * @since  		09.10.2009
 * 
 * th.ui.expandable  formally known as open/close box
 *	  
 *	  There must be a wrapper <div class="any_container_classname"> which 
 *	  acts as a container for the open/close-link: <a class="any_link_classname> 
 *	  and the content to be shown or hidden: <div class="any_content_classname">.
 *	  The link cannot be child of content and inversely.
 *
 *	  Initialization by "th.ui.expandable.init(class_container, class_content, class_link, initial_state)";
 *	  
 *	  There is no need to manually show/hide content or open/close the link, this
 *	  is set by the "initial_state" parameter. true: box is expanded; false: box is hidden; 
 *	    
 *		<script type="text/javascript">
 *			
 *			$(document).ready( function () {
 *				
 *				th.ui.expandable.init("ci_open_close_container_v3", "ci_open_close_content", "ci_open_close_link", false);
 *				
 *			});	
 *			
 *		</script>
 * 
 * 
 */
th.ui.expandable = {
	
	_class_container : '.open_close_container',
	_class_content : '.open_close_content',
	_class_contentfade : '.open_close_content_fade',
	_class_fade : '_fade',
	_class_link : '.open_close_link',
	_initial_state : false,
	_inprogress : false,

/**
 * 
 * th.ui.expandable.show(target);
 * 
 * expands the box and fades in the content.
 * 
 * @param string target		target tag from click eventhandler
 * 
 */
	show: function (target) {
		
		$(target).removeClass('open');
		$(target).addClass('close');

		// get the indexclassname for clicked open/close box 
		var _index = $(target).data('index').toString();
		// var _c_index_class = '.c_index_' + _index;
		// var _cf_index_class = '.cf_index_' + _index;
		var _c_index_class = $(target).data('class_content').toString() + _index;
		var _cf_index_class = $(target).data('class_contentfade').toString() + _index;

		// th.log(_c_index_class + ' ' + _cf_index_class);

		// get the stored height of the content
		var _content_class_height = $(_c_index_class).data('height');
		
		// th.log('height: ' + _content_class_height);

		var this_class = this;
		
		// First open the box then fade in the content as callback
		if (th.ui.isBrowser.chrome()) {
			$(_cf_index_class).css({'display' : 'block'});
			$(_c_index_class).css({'display' : 'block'});
			this_class._inprogress = false;
			if ($(_c_index_class).hasClass('scrollto')) $.scrollTo(target) ;
		}
		else {
			$(_c_index_class).height(_content_class_height).slideDown('fast', function () {
				$(_cf_index_class).fadeIn('normal', function () { 
					this_class._inprogress = false;
					if ($(_c_index_class).hasClass('scrollto')) $.scrollTo(target) ;
				});
			});
		}
		
		// th.log('show fertig');
		
		this._inprogress = this_class._inprogress;
		
	},
	
/**
 * 
 * th.ui.expandable.hide(target);
 * 
 * fades out the content and shrinks the the box.
 * 
 * @param string target		target tag from click eventhandler
 * 
 */
	hide: function (target) {

		$(target).removeClass('close');
		$(target).addClass('open');
		
		// get the indexclassname for clicked open/close box 
		var _index = $(target).data('index').toString();
		// var _c_index_class = '.c_index_' + _index;
		// var _cf_index_class = '.cf_index_' + _index;
		var _c_index_class = $(target).data('class_content').toString() + _index;
		var _cf_index_class = $(target).data('class_contentfade').toString() + _index;
		
		// th.log(_c_index_class + ' ' + _cf_index_class);

		// get the stored height of the content
		var _content_class_height = $(_c_index_class).data('height');
		
		var this_class = this;

		// First fade out then close the box as callback
		if (th.ui.isBrowser.chrome()) {
			$(_cf_index_class).css({'display' : 'none'});
			$(_c_index_class).css({'display' : 'none'});
			this_class._inprogress = false;
		}
		else {
			$(_cf_index_class).fadeOut('normal', function () {
				$(_c_index_class).height(_content_class_height).slideUp('fast', function () { this_class._inprogress = false; });
			});
		}

		this._inprogress = this_class._inprogress;
		
	},
	
/**
 * 
 * th.ui.expandable.toggle(target);
 * 
 * examines wheter the link has a open or close class and swiches through the states
 * 
 * @param string target		target tag from click eventhandler
 * 
 */
	toggle: function (target) {
		
		// set inprogress to prevent wild clicking
		this._inprogress = true;
		
		// th.log(target);

		// if expandable box is open change classname and hide it
		if ($(target).hasClass('close')) {

			this.hide(target);

		}

		// if expandable box is closed change classname and show it
		else if ($(target).hasClass('open')) {

			this.show(target);

		}
		
	},
	
/**
 * 
 * th.ui.expandable.init(class_container, class_content, class_link, initial_state);
 * 
 * initializes the open/close functionality. Mostly called in $(document).ready() event.
 * 
 * @param string 	class_container		class name for the <div> tag which wraps the open/close-link and -content
 * @param string 	class_content		class name for the <div> tag which wraps the content to be show or hidden
 * @param string 	class_link			class name for the <a> tag which gets the click handler for switching through the open/close states
 * @param boolean  	initial_state		true for opened and false for closed box at beginning
 * 
 */

	init: function (class_container, class_content, class_link, initial_state) {
		
		// if (th.ui.isBrowser.chrome()) return;
		
		// assign defaultvalues when there are no arguments passed within the function
		if (typeof class_container != 'undefined' && class_container != '') this._class_container = '.' + class_container;
		if (typeof class_content != 'undefined' && class_content != '') this._class_content = '.' + class_content;
		if (typeof class_link != 'undefined' && class_link != '') this._class_link = '.' + class_link;
		if (typeof initial_state == 'boolean') this._initial_state = initial_state;

		// th.log("_class_link: " + this._class_link);

		this._class_contentfade = this._class_content + this._class_fade;

		// if there exists no container, content or link: exit
		if ($(this._class_container).length < 1 || $(this._class_content).length < 1 || $(this._class_link).length < 1) return false;
		
		var this_tmp = this;
		
		var tmp_prepend = '<div class="' + this_tmp._class_contentfade.split('.')[1] + '">';
		var tmp_append = '</div>';
		var tmp_fadecontent;
		var tmp_newfadecontent;

		$.each($(this._class_content), function (_index) {

			// wrap the open/close content with an extra <div> for fading
			// Only firefox likes the $.wrapInner JQuery command. So the following is a workaround 
			var tmp_fadecontent = $(this).html();
			var tmp_newfadecontent = tmp_prepend + tmp_fadecontent + tmp_append;

			$(this).html(tmp_newfadecontent); 

		});				
		
		$.each($(this._class_content), function (_index) {
			
			// add new classname with appended index to current _class_content
			// $(this).addClass('c_index_' + _index.toString());
			$(this).addClass(this_tmp._class_content.split('.')[1] + _index.toString());
			
			// give every _class_content his height as data, because the height changes with every silde.
			// the slide effect animation acts strange when height is not known.
			$(this).data('height', $(this).height());
			// th.log($(this).show().height());
		
		});
		
		$.each($(this._class_contentfade), function (_index) {
			
			// add new classname with appended index to current _class_contentfade
			// $(this).addClass('cf_index_' + _index.toString());
			$(this).addClass(this_tmp._class_contentfade.split('.')[1] + _index.toString());

		});

		$.each($(this._class_link), function (_index) {
			
			// give every _class_link an index value as data
			$(this).data('index', _index.toString());
			$(this).data('class_conatiner', this_tmp._class_container);
			$(this).data('class_content', this_tmp._class_content);
			$(this).data('class_contentfade', this_tmp._class_contentfade);
			$(this).data('class_link', this_tmp._class_link);
		
		});
		
		// depending on the initial_state the expandable box will be set to open or closed
		if (this._initial_state) {
			
			if (! $(this._class_link).hasClass('close')) $(this._class_link).addClass('close');
			if ($(this._class_link).hasClass('open')) $(this._class_link).removeClass('open');
			$(this._class_content).css({'display' : 'block'});
			$(this._class_contentfade).css({'display' : 'block'});
			
		}
		else {
			
			if (! $(this._class_link).hasClass('open')) $(this._class_link).addClass('open');
			if ($(this._class_link).hasClass('close')) $(this._class_link).removeClass('close');
			$(this._class_content).css({'display' : 'none'});
			$(this._class_contentfade).css({'display' : 'none'});

		}
		
		var this_class = this;
	
		// add clickhandler to every open/close link for showing and hiding the expandable box
		$(this._class_link).click(function (event) {
			
			// deactivate href link
			event.preventDefault();
			
			// switch through showing and hiding clicked box
			if (! this_class._inprogress) this_class.toggle(this);
			
			// deactivate href link
			return false;
			
		});

	}
	
}


/**
 * 
 * Thickbox Wrapper
 * 
 */
th.ui.thickbox = {
	
	onCloseCallback : [],

	addOnCloseCallback: function(callback) {
		
		this.onCloseCallback.push(callback);
		
	},
		
	show: function ( caption, url, imageGroup , noLoadAnim )
	{
		$('#recaptcha_widget_div').remove();
		// Hide flash
		th.flash.blur();
		
		// Show Thickbox
		tb_show( caption, url, imageGroup , noLoadAnim , th.params.swfLoadingAnim, th.params.bucketPath + '/flash/expressInstall.swf');

		// Attempt Google Log
		try {

			// XXXRobert useless if clause: 
			// if pageTracker is or is not defined or null is not important, 
			// because pageTracker will be defined in ga_trackpageview
			// And there is no "path" but URL!!!

			// if ( typeof pageTracker != 'undefined' && pageTracker != null ) {
				// ga_trackpageview(path);
			// }
			
			th.ga.trackPageview(url);
			
			//if ( typeof pageTracker != 'undefined' && pageTracker != null ) {
				//ga_trackpageview(path);
			//}
		}catch (e) { 
			th.log('th.ga.trackPageview(' + url + '); failed: ' + e.toString()); 
		};
			
		return;
	},
	
	hide: function() {
		$('#recaptcha_widget_div').remove();
		tb_remove();
	}

};


/**
 * 
 * Loading Animation
 * 
 */
th.ui.loadingAnimation = {
		
		// alias
		show: function( targetId , _timeout) {
			th.ui.loadingAnimation.start( targetId , _timeout);
		},

		start: function( targetId , _timeout, _overlay ) {
	
			if ( typeof targetId == 'undefined' || targetId == '' ) {
				return;
			}
			if ( $(targetId + ':reallyvisible').size() < 1 ) {
				return;
			}
			
			// Stop existing animations
			$.loadAnimation.end();
			
			var ov_color = '#000';
			if ( typeof _overlay != 'undefined' ) 
			{ 
				if ( _overlay === false ) {
					ov_color = 'transparent';
				} else {
					ov_color = _overlay;
				}
			}
				
			// Set options
			var options = {
				    // Ein- / Ausblenden
				    loadSpeed: 'slow',
				    closeSpeed: 'fast',
				    // CSS Otionen
				    zIndex: 998,
				    opacity: 0.8,
				    // Farbe
				    color: ov_color,
				    loadingswf: th.params.swfLoadingAnim,
				    expressinstallswf: th.params.bucketPath + '/flash/expressInstall.swf',
				    
				    // Bild in der Mitte
				    image: {
				        src: '...',
				        alt: '...',
				 
				       // Grösse des Bildes wird benötigt um das Bild schön in der Mitte darzustellen.
				       size: {
				            width: 50,
				            height: 50
				        }
				    }
				};
			
			// Force end after timeout value
			if (typeof _timeout != 'undefined' && _timeout != false)
			{
				setTimeout(function() { $.loadAnimation.end(); }, _timeout);
			}
			
			$(targetId).css('display', 'block');
			$(targetId).loadAnimation(options);
		},
		
		// alias
		hide: function() {
			th.ui.loadingAnimation.stop();
		},
		stop: function(  ) {
			try {
				$.loadAnimation.end();
				$('#exposeMask').remove();
			} catch (e) {}
		}

};



/**
 * @project talenthouse
 * @package th.ui.scroller
 * @since   07.05.2009
 *
 * Scroll Object: applies custom HORIZONTAL scroll to target container
 * 
 * XXXRobert Maybe not needed anymore
 * 
 */
th.ui.scroller = {
	reset: function ( target ) {
		var itemCount = $('li', $(target)).size();
		var liItem = $('ul li:first', $(target));
		var totalWidth = liItem.width();	// Item Width
		totalWidth += (parseInt(liItem.css("padding-left"), 10) || 0) + (parseInt(liItem.css("padding-right"), 0) || 0); 		//Total Padding Width
		totalWidth += (parseInt(liItem.css("margin-left"), 10) || 0) + (parseInt(liItem.css("margin-right"), 0) || 0); 			//Total Margin Width
		totalWidth += (parseInt(liItem.css("borderLeftWidth"), 10) || 1)  + (parseInt(liItem.css("borderRightWidth"), 0) || 1)  ;	//Total Border Width
		var rowWidth = ( itemCount * totalWidth );
		$(target + ' ul').width(rowWidth);
	},
	
	init: function( target ) {
		this.reset( target );
		
		return true;
	}
	
};

/**
 * Wrapper for scrollable and scrollable.circular plugin from
 * http://flowplayer.org/tools/scrollable.html
 * 
 * @author 		Robert Kararic [robert1@kronomy.com]
 * @since 		08.10.2009
 * 
 * USAGE:
 * 
 * There must be a wrapper <div class="scrollable"></div> tag for all items to be scrolled.
 * The items themselves again have to be wrapped by a <div class="items"></div> tag.
 * If an item has a group of tags every group has to be wrapped by a <div class="item></div> tag.
 * 
 * <div id="id_for_initialization" class="scrollable">
 * 
 * 		<div class="items">
 * 
 * 			<div class="item">
 * 				<p></p>
 * 				<img></img>
 * 				<...></...>
 * 			</div>
 * 
 * 			<div class="item">
 * 				<p></p>
 * 				<img></img>
 * 				<...></...>
 * 			</div>
 * 
 * 		</div>
 * 
 * </div>
 * 
 * Intialization by "th.ui.scrollable.init(target, interval, scrollitemsperpage, showitemsperpage);" 
 * mostly in the $(document).ready() event handler, e.g. scrollInit("#ci_big_scroller", 3000, 2000, 1, 3);
 * 
 */

th.ui.scrollable = {
	
/**
 * th.ui.scrollable.init( target, interval, scrollspeed, scrollitemsperpage, showitemsperpage );
 * 
 * @param string target				the id of the all wrapping <div> tag which contains the "scrollable" class 
 * @param int intervall				time in milliseconds the scroll procedure pauses
 * @param int scrollitemsperpage	number of items scrolled in one procedure
 * @param int showitemsperpage		number of items visible on screen
 * 
 */  
 
	_target : null,
	_interval : null,
	_scrollspeed : null,
	_scrollitemsperpage : null,
	_showitemsperpage : null,
	
	_scrollapi : null,
	_scrollapi_conf : null,
	
	_scroll_left_target : null,
	_scroll_right_target : null,

	begin: function() {
		
		if ($(this._target).size() < 1) return false;
		
		if (typeof this._scrollapi == 'undefined') return;
		
		this._scrollapi.begin();
		
	},

	init: function( target, scroll_left_target, scroll_right_target, scrollspeed, scrollitemsperpage, showitemsperpage ){
	
		// set default values if there are no or not all arguments commited
		this._target = typeof target != 'undefined' ? target : "#scroller";
		this._scrollspeed = typeof scrollspeed != 'undefined' ? scrollspeed : 1000;
		this._scrollitemsperpage = typeof scrollitemsperpage != 'undefined' ? scrollitemsperpage : 3;
		this._showitemsperpage = typeof showitemsperpage != 'undefined' ? showitemsperpage : 3;
		this._scroll_left_target = typeof scroll_left_target != 'undefined' ? scroll_left_target : '#scroll_left';
		this._scroll_right_target = typeof scroll_right_target != 'undefined' ? scroll_right_target : '#scroll_right';
		
		// exit if there is no scrollable container
		if ($(this._target).size() < 1) return false;
		
		// initializes the scrollable plugin
		this._scrollapi = $(this._target).scrollable().circular({
			api : true,
			size : this._showitemsperpage
		});
	
		// exit if the plugin initialization failes
		if (typeof this._scrollapi == 'undefined') return false;
		
		// creates an custom easing for animation
		$.easing.custom = function (x, t, b, c, d) {
		     var s = 1.70158;      
			 if ((t/=d/2) < 1) 
			 	return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;     
			 return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b; 
		}
		
		// get the configuration object from the plugin to change properties
		this._scrollapi_conf = this._scrollapi.getConf();
	
		// exit if no configuration object is returned
		if (typeof this._scrollapi_conf == 'undefined') return false;
		
		// some configure
		this._scrollapi_conf.clickable = false;
		this._scrollapi_conf.speed = this._scrollspeed;
		this._scrollapi_conf.easing = 'custom';
		
		var this_tmp = this;
		
		$(this._scroll_left_target).click( function() {
			
			this_tmp._scrollapi.move( - this_tmp._scrollitemsperpage);
			
		});
				
		$(this._scroll_right_target).click( function() {
			
			this_tmp._scrollapi.move(this_tmp._scrollitemsperpage);
			
		});
				
		// else return the scrollable object for further control
		return this._scrollapi;

	}

};


/**
 * @project talenthouse
 * @package th.ui.sortable
 * @since   07.05.2009
 *
 * Sortable Interface: for drag and drop
 * 
 */

 th.ui.sortable = function( type , projectid , activetab , target , updateUrl , _params, tm ) {

     var defaults = {
   		 /*
   		 start: function(event, ui) { 
    	 	if ( $('.toppic', $(ui.item)).size() > 0 ) {
    	 		$(this).sortable('cancel');	
    	 	}
     	 },
     	 */
         update: function(event, ui) {
    	 	var comma = '';
    	 
	        // Toggle marked class [undo select initiated by 
			//	click - because this is a move, not a select]
	        if (tm) {
	            if ($(ui.item).hasClass('markedItem')){
	                $(ui.item).removeClass('markedItem');
	            } else {
	                $(ui.item).addClass('markedItem');
	            }
	        }
	         
	        // prepare flash update vars
			var itemId = $(ui.item).attr('id');
			var nextId = $(ui.item).next().attr('id');
			var prevId = $(ui.item).prev().attr('id');
		 
		 	if (typeof itemId == 'undefined')
		 		return;
		 	if (typeof nextId == 'undefined')
		 		nextId = '';
		 	if (typeof prevId == 'undefined')
		 		prevId = '';
		 	
    
            if (type == "project")
            {
            	th.projectsList.updateOrder();
            	
            }
            else
            {

            	th.myprofile.medialist.updateMediaOrder(activetab, projectid);
            	if (activetab == 'artwork') {
            		th.myprofile.medialist.checkTopPic();
            	}
            	
	        }
                
         },
         scroll : true,
         container: target,
         opacity: 0.5,
         cursor: 'move',
         handle: '.handle',
         cancel: '.nodrag',
         tolerance: 'pointer',
         cursorAt: { left: 53, top: 27 }

     };


     // Setup Sortable Interface
     var params = $.extend(defaults, _params || {});
     th.log('SORTABLE: TARGET: ' + target);
     $( target + ' ul' ).sortable( params );	

     return;
 };


th.ui.form = {
	
	// Vars to store link data
	link: '',
	target: '',
	sourceForm: '',
	inProgress: false,
	animationTarget: false,
	overlayBackground: '#000',

	submit: function(_link, _data)
	{
		th.log('th.ui.form.submit depreciated; use submitform');
		
		var form = $(_link).parents('form:first').attr('id');
		var data = _data;
		th.ui.form.submitform(form, data);
	},
	
	simpleSubmit: function(_form, _link) {
		var form = _form;
		th.ui.form.submitform(form);
	},
	
	
	/**
	 * @project talenthouse
	 * @package th.ui.form
	 * @method  submitform
	 * @since   07.05.2009
	 *
	 * Submits a form, preventing double submit, handling JSON error results 
	 * & loading animations
	 * 
	 * @param  form The id of the source form
	 * @param  _additionalData, Additional info to submit: e.g. { 'myname' : 'kevin' }
	 * @param  _animationTarget Normally loading animation covers the form; this optional param overrides it
	 * @param  _overlayBackground Sets the Background color for the loading Animation
	 */
	submitform: function(form, _additionalData, _animationTarget, _overlayBackground)
	{
		// Prevent double submit
		if ( th.ui.form.inProgress ) {
			return false;
		}
		
		if ( typeof _additionalData != 'object' ) {
			if ( typeof _additionalData != 'undefined' ) {
				th.log('th.ui.form.submit: _additionaldata is not an object');
			}
			_additionalData = {};
		}
		
		th.ui.form.inProgress = true;
		
		// Get DOM Ids
		th.ui.form.sourceForm = form;
		th.ui.form.target = $(th.ui.form.sourceForm).attr('target');
		
		// prevent double submit
		var fId = $(th.ui.form.sourceForm).attr('id');
		
		// remove Form target from panel cache
		th.ui.panels.markPanelLoaded('', th.ui.form.target);

		if (typeof _animationTarget != 'undefined' && _animationTarget != '') { 
			th.ui.form.animationTarget = _animationTarget;
		} else {
			th.ui.form.animationTarget = form;
		}
		
		// Customizeable overlayBackground.
		if (typeof _overlayBackground != 'undefined' && _overlayBackground != '') {
			th.ui.form.overlayBackground = _overlayBackground;
		} else {
			th.ui.form.overlayBackground = '#000';
		}
		
		// If Hints Blur used, remove values:
		$('.hints_blur').each(function(){
			if ($(this).attr('title') == $(this).val()) {
				$(this).val('');
			}
		});
		
		// Grab url 
		var path = $(th.ui.form.sourceForm).attr('action');
		
		// Submit Form:
		$(th.ui.form.sourceForm).ajaxSubmit({
			success: function(data) { th.ui.form.submitSuccess(data,path); },
			complete: th.ui.form.submitComplete,
			beforeSubmit: th.ui.form.beforeSubmit,
			data: _additionalData
		});
		
		return false;
	},

	beforeSubmit: function() {
		// Save submit buttons:
		th.ui.loadingAnimation.start(th.ui.form.animationTarget, false, th.ui.form.overlayBackground);
	},
	
	submitSuccess: function(data,path)
	{
		try {
			var jsonObj = JSON.parse(data); // eval('var obj='+'(' + x + ')'); 
		}
		catch (e) { }

		// if json result 
		if (typeof jsonObj == 'object')
		{
			var errorFound = false;

			// Process Errors Returned
			for ( errInputFieldId in jsonObj ) {
				
				// Get Error Object for current field
				errorDescObj = jsonObj[errInputFieldId];

				// Get Error String
				for ( errorStrKey in errorDescObj) {
					$('#' + errInputFieldId).bt(
							errorDescObj[errorStrKey],
							th.params.bt_Error_Options);
					$('#' + errInputFieldId).addClass('error');
					$('#' + errInputFieldId).change(function () {
						$(this).removeClass('error');
					});

					if (! errorFound ) {
						errorFound = true;
						// Focus on first field
						$('#' + errInputFieldId).focus();
					}
				}
			}

		} else {
			if (data == '') {
				// Remove mask
				th.ui.loadingAnimation.stop();
				// Remove thickbox
				th.ui.thickbox.hide();
			} else {
				// Remove mask
				th.ui.loadingAnimation.stop();
				// not json
				$(th.ui.form.target).html(data);
			}
		}

		// Init links
		th.ui.panels.initAjaxLinks();
		// Execute Callbacks
		th.ajax.executeOnLoadCallbacks();


		// Attempt Google Log
		try {

			// XXXRobert useless if clause: 
			// if pageTracker is or is not defined or null is not important, 
			// because pageTracker will be defined in ga_trackpageview

			th.ga.trackPageview(path);
			
			//if ( typeof pageTracker != 'undefined' && pageTracker != null ) {
				//ga_trackpageview(path);
			//}
		}catch (e) { 
			th.log('th.ga.trackPageview(' + path + '); failed: ' + e.toString()); 
		};
	},

	submitComplete: function(XMLHttpRequest, textStatus, errorThrown) 
	{
		// Remove loading animation
		th.ui.loadingAnimation.stop();
		
		// Allow future submit
		th.ui.form.inProgress = false;
	}	
	

};



	


