function _windowCenter( width, height )
{
	var left = parseInt((screen.availWidth/2) - (width/2));
	var top = parseInt((screen.availHeight/2) - (height/2));
	return ",left=" + left + ",top=" + top + "screenX=" + left + ",screenY=" + top;
}

function _windowBrowser( url, title, width, height )
{
	url = url || "";
	title = title || "";
	width = width || screen.availWidth;
	height = height || screen.availHeight;
	window.open( url, null, 'width='+width+',height='+height+',scrollbars=yes'+_windowCenter( width, height ) );//, 'width='+width+',height='+height+',scrollbars=1'+_windowCenter( width, height ));
}

function printFlyer( url, title )
{
	_windowBrowser( url, null, 750, screen.availHeight );
}

function showLoader( node )
{
	node.html('<div style="display: block;" id="loading"><img align="left" alt="Loading..." src="/images/loader.gif"><b>Loading...</b></div>');
}

function showSmallLoader( node )
{
	node.html('<img align="left" alt="Loading..." src="/images/loader2.gif">');
}

function showTextLoader( node )
{
	node.html('Loading...');
}

function _modalbox( page_url, title, width)
{
	width = ( width || 450 );
	//Modalbox.show(url, {title:title});
	showLoader($("#dialog"));
	$("#dialog").dialog("destroy");
	$("#dialog").dialog({
		autoOpen: true,
		width: width,
		title: title,
		modal: true,
		open: function(event, ui){
			$.ajax({
				url: page_url,
				type: "GET",
				dataType: "html",
				success: function( data ){$('#dialog').html(data);}
			});
		}
	});
	return false;
}

var featuredOffset = 0;

function loadFeatured( back )
{
	back = back || 0;
	return;
	if ( back == 0 )
	{
		if ( ( featuredOffsetMax - 5 ) < featuredOffset )
			return;
		featuredOffset = featuredOffset + 1;
	}
	else if ( featuredOffset > 0 )
		featuredOffset = featuredOffset - 1;
	else
		return;
	//$( "#properties-area .property" ).effect( "drop", {}, 500);
	$.ajax({
		url: "/featured/"+featuredOffset,
		dataType: "html",
		success: function( data ){
			$( "#properties-area" ).html(data);
			//$( "#properties-area .property" ).removeAttr( "style" ).hide().fadeIn();
			//$(this).addClass("done");
		}
	});
		//$("#properties-area .property").load("/featured/"+featuredStep);
		//removeAttr( "style" ).hide().fadeIn();
}

function __modalbox( page_url, title, width, height)
{
	width = ( width || 450 );
	height = ( height || 350 );
	showLoader($("#dialog"));
	$("#dialog").dialog("destroy");
	$("#dialog").dialog({
		autoOpen: true,
		width: width,
		height: (height+40),
		title: title,
		modal: true,
		open: function(event, ui){
			$.ajax({
				url: page_url,
				type: "GET",
				dataType: "html",
				async: false,
				success: function(data){
					$("#dialog").html(data);
				}
			});
//			$('#dialog').html('<iframe src="'+page_url+'" width="100%" height="'+height+'" frameborder="0"></iframe>');
		}
	});
	return false;
}

function openDialog( data, title, width, height )
{
	width = ( width || 450 );
	height = ( height || 100 );
	$('#dialog').html(data);
	$("#dialog").dialog("destroy");
	$("#dialog").dialog({
		autoOpen: true,
		width: width,
		height: height,
		title: title,
		modal: true
	});
}

function closeDialog()
{
	$('#dialog').html("");
	$("#dialog").dialog("destroy");
}

function socialFb( title )
{
	_windowBrowser( "http://www.facebook.com/share.php?u="+$.URLEncode(location.href), title, 500, 400 );
	//_windowBrowser( 'http://www.facebook.com/share.php?u='+$.URLEncode(location.href), title, 500, 400 );
}

function socialTwitter( title )
{
	_windowBrowser( 'http://twitter.com/share?url='+$.URLEncode(location.href)+'&text='+$.URLEncode(title), title, 500, 400 );
}

function socialDigg( title )
{
	_windowBrowser( 'http://digg.com/submit?phase=2&url='+$.URLEncode(location.href)+'&title='+$.URLEncode(title), "Digg", 500, 400 );
}

function socialYoutube( title )
{
	_windowBrowser( 'http://youtube.com', "YouTube", 500, 400 );
}

function _hideLoader( id )
{
	$("#"+id).hide( "blind", {}, 500 );
	setTimeout(function() {
		$("#"+id).show( "blind", {}, 500 );
	}, 500 );
}

function signInDialog()
{
	_modalbox('/login', 'Sign In',340,300);
}

function forgottenPasswordDialog()
{
	_modalbox('/forgotten_password', 'Forgotten Password',340,300);
}

function registrationDialog()
{
	_modalbox('/register', 'Create an Account',620,246);
}

