function populateSelect(selectobj,order){
//alert(order);
  if(order) {
	picsarray = picsarray.sort();
  } else {
	picsarray = picsarray.sort().reverse();
  }
  for (var i=0; i<picsarray.length; i++)
  	selectobj.options[selectobj.options.length]=new Option(picsarray[i], picsarray[i])
	if (selectobj.options.length>1){
	  selectobj.selectedIndex=0
	  //showpicture(document.getElementById("picsform").picslist)
 	}
}

function playaudio(selectobj){
//  var so = selectobj.options[selectobj.selectedIndex].value;
  var so = selectobj;
  //alert(so);
  var url = path + so;
  //alert(url);
  if(so.match('.mp3')) {
	//alert(so.match('.mp3'));
	embedFlash(url,true,null,null,'audioarea');
  } else if(so.match('.flv')) {
	//alert(so.match('.flv'));
	embedFlash('dummy.mp3',true,null,null,'audioarea');
	document.getElementById('picturearea').innerHTML='<div style="margin-top: 135px;"><div id="fldiv"></div></div>';
	embedFlash(url,true,620,460,'fldiv');
  } else if(so.match('.rm')) {
	embedRm(url,true,null,null,'audioarea');
	//alert(this.value.match('.rm'));
  } else {
  	alert('Unknown audioformat');
  }
  /*
  piccontainerobj=document.getElementById("audioarea")
  resetfade(10)
  piccontainerobj.innerHTML='<img src="'+locationstring+so+'">'
  fadepictoview=setInterval("gradualfade(piccontainerobj)",50)
  */
}

function showpicture(selectobj){
piccontainerobj=document.getElementById("picturearea")
resetfade(10)
piccontainerobj.innerHTML='<img src="'+locationstring+selectobj.options[selectobj.selectedIndex].value+'">'
fadepictoview=setInterval("gradualfade(piccontainerobj)",50)
}

function resetfade(degree){
if (window.fadepictoview)
clearInterval(fadepictoview)
if (typeof piccontainerobj.style.MozOpacity=="string")
piccontainerobj.style.MozOpacity=degree/100
else if (piccontainerobj.filters)
piccontainerobj.filters.alpha.opacity=degree
}

function gradualfade(){
if (typeof piccontainerobj.style.MozOpacity=="string" && piccontainerobj.style.MozOpacity<1)
piccontainerobj.style.MozOpacity=Math.min(parseFloat(piccontainerobj.style.MozOpacity)+0.2, 0.99)
else if (piccontainerobj.filters && piccontainerobj.filters.alpha.opacity<100)
piccontainerobj.filters.alpha.opacity+=20
else //if not IE or Moz
clearInterval(fadepictoview)
}

//-----------------------------
//Embed media functions
//-----------------------------

function embedFlash(urltoplay,autoplay,w,h,divid,playinwindow) {
   pw = 250; ph = 20; 
   if(w)pw = w;
   if(h)ph = h;
   var style = ' style="width: ' + pw + 'px; height: ' + ph + 'px;"'; 
   var pwindow = window;
   if(playinwindow)pwindow = playinwindow;

   var button = 'http://thurayya.info/01_LIB/mediaplayer_4.3.swf';

   var url = 'dummy.mp3';
   if(urltoplay)url = urltoplay;
   pauto = 'false';
   if(autoplay) {
	pauto = 'true';
	url += '&autostart=true'; 
   }
   var str = '';
   str += '<object '; 
   str += ' type="application/x-shockwave-flash" '; 
   str += style + ' data="' + button + '" '; 
   str += '<param name="allowScriptAccess" value="always">';
   str += '<param name="movie" value=" ' + button + '">';
   str += '<param name="quality" value="high">';
   str += '<param name="bgcolor" value="white">';
   str += '<param name="autostart" value="' + pauto + '">';
   str += '<param id="flashvars" name="FlashVars" value="file=' + url + '">';
   str += '</object>';
//   alert(str);
   pwindow.document.getElementById(divid).innerHTML = str; 
// alert(pwindow.document.getElementById(divid).innerHTML);
}

function embedRm(urltoplay,autoplay,w,h,divid,playinwindow) {
   pw = 174; ph = 40; 
   if(w)pw = w;
   if(h)ph = h;
   var style = 'width="' + pw + '" height="' + ph + '"'; 
   var pwindow = this;
   if(playinwindow)pwindow = playinwindow;
   var url = 'http://www.emanway.com/media/anasheed/laysa-alghreeb.rm';
   if(urltoplay)url = urltoplay;
   if(playinwindow)pwindow = playinwindow;
   var str = '';
   str += '<embed src="' + url + '" type="audio/x-pn-realaudio-plugin" console="' + url + '" controls="ControlPanel,StatusBar" autostart="' + autoplay + '" allowscriptaccess="always" nojava="true"' + style + '>';
// alert(str);
   pwindow.document.getElementById(divid).innerHTML = str;
}

function embedYoutube(urltoplay,autoplay,w,h,divid,playinwindow) {
   pw = 605; ph = 456; // textframe dimensions
   pw = 480; ph = 385; // youtube standard      
   pw = 500; ph = 400;      
   if(w)pw = w;
   if(h)ph = h;
   var style = 'width="' + pw + '" height="' + ph + '"'; 
   var pwindow = this;
   if(playinwindow)pwindow = playinwindow;
   var url = 'http://www.youtube.com/v/RRc3G06-Fs0&hl=en_US&fs=1&';
   if(urltoplay)url = urltoplay;
   pauto = 'false';
   if(autoplay) {
	pauto = 'true';
	url += '&autostart=true'; 
   }
   var str = '';
   str += '<object ' + style + '>';
   str += '<param name="movie" value="' + url + '"></param>';
   str += '<param name="allowFullScreen" value="true"></param>';
   str += '<param name="allowScriptAccess" value="always"></param>';
   str += '<embed src="' + url + '" type="application/x-shockwave-flash"';
   str += 'allowscriptaccess="always" allowfullscreen="true"' + style + '>';
   str += '</embed></object>';
//   alert(str);

   pwindow.document.getElementById(divid).innerHTML = str; 
// alert(pwindow.document.getElementById(divid).innerHTML);

}

function selectmedia(mvalue) {
  var filepath = 'http://thurayya.info/ShadhiliMasters//Multimedia/';
  var url = filepath + mvalue;
  //alert(url);
  if(mvalue.match('.mp3')) {
  //alert(mvalue.match('.mp3'));
    embedFlash(url,true,null,null,'player',parent);
  } else if(mvalue.match('.rm')) {
    embedRm(url,true,null,null,'player',parent);
  //alert(mvalue.match('.rm'));
  } else {
    alert('Unknown audioformat');
  }
}


