jQuery(function() {
	$('input[type=checkbox].custom').checkbox({
	    cls : 'jquery-safari-checkbox',
	    empty : '/images/empty.gif'
	});
	
	$('.ir-abuse-close').live('click', function(e){
		
		e.preventDefault();
		
		$('#abuse-overlay').remove();
		$('#ir-abuse-form-block').remove();
		
		$('#ir-abuse-message')
			.removeClass('error')
			.removeClass('success');
		return false;
	});
	
	$('#ir-abuse-message').live('click', function(){		
		$(this)
			.stop(true)
			.hide();
	})
	
	
	
	$('#ir-abuse').click(function(){
		
		if( $('#ir-abuse-form-block').is(':visible') )
		{			
			$('.ir-abuse-close').click();
		}
		
		$.ajax({
			url:'/fb',
			dataType:'html',
			data:{
				is_ajax:'true'
			},
			success:function(html){
				
				var iWidth = $(document).width();
				var overlay= $('<div>')
					.attr('id', 'abuse-overlay')
					.animate({
						'opacity' : '.8'
					}, 1000)
					.css({
						'width' : iWidth,
						'height' : $(document).height()
					});
				
				$('body')
					.append(overlay)
					.append(html);
				
				$('#ir-abuse-form-block')
					.css({
						'left': iWidth/2 - 265,
						'top' : $(document).scrollTop() + 40,				
						'z-index':5
					})
					.show();
				
				$('#ir-abuse-form').ajaxForm({
					dataType:'json',
					beforeSubmit:function(){
						$('.form_block', '#ir-abuse-form-block').append('<div id="tree-loader" />')
					},
					success:function(json){
						$('#tree-loader').remove();
						if( json.status == 'error' )
						{
							$('#ir-abuse-message')
								.addClass('error')
								.stop(true)
								.text(json.error_msg)
								.fadeIn()
								.delay(6000)
								.fadeOut();
						}
						
						if( json.status == 'success' )
						{
							$('#ir-abuse-message')
								.addClass('success')
								.stop(true)
								.text(json.error_msg)
								.fadeIn()
								.delay(2000)
								.fadeOut(function(){
									$('.ir-abuse-close').click();
								});
							
							
							$('#ir-abuse-form').resetForm();
						}
					}
				});
			}
		});
		
		
//	

//		

		
		return false;
	});
});

function submit_form(form_id) {
	$('#' + form_id).submit();
	return false;
}

function toggle_show(id) {
	$('#' + id).toggle('fast');
	return false;
}

	function rand(){
		return mt_rand();
	}


	function mt_rand(min, max) {
		var argc = arguments.length;
		if ( argc === 0 )
		{
			min = 0;
			max = 2147483647;
		}
		else if ( argc === 1 )
		{
			throw new Error('Warning: mt_rand() expects exactly 2 parameters, 1 given');
		}
		return Math.floor(Math.random() * (max - min + 1)) + min;
	}

function select_all(status, form_id) {
	$("input[type='checkbox']", '#' + form_id).attr('checked', status);
	return false;
}

	function log() {
		window.console && console.log && console.log(Array.prototype.slice.call(arguments));
	};

//function log(item, context) {
//	if ( typeof (context) == 'undefined' )
//	{
//		window.console && console.log && console.log(item);
//	}
//	else
//	{
//		window.console && console.log && console.log(context, item);
//	}
//}

function wordwrap(str, int_width, str_break, cut) {
	var m = ((arguments.length >= 2) ? arguments[1] : 75);
	var b = ((arguments.length >= 3) ? arguments[2] : "\n");
	var c = ((arguments.length >= 4) ? arguments[3] : false);
	var i, j, l, s, r;

	str += '';

	if ( m < 1 )
	{
		return str;
	}

	for ( i = -1, l = (r = str.split(/\r\n|\n|\r/)).length; ++i < l; r[i] += s )
	{
		for ( s = r[i], r[i] = ""; s.length > m; r[i] += s.slice(0, j) + ((s = s.slice(j)).length ? b : "") )
		{
			j = c == 2 || (j = s.slice(0, m + 1).match(/\S*(\s)?$/))[1] ? m : j.input.length - j[0].length || c == 1 && m || j.input.length + (j = s
			        .slice(m).match(/^\S*/)).input.length;
		}
	}

	return r.join("\n");
}

