var thingalyzer_wait = (function() {
	var dialog_div = $("<div />").css('display','none');
	var set_content = function(content) { 
		dialog_div.html(content);
	}
	var set_title = function(txt) {
		dialog_div.dialog('option','title',txt);
	}
	var close_dialog = function() {
		dialog_div.dialog('close');
	}
	var browser_stop = function() {
		try {
			document.execCommand('Stop');
		} catch (e) {
		}
		window.stop() ;
	}
	dialog_div.dialog({
		autoOpen: false,
		bgiframe: true,
		modal: true,
		resizable: false,
		draggable: false,
		buttons: {
			"Cancel": (function() {
				close_dialog();
				browser_stop();
			})
		},
		close: browser_stop
	});
	set_title("Please wait...");
	dialog_div.html('The Thingalyzer is thingalyzing your things!<br />This may take a little while...');
	
	return {
		setContent: set_content,
		setTitle: set_title,
		getContent: function() { return text_content; },
		show: function() { dialog_div.dialog('open'); },
		cancel: close_dialog,
		dialogDiv: dialog_div
	};
});
var thingalyzer_tryit = (function (example_inputs,delay) {
	var curr_ex_input = 0;
	var ps = $('div.box_examples:first p');
	var box = $('div.box_examples:first');
	var try_it = $('div.try_it img');
	var box2 = $("div.box2:first");
	var timer;
	var startTimer,stopTimer;
	var copy_items = function(){
		var i;
		for (i=0; i<example_inputs[curr_ex_input].length; i++) {
			$("p.thingalyzer_text input")[i].value = example_inputs[curr_ex_input][i];
		}
	};
	var switch_examples = function () {
		curr_ex_input+=1;
		if (curr_ex_input >= example_inputs.length) {
			curr_ex_input = 0;
		}
		box.fadeOut("fast",function(){
			ps.each(function(i){
				this.innerHTML = example_inputs[curr_ex_input][i];
			});
		});
		box.fadeIn();
		startTimer();
	}
	startTimer = function() {
		timer && clearTimeout(timer);
		timer = setTimeout(switch_examples,delay*1000);
	};
	stopTimer = function() {
		timer && clearTimeout(timer);
	};
	
	box2.css("height",$("div.box_box2:first").css('height'));
	ps.click(copy_items);
	ps.mouseover(stopTimer);
	ps.mouseout(startTimer);
	try_it.click(copy_items)
	try_it.mouseover(stopTimer);
	try_it.mouseout(startTimer);
	ps.each(function(i){
		this.innerHTML = example_inputs[curr_ex_input][i];
	});
	startTimer();
});
