jQuery(document).ready(function(){

	var modal = jQuery('#prompt');

	modal.css({ width: 'auto', height: 'auto' });

	modalapi = modal.overlay({
				expose: {
					color: '#333',
					loadSpeed: 200,
					opacity: 0.9
				},
				closeOnClick: true,
  				api: true,
  				onClose: function(test) {
					modal.attr('class', 'modal');
				}
	});



	function loadLocalMedia(media) {

		var item_id = media.attr('item_id');
		var type = media.attr('type');
		var url;

		switch (type) {
			case 'photo':
			case 'album':
				url = '/ajax/' + type + 'embed/id/' + item_id + '/';
			break;
			default: url = '/ajax/' + type + 'embed/width/480/height/315/vid/' + item_id + '/'; break;
		}

		modal.addClass(type + '-wall');
		modal.load(url, function() {

			switch (type) {
				case 'album':
					modal.find('#album').css({ height: '470px', width: '950px' });
				break;
				case 'photo':
					modal.find('img').wrap('<a href="' + media.attr('href') + '"></a>');
				break;
			}

			modal.find('.close').click(function() { modal.html(''); modalapi.close(); });
			modalapi.load();
		});
	}

	jQuery('.media a').bind('click', function(e) {
		e.preventDefault();
		loadLocalMedia(jQuery(this));
	});
});