var active_att = new Array();

// affiche une autre page attachment
function display_att(id,page,maxatt)
{
	for(var i=0; i<maxatt; i++)
		document.getElementById('att_'+id+'_'+i).style.display = 'none';
	for(var i=page*4; i<(page+1)*4; i++) 
		document.getElementById('att_'+id+'_'+i).style.display = 'block';
	return false;
}

// affiche l'image/son/video en grand a coté de l'article
function select_att(id,htm,i, aParams, aValues)
{
	try
	{
		if (htm.substring(0,13) != 'http%3A%2F%2F') {
			// contenu image
			document.getElementById("image-"+id).innerHTML = unescape(htm);
		} else if (htm.indexOf('.mp3')>0) {
			// contenu son
			var fo = new FlashObject("/wp-content/themes/dewplayer.swf", "player", "200", "20", "7", "#ffffff");
			fo.addVariable('son', htm);
			//fo.addVariable('image', 'http://blogs.infobebes.com/wp-content/themes/v1/../mp3_onde.jpg');
			fo.write("image-"+id);
		} else {
			// contenu video
			var fo = new FlashObject(unescape(htm), "videoflash", "350", "310", "7", "#000000");
			var iCount = aParams.length;
			for(var i= 0; i < iCount; i++) {
				if (aValues[i]) {
					
					fo.addVariable(aParams[i], aValues[i]);
				}
			}
			
			fo.write("image-"+id);
		}
	} catch(e)
	{ 
	}
	active_att[id] = i;
	return false;
}

// affiche l'attachment précedent
function prec_att(id)
{
	try
	{
		var index = Number(active_att[id]);
		index = index - 1;
		if (index<0)
			index = active_att[id+"_max"];
		active_att[id] = index;
		document.getElementById("att_" + id + "_" + index).onclick();
	}
	catch(e)
	{
	}
	return false;
}

// affiche l'attachment suivant
function next_att(id)
{
	try {
		var index = Number(active_att[id]);
		index = index + 1;
		if (index > active_att[id+"_max"])
			index = 0;
		active_att[id] = index;
		document.getElementById("att_" + id + "_" + index).onclick();
	}
	catch(e)
	{
	}
	return false;
}

function test_select(aInfos, sId) {

	var oDiv    = $(sId);
	var sType   = '';
	var sUrl    = '';
	var sIcon   = '';
	var aParams = new Array();
	var aValues = new Array();
	
	aInfos.each(function(pair) {
		  if (pair.key == 'type')   sType   = pair.value;
		  if (pair.key == 'url')    sUrl    = pair.value;
		  if (pair.key == 'icon')   sIcon   = pair.value;
		  if (pair.key == 'params') aParams = pair.value;
		  if (pair.key == 'values') aValues = pair.value;
	});

	if (sType == 'image') {
		oDiv.innerHTML = '<a href="' + sUrl + '" rel="lightbox" style="display:block;"><span style="position:absolute; top:0; left:0; width:20px; height:19px;cursor:pointer;"><img src="/wp-content/themes/images/loupe.jpg" width="20" height="19" alt="zoom" title="zoom" /></span><img src="' + sUrl + '" alt="" /></a>';
	} else if (sType == 'video') {
		var fo = new FlashObject(sUrl, "videoflash", "350", "310", "7", "#000000");
		fo.addParam("wmode", "transparent");
		var iCount = aParams.length;
		for(var i= 0; i < iCount; i++) {
			if (aValues[i]) {
				
				fo.addVariable(aParams[i], aValues[i]);
			}
		}
		fo.write(sId);
	} else if (sType == 'son') {
	
		var fo = new FlashObject("/wp-content/themes/dewplayer.swf", "player", "200", "20", "7", "#ffffff");
		fo.addVariable('son', sUrl);
		fo.addParam("wmode", "transparent");
		//fo.addVariable('image', 'http://blogs.infobebes.com/wp-content/themes/v1/../mp3_onde.jpg');
		fo.write(sId);
	}
}
