window._refresh_interval = 300;
window._refresh_delay = 1.5;

var tabs = Class.create();
tabs.prototype = {
   initialize : function(element) {
          this.element = $(element);
                var options = Object.extend({}, arguments[1] || {});
                this.setQueryFocus();
              this.menu = $A(this.element.select('a'));
           //this.show(this.getInitialTab());
          this.menu.each(this.setupTab.bind(this));
 },
        setupTab : function(elm) {
                Event.observe(elm,'click',this.activate.bindAsEventListener(this),false)
  },
        activate :  function(ev) {
                var elm = Event.findElement(ev, "a");
           Event.stop(ev);
           this.show(elm);
           this.menu.without(elm).each(this.hide.bind(this));
           this.setDestination(elm);
           this.setQueryFocus();
        },
        hide : function(elm) {
            $($(elm).parentNode).removeClassName('thisPage');
             $(this.tabID(elm)).removeClassName('focus');
    },
        show : function(elm) {
            $($(elm).parentNode).addClassName('thisPage');
                $(this.tabID(elm)).addClassName('focus');
  },
        tabKey : function(elm) {
           return elm.id.match(/tab\-(\w.+)/)[1];
      },
        tabID : function(elm) {
           return 'sc-'+this.tabKey(elm);
      },
        setDestination : function(elm) {
        	$('search_destination').value = (this.tabKey(elm));
        },
        setQueryFocus : function() {
        	$('q').focus();
        }
}

// Static definition of Month names
Date.MONTH_NAMES = [
"January", "February", "March",
"April", "May", "June",
"July", "August", "September",
"October", "November", "December" ];

// Static definition of weekday names
Date.WEEKDAY_NAMES = [
"Sunday", "Monday", "Tuesday",
"Wednesday", "Thursday", "Friday",
"Saturday" ];

// clone the current date object and return a different object with identical value
Date.prototype.clone = function () {
  return new Date(this.getTime());
}

// clear the time information from this date and return it
Date.prototype.clearTime = function () {
  this.setHours(0); this.setMinutes(0);
  this.setSeconds(0); this.setMilliseconds(0);
  return this;
}

// return the last day of this month
Date.prototype.lastDay = function () {
  var tempDate = this.clone();
  tempDate.setMonth(tempDate.getMonth()+1);
  tempDate.setDate(0);
  return tempDate.getDate();
}

// return number of days since start of year
Date.prototype.getYearDay = function () {
  var today = new Date(this);
  today.setHours(0); today.setMinutes(0); today.setSeconds(0);
  var tempDate = new Date(today);
  // set start of year
  tempDate.setDate(1);
  tempDate.setMonth(0);
  return Math.round(
  (today.getTime() - tempDate.getTime())
  / 86400 / 1000) + 1; // Jan/1 is day 1
}

// add format() to Date
Date.prototype.format = function(formatString) {
  var out = new String();
  var token = ""
  for (var i = 0; i < formatString.length; i++) {
    if (formatString.charAt(i) == token.charAt(0)) {
      token = token.concat(formatString.charAt(i));
      continue;
    }
    out = out.concat(this.convertToken(token));
    token = formatString.charAt(i);
  }
  return out + this.convertToken(token);
}

// internal call to map tokens to the date data
Date.prototype.convertToken = function (str) {
  switch(str.charAt(0)) {
    case 'y': // set year
      if (str.length > 2)
      return this.getFullYear();
      return this.getFullYear().toString().substring(2);
    case 'd': // set date
      return Date.zeroPad(this.getDate(),str.length);
    case 'e': // date ending (st/nd/rd/th)
      return this.getDateSuffix();
    case 'D': // set day in year
      return this.getYearDay();
    case 'a':
      return this.getHours() > 11 ? "pm" : "am";
    case 'H': // set hours
      return Date.zeroPad(this.getHours(),str.length);
    case 'h':
      return Date.zeroPad(this.get12Hours(),str.length);
    case 'm': // set minutes
      return Date.zeroPad(this.getMinutes(),2);
    case 's': // set secondes
      return Date.zeroPad(this.getSeconds(),2);
    case 'S': // set milisecondes
      return Date.zeroPad(this.getMilliseconds(),str.length);
    case 'x': // set epoch time
      return this.getTime();
    case 'Z': // set time zone
      return (this.getTimezoneOffset() / 60) + ":" +
      Date.zeroPad(this.getTimezoneOffset() % 60,2);
    case 'M': // set month
      if (str.length > 3) return this.getFullMonthName();
      if (str.length > 2) return this.getShortMonthName();
      return Date.zeroPad(this.getMonth()+1,str.length);
    case 'E': // set dow
      if (str.length > 3) return this.getDOWName();
      if (str.length > 1) return this.getShortDOWName();
      return this.getDay();
      default:
      return str;
  }
}

// Retreive the month's name in english
Date.prototype.getFullMonthName = function() {
  return Date.MONTH_NAMES[this.getMonth()];
}

// Retreive the abberviated month name in english
Date.prototype.getShortMonthName = function() {
  return Date.MONTH_NAMES[this.getMonth()].substring(0,3);
}

// Retreive the week day name in english
Date.prototype.getDOWName = function () {
  return Date.WEEKDAY_NAMES[this.getDay()];
}

// Retreive the abberviated week day name in english
Date.prototype.getShortDOWName = function () {
  return Date.WEEKDAY_NAMES[this.getDay()].substring(0,3);
}

// Retreive the hour in a 12 hour clock (without the AM/PM specification)
Date.prototype.get12Hours = function () {
  return this.getHours() == 0 ? 12 :
  (this.getHours() > 12 ? this.getHours() - 12 : this.getHours());
}

Date.prototype.getDateSuffix = function () {
	d = this.getDate();
	if (d==1 || d == 21 || d == 31)
			return 'st';
	else if (d == 2 || d == 22)	
			return 'nd';
	else if (d == 3 || d == 23)	
			return 'rd';
	else
		return 'th';
}

// helper function to add required zero characters to fixed length fields
Date.zeroPad = function(num, width) {
  num = num.toString();
  while (num.length < width)
  num = "0" + num;
  return num;
}


function startclock()
{
	var now = new Date();
		
	$('now').update(now.format('h:mma EEEE, de MMMMM'));
	
	setTimeout('startclock()',10000);
}



var Tooltip = Class.create();
Tooltip.prototype = {
  initialize: function(element, tool_tip) {
    var options = Object.extend({
      default_css: false,
      margin: "0px",
	    padding: "5px",
	    backgroundColor: "#d6d6fc",
	    min_distance_x: 5,
      min_distance_y: 5,
      delta_x: 0,
      delta_y: 0,
      zindex: 1000
    }, arguments[2] || {});

    this.element      = $(element);

    this.options      = options;
    
    // use the supplied tooltip element or create our own div
    if($(tool_tip)) {
      this.tool_tip = $(tool_tip);
    } else {
      this.tool_tip = $(document.createElement("div")); 
      document.body.appendChild(this.tool_tip);
      this.tool_tip.addClassName("tooltip");
      this.tool_tip.appendChild(document.createTextNode(tool_tip));
    }

    // hide the tool-tip by default
    this.tool_tip.hide();

    this.eventMouseOver = this.showTooltip.bindAsEventListener(this);
    this.eventMouseOut   = this.hideTooltip.bindAsEventListener(this);
    this.eventMouseMove  = this.moveTooltip.bindAsEventListener(this);

    this.registerEvents();
  },

  destroy: function() {
    Event.stopObserving(this.element, "mouseover", this.eventMouseOver);
    Event.stopObserving(this.element, "mouseout", this.eventMouseOut);
    Event.stopObserving(this.element, "mousemove", this.eventMouseMove);
  },

  registerEvents: function() {
    Event.observe(this.element, "mouseover", this.eventMouseOver);
    Event.observe(this.element, "mouseout", this.eventMouseOut);
    Event.observe(this.element, "mousemove", this.eventMouseMove);
  },

  moveTooltip: function(event){
	  Event.stop(event);
	  // get Mouse position
    var mouse_x = Event.pointerX(event);
	  var mouse_y = Event.pointerY(event);
	
	  // decide if wee need to switch sides for the tooltip
	  var dimensions = Element.getDimensions( this.tool_tip );
	  var element_width = dimensions.width;
	  var element_height = dimensions.height;
	
	  if ( (element_width + mouse_x) >= ( this.getWindowWidth() - this.options.min_distance_x) ){ // too big for X
		  mouse_x = mouse_x - element_width;
		  // apply min_distance to make sure that the mouse is not on the tool-tip
		  mouse_x = mouse_x - this.options.min_distance_x;
	  } else {
		  mouse_x = mouse_x + this.options.min_distance_x;
	  }
	
	  if ( (element_height + mouse_y) >= ( this.getWindowHeight() - this.options.min_distance_y) ){ // too big for Y
		  mouse_y = mouse_y - element_height;
	    // apply min_distance to make sure that the mouse is not on the tool-tip
		  mouse_y = mouse_y - this.options.min_distance_y;
	  } else {
		  mouse_y = mouse_y + this.options.min_distance_y;
	  } 
	
	  // now set the right styles
	  this.setStyles(mouse_x, mouse_y);
  },
	
		
  showTooltip: function(event) {
    Event.stop(event);
    this.moveTooltip(event);
	  new Element.show(this.tool_tip);
  },
  
  setStyles: function(x, y){
    // set the right styles to position the tool tip
	  Element.setStyle(this.tool_tip, { position:'absolute',
	 								    top:y + this.options.delta_y + "px",
	 								    left:x + this.options.delta_x + "px",
									    zindex:this.options.zindex
	 								  });
	
	  // apply default theme if wanted
	  if (this.options.default_css){
	  	  Element.setStyle(this.tool_tip, { margin:this.options.margin,
		 		  						                    padding:this.options.padding,
		                                      backgroundColor:this.options.backgroundColor,
										                      zindex:this.options.zindex
		 								    });	
	  }	
  },

  hideTooltip: function(event){
	  new Element.hide(this.tool_tip);
  },

  getWindowHeight: function(){
    var innerHeight;
	  if (navigator.appVersion.indexOf('MSIE')>0) {
		  innerHeight = document.body.clientHeight;
    } else {
		  innerHeight = window.innerHeight;
    }
    return innerHeight;	
  },
 
  getWindowWidth: function(){
    var innerWidth;
	  if (navigator.appVersion.indexOf('MSIE')>0) {
		  innerWidth = document.body.clientWidth;
    } else {
		  innerWidth = window.innerWidth;
    }
    return innerWidth;	
  }

}

Object.extend(window,{	
	openedWindows: {},
	openCentered: function(location,name,params){
		this.openedWindows[name] = window.open(location,name,$H({
			width: 800,
			height: 600,
			left: Math.round((screen.width ? (screen.width - (params && params.width ? params.width : 800)) / 2 : 0)),
			top: Math.round((screen.height ? (screen.height - (params && params.height ? params.height : 600)) / 4 : 0)),
			dependent: true,
			directories: false,
			fullscreen: false,
			location: false,
			menubar: false,
			resizable: false,
			scrollbars: true,
			status: false,
			toolbar: false
		}).merge(params || {}).inject('',function(str,item){
			if(item[1] == true)
				value = 'yes';
			else if(item[1] == false)
				value = 'no';
			else
				value = item[1];
			return str + item[0] + '=' + value + ',';
		}).replace(/\,$/,''));
		this.openedWindows[name].focus();
		return this.openedWindows[name];
	}
});

var widgetInstanceID = function(elm) {
	return elm.select('.widget_iid').first().getValue();
}
var widgetUniqueID = function(elm) {
	return elm.id;
}
	
var refreshWidget = function(elm, shell) {
	if (typeof elm == 'string' || typeof elm == 'number') { elm = $('widget_' + elm); };
	if (!elm) { return; };
	
	elm.select('.widget_body_ctn').first().hide();
	elm.select('.widget_editpane').first().hide();
 	elm.select('.widget_loading').first().show();
 	//elm.select('.widget_inner').first().show();
 	toggleWidgetDown(elm);
 	
 	params = $H({
 		sid: window._sessionid,
 		uid: window._userid,
 		wuid: widgetUniqueID(elm),
 		wiid: widgetInstanceID(elm)
 	});
 	
 	if (shell) {
 		var widget_ctn_id = 'a' + widgetUniqueID(elm); // awidget_xx
 		params = params.merge({a: 'render_shell'});
 		new Ajax.Updater(widget_ctn_id, '/callback/widget', {
 		parameters: params,
 		onComplete: function(t) { initWidgets(widget_ctn_id, true); },
    on409: function(transport) { reloadPage(); }
 		});
 	} else {
 		new Ajax.Updater(elm.select('.widget_body').first(), '/callback/widget', {
    		parameters: params,
    		onComplete: function(transport) { updateWidget(elm); },
    		on409: function(transport) { reloadPage(); }
	  	});
 	};
}
	
var toggleWidget = function(elm) {
	if (typeof elm == 'string') { elm = $('widget_' + elm); };
	if (!elm) { return; };
	
	var hidden = (elm.select('.widget_inner').first().getStyle('display') != 'none'); 
    Effect.toggle(elm.select('.widget_inner').first(), 'blind', {duration: 0.3 });
    var params = 'sid=' + window._sessionid + '&uid=' + window._userid + '&a=toggle_widget&wuid=' + widgetUniqueID(elm) + '&hidden=' + hidden;
	new Ajax.Request('/callback/', {parameters:params, onFailure:errFunc});
	equaliseColumnHeights();
};

var toggleWidgetDown = function(elm) {
	if (typeof elm == 'string') { elm = $('widget_' + elm); };
	if (!elm) { return; };
	
	var hidden = (elm.select('.widget_inner').first().getStyle('display') != 'none'); 
	if (!hidden) {
		toggleWidget(elm);
	}
}

var toggleEditPane = function(elm) {
	if (typeof elm == 'string') { elm = $('widget_' + elm); };
	if (!elm) { return; };
	
	toggleWidgetDown(elm);

	var ep = elm.select('.widget_editpane').first();
	var hidden = (ep.getStyle('display') == 'none'); 
	elm.select('.widget_body_ctn').first().show();
    Effect.toggle(ep, '', {duration: 0.4 });
    if (hidden) {
	    var params = 'sid=' + window._sessionid + '&uid=' + window._userid + '&wuid=' + widgetUniqueID(elm) + '&wiid=' + widgetInstanceID(elm);
		new Ajax.Updater(ep, '/callback/widget',
  		{
    		//method: 'get',
    		parameters: params + '&a=edit',
    		onComplete: function(transport) { editFormLoaded(elm, ep); },
    		on409: function(transport) { reloadPage(); }
  		});
    }
};


var editFormLoaded = function(elm, f) {
	b = f.select('.w_edit_close');
	if (b.size() > 0) {
		Event.observe(b.first(), 'click', function(ev) {
			Event.stop(ev);
			f.hide(); 
			}
		);
	}
	initWidgetForm(elm, f);
}

var initWidgetForm = function(w, f) {
	f.select('input').each(function(i) {
		if (i.type=='submit' || i.type=='image') {
	    	i.observe('click', function(ev) { 
	    		Event.stop(ev);
				submitWidgetForm(w, f, i);
			});
		};
	});	
}

var submitWidgetForm = function(w, f, sub) {
	//
    var params = $H({
    	sid: window._sessionid,
    	uid: window._userid,
    	wuid: widgetUniqueID(w),
    	wiid: widgetInstanceID(w),
    	a: f.action.toLowerCase()
    });
    params = params.merge(f.serialize(true));
    
    // remove submit controls
	f.select('input').each(function(i) {
		if (i.type=='submit' || i.type=='image') {
			params.unset(i.name);
		}
	});
	
	if (sub) {
		n = sub.name;
		v = sub.value;
		if (!v) { v = '1'; };
		params[n] = v;
	}

	new Ajax.Request('/callback/widget',
		{
		parameters: params,
		onSuccess: function(transport) { refreshWidget(w, true); },
    on409: function(transport) { reloadPage(); },
		onFailure: function(transport) { refreshWidget(w, true); }
		}
	);
}

function saveWidgetOrder() {
	var data = Sortable.serialize('widgets_c1', {tag:'div',name:'c1'}) + '&' + Sortable.serialize('widgets_c2', {tag:'div',name:'c2'}) + '&' + Sortable.serialize('widgets_c3', {tag:'div',name:'c3'});
	var params = 'sid=' + window._sessionid + '&uid=' + window._userid + '&a=reorder_widgets&' + data;
	new Ajax.Request('/callback/', {parameters:params, onFailure:errFunc, asynchronous:true});
	equaliseColumnHeights();
}

var errFunc = function(t) {
    // alert('Error ' + t.status + ' -- ' + t.statusText);
}

var updateWidget = function(elm) {
	if (typeof elm == 'string') { elm = $('widget_' + elm); };
	if (!elm) { return; };
	
	elm.select('.widget_loading').first().hide();
	elm.select('.widget_body_ctn').first().show();
    
  make_links_new_window(elm);
	equaliseColumnHeights();  
}

var openWindow = function(wuid, wiid, action, options) {
	options = $H({
			width: null,
			height: null
		}).merge(options || {});	
	
	w = window.openCentered(window._secure_callback_url + 'widget?sid=' + window._sessionid + '&uid=' + window._userid + '&wuid=' + wuid + '&wiid=' + wiid + '&a=' + action, 'window_' + wuid, options);
}

var closeWindow = function(wid) {
	w = window.openedWindows['window_' + wid];
	if (w) { w.close(); }
	// use P.E. with 0.1s time instead of immediate execution to avoid bug in FF
	new PeriodicalExecuter(function(pe) {
		 pe.stop(); refreshWidget(wid);
		}, 0.1);
	
}

var reloadPage = function() {
	window.location.reload(true);
}

var initWidgets = function(parentEl, load) {
	if (typeof parentEl == 'string') { parentEl = $(parentEl); };
	if (!parentEl) { return; };
	
	parentEl.select('.widget').each(function(elm) {
	
	    Event.observe(elm.select('.widget_tog').first().down(), 'click', function(ev) { 
	    	Event.stop(ev); 
	    	toggleWidget(elm);     	
	    });
	     	
	    Event.observe(elm.select('.widget_del').first().down(), 'click', function(ev) {
	    	Event.stop(ev);
	    	if (!confirm('This item will be removed from your page. Do you want to continue?')) {
	    		return;
	    	};
	    	Effect.SwitchOff(elm);
	    	var params = 'sid=' + window._sessionid + '&uid=' + window._userid + '&a=del_widget&wuid=' + widgetUniqueID(elm);
	    	new Ajax.Request('/callback/', {parameters:params, onFailure:errFunc });     	
	    });
	
	   	Event.observe(elm.select('.widget_tlc').first(), 'dblclick', function(ev) { toggleWidget(elm); });
	     	
	    r = elm.select('.widget_refresh');
	    if (r.size() > 0) { Event.observe(r.first().down(), 'click', function(ev) { 
	  		Event.stop(ev);
			refreshWidget(elm);     		
	    })};
	
	    r = elm.select('.widget_edit');
	    if (r.size() > 0) { Event.observe(r.first().down(), 'click', function(ev) { 
	  		Event.stop(ev);
			toggleEditPane(elm);     		
	    })};
	
	    r = elm.select('.widget_editpane');
	    if (r.size() > 0) { 
	    	var f = r.first();
			f.observe('submit', function(ev) { 
				Event.stop(ev); 
				submitWidgetForm(elm, f);
			});	    	
			initWidgetForm(elm, f);
	    };
	    
	    Event.observe(elm, 'mouseover', function(ev) { elm.addClassName('w_hover'); } );
	    Event.observe(elm, 'mouseout', function(ev) { elm.removeClassName('w_hover'); } );
	});
     
  if (window._autorefresh) {
		parentEl.select('.w_async', '.w_inline_autorefresh').each(function(elm) {
			new PeriodicalExecuter(function(pe) {
				pe.stop();
				new Ajax.PeriodicalUpdater(elm.select('.widget_body').first(), '/callback/widget',	{
					onSuccess: function() { new PeriodicalExecuter(function(pe) {
						pe.stop();
						updateWidget(elm); },
						1); },
					on409: function(transport) { reloadPage(); },
					frequency: window._refresh_interval, decay: window._refresh_delay, parameters: 'sid=' + window._sessionid + '&uid=' + window._userid + '&wuid=' + widgetUniqueID(elm) + '&wiid=' + widgetInstanceID(elm)
				});
			}, window._refresh_interval);
		}); 	
		
		parentEl.select('.w_inline', '.w_inline_autorefresh').each(function(elm) {
			make_links_new_window(elm);
		});
		
	};
		     
	if (load) {
		parentEl.select('.w_async', '.w_async_norefresh').each(function(elm) {
		   	new Ajax.Updater(elm.select('.widget_body').first(), '/callback/widget',	{
				parameters: 'sid=' + window._sessionid + '&uid=' + window._userid + '&wuid=' + widgetUniqueID(elm) + '&wiid=' + widgetInstanceID(elm),
				onSuccess: function() { new PeriodicalExecuter(function(pe) {
					pe.stop();
					updateWidget(elm); },
					1); }
		  	});
		}); 	
	}
		
	parentEl.select('.widget_first_display').each(function(elm) {
		header = elm.select('h2').first();
		if (header) {
//			alert(header);
		new Effect.Highlight(header, {duration: 5});
//			header.setStyle({backgroundColor: 'transparent'});
		}
	});
	
	initSortables();
	equaliseColumnHeights();
};

var make_links_new_window = function(parent) {
	if (!window._links_new_window || window._links_new_window == '0') return;
	
    r = parent.select('.widget_body');
    if (r.size() > 0) { 
		r.first().select('a').each(function(elm) {
			if (elm.hasClassName('showEditPane')) {
		 		elm.observe('click', function(ev) {
		 			Event.stop(ev);
		 			toggleEditPane(parent);     			
		 			return false;
		 		});
			} else if (elm.getAttribute("href") && (elm.getAttribute("href")!='#') && (elm.getAttribute("href")!=window.location+'#') && !elm.hasClassName('sameWindow') ) {
		 		elm.target = (window._links_new_window == '2') ? '_blank' : parent.id;
		 		elm.observe('click', function(ev) {
		 			Event.stop(ev);
		 			w = window.open(elm.href, elm.target);     			
		 			w.focus();
		 		});
			}
		});
    };

}

var initSortables = function() {
	Sortable.create("widgets_c1", {tag:'div',only:'widget_ctn',handle:'widget_tlc',dropOnEmpty:true,containment:["widgets_c1","widgets_c2","widgets_c3"],constraint:false,onUpdate:saveWidgetOrder});
	Sortable.create("widgets_c2", {tag:'div',only:'widget_ctn',handle:'widget_tlc',dropOnEmpty:true,containment:["widgets_c1","widgets_c2","widgets_c3"],constraint:false,onUpdate:saveWidgetOrder});
	Sortable.create("widgets_c3", {tag:'div',only:'widget_ctn',handle:'widget_tlc',dropOnEmpty:true,containment:["widgets_c1","widgets_c2","widgets_c3"],constraint:false,onUpdate:saveWidgetOrder});
}

var initTopHalf = function() { 
	new tabs('tabs');
	startclock();

}

//new Tooltip('link_send', 'Tell your friends about the ClickUni Start! page');
Event.observe(window, 'load', function() {
	new Tooltip('link_facebook', 'Like it? Spread the word!');
	new Tooltip('link_homepage', 'Set ClickUni Start! to be your home page');
 });
 
var initHighlighting = function(ctn) {
	ctn.select('a.img').each(function (e) {
		Event.observe(e, 'mouseover', function(ev) { high(e); });		
		Event.observe(e, 'mouseout', function(ev) { low(e); });		
	} );
}

function high(which2){
theobject=which2;
highlighting=setInterval("highlightit(theobject)",50);
}
function low(which2){
clearInterval(highlighting);
if (which2.getStyle('opacity'))
which2.setStyle({opacity: 0.5});
else if (which2.filters)
which2.filters.alpha.opacity=50;
}

function highlightit(cur2){
if (cur2.getStyle('opacity')<1)
cur2.setStyle({opacity: parseFloat(cur2.getStyle('opacity')+0.1)});
else if (cur2.filters&&cur2.filters.alpha.opacity<100)
cur2.filters.alpha.opacity+=10;
else if (window.highlighting)
clearInterval(highlighting);
}

var toggleFooterMenu = function() {
	fm = $('footer_menu');
	var hidden = (fm.getStyle('display') != 'none'); 
    Effect.toggle(fm, 'blind', {duration: 1 });
    link = $('toggle_footer');
    if (hidden) { link.innerHTML = 'show menu'; } else { link.innerHTML = 'hide menu'; }
    var params = 'sid=' + window._sessionid + '&uid=' + window._userid + '&a=toggle_footer_menu&hidden=' + hidden;
	new Ajax.Request('/callback/', {parameters:params, onFailure:errFunc});
};

var equaliseColumnHeights = function() {
	new PeriodicalExecuter(function(pe) {
		pe.stop();
		c1 = $('widgets_c1'); c2 = $('widgets_c2'); c3 = $('widgets_c3');
		c1.style.height = ''; c2.style.height = ''; c3.style.height = '';
		h1 = c1.offsetHeight; h2 = c2.offsetHeight; h3 = c3.offsetHeight;
		max = Math.max(h1,Math.max(h2,h3));
		if (h1 < max) { 
			c1.style.height = max + 'px';
		}
		if (h2 < max) { 
			c2.style.height = max + 'px';
		}
		if (h3 < max) { 
			c3.style.height = max + 'px';
		}
	}, 0.8);
}
