// Config
var customContainerConfig = {
	width:"700px",
	fixedcenter: 'contained',
	close:true,
	draggable:false,
	zindex:4,
	modal:true,
	visible:false
};

// States
var currentphoto=0;
var videoplayed=false;

// YUI
var mapContainer		= null;
var contactContainer	= null;
var photoContainer		= null;
var emailContainer		= null;
var embedContainer		= null;
var avtContainer		= null;
var chatContainer		= null;

var showVideo = function() {document.getElementById('apartment-video').style.visibility='visible';}
var hideVideo = function() {document.getElementById('apartment-video').style.visibility='hidden';}

// Starter
function initialize()
{
	mapContainer = new YAHOO.widget.Panel("map", customContainerConfig);
	mapContainer.render();
	mapContainer.showMaskEvent.subscribe(function() { YAHOO.util.Event.addListener(mapContainer.mask,'click',function() {mapContainer.hide();})});
	mapContainer.beforeShowEvent.subscribe(hideVideo)
	mapContainer.beforeHideEvent.subscribe(showVideo);

	contactContainer = new YAHOO.widget.Panel("contactus", customContainerConfig);
	contactContainer.render();
	contactContainer.showMaskEvent.subscribe(function() { YAHOO.util.Event.addListener(contactContainer.mask,'click',function() {contactContainer.hide();})});
	contactContainer.beforeShowEvent.subscribe(hideVideo);
	contactContainer.beforeHideEvent.subscribe(showVideo);

	photoContainer = new YAHOO.widget.Panel("viewphoto", customContainerConfig);
	photoContainer.render();
	photoContainer.showMaskEvent.subscribe(function() { YAHOO.util.Event.addListener(photoContainer.mask,'click',function() {photoContainer.hide();})});
	photoContainer.beforeShowEvent.subscribe(hideVideo);
	photoContainer.beforeHideEvent.subscribe(showVideo);

	emailContainer = new YAHOO.widget.Panel("emailfriend", customContainerConfig);
	emailContainer.render();
	emailContainer.showMaskEvent.subscribe(function() { YAHOO.util.Event.addListener(emailContainer.mask,'click',function() {emailContainer.hide();})});
	emailContainer.beforeShowEvent.subscribe(hideVideo);
	emailContainer.beforeHideEvent.subscribe(showVideo);

	embedContainer = new YAHOO.widget.Panel("embed", customContainerConfig);
	embedContainer.render();
	embedContainer.showMaskEvent.subscribe(function() { YAHOO.util.Event.addListener(embedContainer.mask,'click',function() {embedContainer.hide();})});
	embedContainer.beforeShowEvent.subscribe(hideVideo);
	embedContainer.beforeHideEvent.subscribe(showVideo);

	if(document.getElementById('contactavt'))
	{
		avtContainer = new YAHOO.widget.Panel("contactavt", customContainerConfig);
		avtContainer.render();
		avtContainer.showMaskEvent.subscribe(function() { YAHOO.util.Event.addListener(avtContainer.mask,'click',function() {avtContainer.hide();})});
		avtContainer.beforeShowEvent.subscribe(hideVideo);
		avtContainer.beforeHideEvent.subscribe(showVideo);
	}

    customContainerConfig.width = "550px";
	chatContainer = new YAHOO.widget.Panel("chat", customContainerConfig);
	chatContainer.render();
	//chatContainer.showMaskEvent.subscribe(function() { YAHOO.util.Event.addListener(chatContainer.mask,'click',function() {chatContainer.hide();})});
	chatContainer.beforeShowEvent.subscribe(hideVideo);
	chatContainer.beforeHideEvent.subscribe(showVideo);

    document.getElementById('map').style.display = 'block';
    document.getElementById('contactus').style.display = 'block';
    document.getElementById('viewphoto').style.display = 'block';
    document.getElementById('emailfriend').style.display = 'block';
    document.getElementById('embed').style.display = 'block';
    if(document.getElementById('contactavt'))
        document.getElementById('contactavt').style.display = 'block';
    document.getElementById('chat').style.display = 'block';
}

//function prepareChat(recipient)
//{
//    document.getElementById('guestchat').src = "/chat/index.php?r="+recipient;
//}

function showPhoto(photoid)
{
	document.getElementById('photoframe').src='/index.php?action=viewphoto&id='+photoid+'&pid='+listing;
	currentphoto=photoid;
	photoContainer.show();
	return false;
}

// Utilities
function bookmark()
{
	if (document.all)
		window.external.AddFavorite(location.href,document.title);
	else if(window.chromium)
		alert('Press Ctrl+D to bookmark this item.');
	else
		window.sidebar.addPanel(document.title,location.href,'');
}

function str2hex(input)
{
	result="";
	for(i=0;i<input.length;i++)
		result+=input.charCodeAt(i).toString(16);

	return result;
}
