var notify_item;

$(function() {
	$('#result-popup').dialog({autoOpen:false, minWidth:200, buttons:{"Close":function(){$(this).dialog("close");}}});
	$('#notify-popup').dialog({autoOpen:false, minWidth:200, buttons:{"Ok":popup_ok,"Cancel":popup_cancel}});
	$('a.notify').click(function() { $('#notify-popup').dialog('open'); notify_item = $(this).attr('id').replace('notify-item-',''); });
	$('li.action-tab').click(show_cinqo);
	select_tab();
});

function select_tab() {
	try {
		var elem;
		var x = location.href.split('#');
		$('li.action-tab span').each(function(){if(x[1] == slugg($(this).html())) elem = $(this);});
		(elem || $('li.action-tab').eq(0)).click();
	} catch(e) {alert(e)}
}

function popup_ok() {
	$(this).dialog("close");
	var email = $('#email').val();
	var item = notify_item;
	$.post("/notify", { email: email, item: item }, notify_complete);
	$(anchor).hide();
}

function popup_cancel() {
	$(this).dialog("close");
}

function notify_complete(data){
	$('#result-popup').dialog('open');
}

function show_cinqo(){
	try{
		var tag = $(this).children().eq(0).html();
		var url = location.href.split('#')
		location.href = url[0] + '#' + slugg(tag);
	} catch(e) {}
	$(".opt-set").hide();
	$("#opt"+$(this).attr('id')).show();
	$('#biglist li').removeClass('selected');
	$(this).addClass('selected');
	var offset = $("#tab-widget").offset();
	$('#stage').height($(window).height() - 200);
}

function slugg(name){
	return name.replace(/ /g,'_').toLowerCase();
}
