DWREngine.setErrorHandler(function(message){
					if (message.indexOf('0x80040111') == -1) {
					  	InlinePopup.popupDialog('Error:'+message,{
					  			width:350,
								popupClass:'s-tabcolor-error', 
								okButtonClass:'s-button',
								okButton: 'Ok',
								type: 'error'
					  	});
				  	}
});


var sel;
function getSel()
{
	var txt = '';
	var foundIn = '';
	if (window.getSelection)
	{
		txt = window.getSelection();
	}
	else if (document.getSelection)
	{
		txt = document.getSelection();
	}
	else if (document.selection)
	{
		txt = document.selection.createRange().text;
	}
	else return;
	return txt+'';
}

function updateSelection() {
	sel = getSel();
}

function doRelatedSearch() {
	if (!sel || sel == '') {
		alert('Please select some text in this page,and click me to try again^_^');
		return;
	}else{
		var url = 'http://search.jongo.com/searchKnows.php?keyword='+encodeURIComponent(sel);
		window.location.href = url;
	}
}

Event.observe(document,'mouseup',updateSelection.bindAsEventListener(), false);


var HelpTopic = {
	'LAZYSEARCH'	: 'Lazy Search is a handy search tool. ' +
				 	  'After you have selected an article to read, you can highlight any word(s)' +
				 	  ' on that page then click \"Lazy Search\" button located at the bottom of the article.' +
				 	  ' You will get the search results immediately without having to type in any words.',
	'TAGS'			: 'Tags can both help you find articles in the Jongo Knows as well as provide an easy' +
					  ' way for you to \'remember\' and classify articles for later recall.',
	'HIREWARDS'		: 'The higher you set the reward points for your question,' +
					  ' the more likely other members will reply to your question quickly.',
	'PERSONALIZE'	: 'Personalized Layout is a feature of Jongo Knows that enables you to get articles tailored specifically to your interests.',
	'LATEST'		: 'Last updated in {0}'
};
function popupHelp(sender, topic, options) {
	sender = $(sender);
	options = options || {};
	
	var container = Builder.node('div', {style:'display:none;z-index:999;width:300px',className:'popupwarn'});
	var msg = HelpTopic[topic];
	if (options.args) {
		for (var i = 0; i < options.args.length; i++) {
			msg = msg.replace('{'+i+'}',options.args[i]);
		}
	}
	container.innerHTML = msg;
	if (options.helpid) 
		container.innerHTML += '<a href="http://help.jongo.com/?channel=faq&action=viewByID&id='+ options.helpid +'" target="_blank">Learn more...</a>';
	document.body.appendChild(container);
  				
			 	if (Effect.Dropshadow) {
		    		if (!container._shadow) {
						container= Effect.Dropshadow(container);
						Element.hide(container);
						Element.show(container._original);
						container.style.zIndex = 1000;
					}else{
						container = container._shadow;
					}		
				}
				
				var pos = Position.positionedOffset(sender);
				var eh = Element.getDimensions( sender ).height;
				var ew = Element.getDimensions( sender ).width;	
			  	var focus  = function() {
			  		this.hasFocus = true;
			  	};
			  	
			  	var blur = function() {
			 		this.hasFocus = false;  	
			  	};						
				var hide = function() {
					if (this.hasFocus) 
			  			return;
					Event.stopObserving(document, 'click', 
		  						this.__hideEventListener,
		  						false);
		  			var o = this;
					Effect.Fade(this, {duration:0.15,afterFinish:function() {
						document.body.removeChild(o);
					}});
				}
				
				container.__hideEventListener = hide.bindAsEventListener(container);
				Event.observe(container,'mouseover',focus.bindAsEventListener(container),false);
				Event.observe(container,'mouseout',blur.bindAsEventListener(container),false);
				
				setTimeout(function() {
					Event.observe(document,'click',container.__hideEventListener,false);
				},150);
				

			    if(!container.style.position || container.style.position=='absolute') {
			      container.style.position = 'absolute';
			    }					
					    
				container.style.left = (pos[0] - Element.getDimensions( container ).width + ew + 5)+'px';
  				container.style.top = (pos[1]+eh + 5)+'px';
  				
				Effect.Appear(container,{duration:0.15});
}

var QuoteShow = Class.create();
QuoteShow.prototype = {
    initialize: function(element, options) {
      this.element = $(element);
      this.options = Object.extend({className: 'quote', duration: 15}, options);
      this.quotes = document.getElementsByClassName(this.options.className, this.element);

      this.prepareQuotes();
      this.registerCallback();
    },

    prepareQuotes: function() {
      this.currentQuote = this.quotes.first();
      this.element.style.position = 'relative';
      this.element.style.height = this.quotes.max(function(quote) {
        var visible = Element.visible(quote), height;
        Element.setStyle(quote, {position: 'absolute', left: '0px'});
        if (!visible) Element.show(quote);
        height = Element.getHeight(quote);
        if (!visible) Element.hide(quote);
        return height;
      }).toString() + 'px';
    },

    nextQuote: function() {
      return this.quotes[(this.quotes.indexOf(this.currentQuote) + 1) % this.quotes.length];
    },

    registerCallback: function() {
      window.setTimeout(this.tick.bind(this), this.options.duration * 1000);
    },

    tick: function() {
      var currentQuote = this.currentQuote, nextQuote = this.nextQuote();

      new Effect.Parallel([
        new Effect.Fade(currentQuote, {sync: true}),
        new Effect.Appear(nextQuote, {sync: true})
      ], {
        duration: 2,
        afterFinish: (function(effect) {
          this.currentQuote = nextQuote;
          this.registerCallback();
        }).bind(this)
      })
    }
}