/**
 * @author bmidget
 */
 
$(document).ready(function(){
	$('.m_buttons').hover(
		function(){
			$(this).attr('src','/images/members/'+$(this).attr('id')+'_tab_sel.jpg');
		},function(){
			$(this).attr('src','/images/members/'+$(this).attr('id')+'_tab.jpg');
		}
	);
	
	$('.pref').click(function(){
		var variable = $(this).children('.hidden').children('.var').text();
		var val = $(this).children('.hidden').children('.val').text();
		var method = $(this).children('.hidden').children('.method').text();
		if ( ! method)
			method = 'set';
			
		var callback = $(this).children('.hidden').children('.callback').text();		
		var url = '/members/preferences/'+method+'/'+variable;
		var data = {value: val};

 		$.post(url, data, eval(callback));
	})
	
	// report a bug
	$('#report_bug_dialog').dialog({
		modal: true,
		title: 'Report a bug',
		resizable: false,
		height: 'auto',
		autoOpen: false,
		width: 400,
		overlay: {
			opacity: .5,
			background: 'black'
		},
		buttons: {
			'Cancel': function(){
				$(this).dialog('close');
			},
			'Send Request': function(){
				$('#report_bug_form').hide();
				$('#report_bug_txt').show();
				$('#report_bug_form').submit();
			}
		}
	});
	
	var options = {
		success: function(response){
			if (response == 'There was an error sending your request')
			{
				$('#report_bug_txt').text(response);
				return;
			}	
			
			$('#report_bug_dialog').dialog('close');
			$('#report_bug_details').val('');
			$('#report_bug_consistent').val('');
			status(response);
		}
	};
	$('#report_bug_form').ajaxForm(options);
	
	$('#report_bug_link').click(function(){
		$("#browser_info").val(navigator.userAgent)
		$('#report_bug_form').show();
		$('#report_bug_txt').hide();
		$('#report_bug_dialog').dialog('open');
	}) // end report a bug
	
	// request a feature
	$('#request_feature_dialog').dialog({
		modal: true,
		title: 'Request a feature',
		resizable: false,
		height: 'auto',
		autoOpen: false,
		width: 400,
		overlay: {
			opacity: .5,
			background: 'black'
		},
		buttons: {
			'Cancel': function(){
				$(this).dialog('close');
			},
			'Send Report': function(){
				$('#request_feature_txt').show();
				$('#request_feature_form').hide();
				$('#request_feature_form').submit();
			}
		}
	});
	
	var options = {
		success: function(response){
			if (response == 'There was an error sending your request')
			{
				$('#request_feature_txt').text(response);
				return;
			}	
			
			$('#request_feature_dialog').dialog('close');
			$('#request_feature_details').val('');
			status(response);
		}
	};
	$('#request_feature_form').ajaxForm(options);
	
	$('#request_feature_link').click(function(){
		$('#request_feature_form').show();
		$('#request_feature_txt').hide();
		$('#request_feature_dialog').dialog('open');
	}) // end request a feature
	
});