/* PLEGAR / DESPLEGAR DIVS HACIA ABAJO */
var divDesplegar_heightini=5;
var divPlegar_heightend=0;

var divDesplegar_interval = 1;
var divPlegar_interval = 1;

var divDesplegar_heightmax;
var divDesplegar_height;
var divPlegar_heightmin=0;
var divPlegar_height;

var divAbierto=-1;
var divFotoAbierto=-1;
function divPlegarDesplegar(id, h) {
	/* Si no hay ningún div abierto, se abre el div id */
	/* Si hay un div abierto que no es id se cierra el abierto y se abre el id */
	if (divAbierto!=-1 && divAbierto!=id) {
		divPlegar(divAbierto);
	}
	if (id != divAbierto) {
		divDesplegarInitialize(h);
		divDesplegar(id);
		divAbierto=id;
	}
}
function divPlegarDesplegarFoto(id, h, categoria, src) {
	/* Si no hay ningún div abierto, se abre el div id */
	/* Si hay un div abierto que no es id se cierra el abierto y se abre el id */
	if (divFotoAbierto!=-1 && divFotoAbierto!=id) {
		divPlegar(divFotoAbierto);
	}
	if (id != divFotoAbierto) {
		divDesplegarInitialize(h);
		divDesplegar(id);
		divFotoAbierto=id;
	}
	if (document.getElementById(id+'_src')) {
		document.getElementById(id+'_src').src = '../gallery/'+src;
		//document.getElementById(id+'_src').src = '../gallery/'+id+'-'+categoria+'.jpg';
	}
}


function divDesplegarInitialize(hmax) {
	divDesplegar_height = divDesplegar_heightini;
	divDesplegar_heightmax = hmax;
}
function divDesplegar(id) {
	var obj = document.getElementById(id);
	obj.style.display = 'block';

	setTimeout("divDesplegar_control('"+id+"')",divDesplegar_interval);
}
function divDesplegar_control(id) {
	var obj = document.getElementById(id);
	divDesplegar_height = divDesplegar_height + 10;
	obj.style.height = divDesplegar_height+'px';

	if (divDesplegar_height < divDesplegar_heightmax) {
		setTimeout("divDesplegar_control('"+id+"')",divDesplegar_interval);
	}
	else {
		if (document.getElementById(id+'_video')) {
			var fileurl = document.getElementById(id+'_url').innerHTML;
			var regex = new RegExp('^(.*)/.*$');
			var result = regex.exec( String(window.location) );
			var url = result[1]+'/'+fileurl;
			
			flashembed(id+'_video',
				{
					src:'../img/flash/FlowPlayerDark.swf',
					width: 450,
					height: 320
				},
				{
					config: {
						videoFile: url,
						initialScale: 'orig',
						autoRewind: false,
						autoPlay: false
					}
				} 
			);
		}
		else if (document.getElementById(id+'_360')) {
			var html = '';
			html += '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" width="450" height="320">';
			html += '<param name="src" value="'+document.getElementById(id+'_url').innerHTML+'" />';
			html += '<param name="controller" value="true" />';
			/*
			 <!--
			 <object type="video/quicktime" data="archivo80.mov" width="450" height="320" class="mov">
			 <param name="controller" value="true" />
			 Error text.
			 </object>
			 -->
			*/
			html += '</object>';

			document.getElementById(id+'_360').innerHTML = html;
		}
		else if (document.getElementById(id+'_youtube')) {

			var _parent = document.getElementById(id+'_youtube');
			var youtubeapi = document.createElement('div');
			youtubeapi.id = id+'_youtube_api';
			_parent.appendChild( youtubeapi );

			var youtubeid = document.getElementById(id+'_url').innerHTML;
			var params = { allowScriptAccess: "always" };
			var atts = { id: 'youtubeapi' };

			swfobject.embedSWF("http://www.youtube.com/v/"+youtubeid+"&enablejsapi=1&playerapiid=ytplayer", id+'_youtube_api', "450", "320", "8", null, null, params, atts);

			/*
			html += '<object width="425" height="355">';
			html += '<param name="movie" value="'+url+'"></param>';
			html += '<param name="wmode" value="transparent"></param>';
			html += '<embed src="'+url+'" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed>';
			html += '</object>';

			document.getElementById(id+'_youtube').innerHTML = html;
			*/
		}

	}
}

function divPlegar(id) {
	var obj = document.getElementById(id);
	divPlegar_height = parseInt(obj.style.height);

	if (document.getElementById(id+'_video'))
		document.getElementById(id+'_video').innerHTML = '';
	else if (document.getElementById(id+'_360'))
		document.getElementById(id+'_360').innerHTML = '';
	else if (document.getElementById(id+'_youtube'))
		document.getElementById(id+'_youtube').innerHTML = '';


	setTimeout("divPlegar_control('"+id+"')",divPlegar_interval);
}
function divPlegar_control(id) {
	var obj = document.getElementById(id);
	divPlegar_height = divPlegar_height - 10;
	if (divPlegar_height<divPlegar_heightmin) divPlegar_height=divPlegar_heightmin;
	obj.style.height = divPlegar_height+'px';

	if (divPlegar_height > divPlegar_heightmin) {
		setTimeout("divPlegar_control('"+id+"')",divPlegar_interval);
	}
}


function ampliarfoto(id, h, categoria,src) {
	divPlegarDesplegarFoto(id,h,categoria,src);
	//document.getElementById(id).style.display = "block";
}
function ampliarvideo(id, h) {
	divPlegarDesplegarFoto(id,h);
	//document.getElementById(id).style.display = "block";
}
function cerrarfoto(id) {
	divPlegar(id);
	/*document.getElementById(id).style.display = "none";*/
}

