function resize_viewport() {
	$.event.remove( this, "resize", DP_position);

	DP_position();

	// do what you need to do
	$.event.add( this, "resize", resize_viewport);
}


function sendLink(form) {
	$(".message").hide();
	$(".error").hide();
	if(form.valid() == true) {

		form.append('<input type="hidden" name="ajax" value="true" />');

		$.post(
			form.attr('action'),
			form.serialize(),
			function (data) {
				if(typeof(data.success) != 'undefined')
				{
					$('.message').html("<p>"+data.success+"</p>").fadeIn('fast');
					setTimeout('$(".message").fadeOut("fast")', 5000);
				}
				else
				{
					var x = "";
					$.each(data.errors, function(i, item) {
						x = x+ "<p>"+item['error']+"</p>";
					
					});
					$('.error').html(x).fadeIn('fast');
					setTimeout('$(".error").fadeOut("fast")', 5000);
					$('input#p1').val("");$('input#p2').val("");$('input#p3').val("");$('input#p5').val("");$('textarea#p5').val("");
				}
			},
			'json'
		)
	}
	return false;
}


function DP_show(url){
	var oh, st = 0;
	st = getScrollTop();
	$("body").append('<div id="DP_overlay"></div><div id="DP_show"><div id="DP_waiting"><img src="images/white_spinner.gif" alt=" " /></div><div id="DP_content" style="display: none;"></div></div>');
	oh = parseInt($(document).height());
	$("#DP_overlay").css("height", oh + st + "px");
	
	DP_position(false, oh);
	
	$("#DP_overlay").fadeIn(500, function(){
		$("#DP_show").fadeIn(500, function(){
			$("#DP_overlay").click(DP_remove);
			DP_dataload(url);
		});
	});
	
	// this is borrowed from thickbox
	document.onkeyup = function(e){   
		if (e == null) { // ie
			keycode = event.keyCode;
		} else { // mozilla
			keycode = e.which;
		}
		if(keycode == 27){ // close
			DP_remove();
		}  
	}
	
	//window.onresize = DP_position;
	resize_viewport();
	
	return false;
}


/*
function DP_show(url){
	var oh, st = 0;
	st = getScrollTop();
	$("body").append('<div id="DP_overlay"></div><div id="DP_show"><div id="DP_waiting"><img src="'+ waitImage.src +'" alt=" " /></div></div>');
	oh = parseInt($(document).height());
	$("#DP_overlay").css("height", oh + st + "px");
	
	DP_position(false, oh);
	
	$("#DP_overlay").fadeIn(500, function(){
		$("#DP_show").fadeIn(500, function(){
			$("#DP_overlay").click(DP_remove);
			DP_dataload(url);
		});
	});
	
	// this is borrowed from thickbox
	document.onkeyup = function(e){   
		if (e == null) { // ie
			keycode = event.keyCode;
		} else { // mozilla
			keycode = e.which;
		}
		if(keycode == 27){ // close
			DP_remove();
		}  
	}
	
	window.onresize = DP_position;
	
	return false;
}



function DP_dataload(url){
	var params = {};
	$.get(url, 
		  params, 
		  function(data){
			$("#DP_show").slideUp(300, function(){
						$('#DP_waiting').remove();
						$("#DP_show").append(data);
						if (typeof(gmap) == 'undefined') GMapLoad();
						imageScroller();
						$("#DP_show").slideDown(550);
					});
			});
}
*/

function DP_dataload(url){
	var params = {'ajax': true};
	$.post(url, 
	  params, 
	  function(data){
		$("#DP_show").slideUp(300, function(){
				$('#DP_waiting').remove();
				$("#DP_content").append(data).show();
				$("#DP_show").slideDown(550);
			});
		});
}




function DP_remove(){
	$("#DP_show").fadeOut("fast", function(){
		$(this).remove();
		$("#DP_overlay").fadeOut("fast", function(){
			$(this).remove();
		});
	});
	
	document.onkeyup = "";
	window.onresize = "";
}

function DP_position(animateMove, windowHeight){
	var anim = true;
	if(animateMove == false){
		anim = false;
	}
	var  window_height, window_width, show_width, st;
	if(window.innerWidth){
		window_width = window.innerWidth;
		window_height = window.innerHeight;
	}else if(document.body.offsetWidth){
		window_width = document.body.offsetWidth;
		window_height = document.body.offsetHeight;
	}
	st = getScrollTop();
	if(typeof (windowHeight) != 'undefined' && window_height > windowHeight){
		$("#DP_overlay").animate({height: st + window_height + 'px'}, 'normal');
	}
	show_width = $("#DP_show").width();
	if(anim == true){
		$("#DP_show").animate({marginLeft: parseInt(((window_width-show_width) / 2),10) + 'px', top: st + 50 + "px"}, 'normal');
	}else{
		$("#DP_show").css({marginLeft: parseInt(((window_width-show_width) / 2),10) + 'px', top: st + 50 + "px"});
	}
}

function getScrollTop(){
	var st=0;
	if (document.documentElement && document.documentElement.scrollTop){
	  st = document.documentElement.scrollTop;
	}else if (document.body && document.body.scrollTop){
	  st = document.body.scrollTop;
	}else if (window.pageYOffset) {
	  st = window.pageYOffset;
	}
	return st;
}

