// set browser styles - Thanks to Rafael Lima (http://rafael.adm.br)
// function css_browser_selector(u){var ua = u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1;},g='gecko',w='webkit',s='safari',h=document.getElementsByTagName('html')[0],b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3')?g+' ff3':is('gecko/')?g:/opera(\s|\/)(\d+)/.test(ua)?'opera opera'+RegExp.$2:is('konqueror')?'konqueror':is('chrome')?w+' '+s+' chrome':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?'mobile':is('iphone')?'iphone':is('ipod')?'ipod':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win':is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c;};

// css_browser_selector(navigator.userAgent);


// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
function OpenClose(theID)
{
	var objDiv = document.getElementById(theID) ;
	var objDisplay = objDiv.style.display ;
	if (objDisplay == 'none')
		Effect.BlindDown(theID, { duration: 0.4 });
	else Effect.BlindUp(theID);       
}
function hideDropped(element)
{
//	element.innerHTML = ''
	var i;
	while (element.childNodes[i])
	{
		if (element.childNodes[i].nodeType == 1) element.childNodes[i].style.display = "hidden";
		i++
	}
}
function OpenCloseFade(theID)
{
	var objDiv = document.getElementById(theID) ;
	document.body.appendChild(objDiv)
	var objDisplay = objDiv.style.display ;
	objDiv.style.height = getPageSize()[1]+'px';
	if (objDisplay == 'none')
		Effect.Appear(theID, { duration: 0.4 });
	else Effect.Fade(theID);       
}

function post_close()
{
	Effect.Fade("post_console");
	document.getElementById("post_post_id").value = null 
	document.getElementById("post_subject").value = "" 
	document.getElementById("post_content").value = "" 
	
}

function tag_content(tag, id)
{
	content_insert("<" + tag + ">", "</" + tag + ">", id);
}
function post_tag_content(tag)
{
	content_insert("<" + tag + ">", "</" + tag + ">", "post_content");
}
function post_content_insert(openTag, closeTag)
{
	content_insert(openTag, closeTag, "post_content")
}
function content_insert(openTag, closeTag, objID)
{
  // Add tags code to textarea
  var txtAr = document.getElementById(objID), oRange;
  txtAr.focus();

  if (document.selection && document.selection.createRange)
  {
    oRange = document.selection.createRange(); 
    
    // Create Range object form the selected Text
    if (oRange.parentElement()==txtAr)
    {
      // Check if the parent of the Range object is our textarea
      // add the tags before and after the selected text
      oRange.text = openTag+oRange.text+closeTag; 
    }
  }
 else if(txtAr.selectionStart || txtAr.selectionEnd)
  {
    // find the start position
    var selStart = txtAr.selectionStart;
    // find the end position
    var selEnd = txtAr.selectionEnd;

    // text before the selected text
    var sect1 = (txtAr.value).substring(0,selStart);
    // the selected text
    var sect2 = (txtAr.value).substring(selStart,selEnd);
    // text after the selected text
    var sect3 = (txtAr.value).substring(selEnd);
    // add the tags before and after the selected text
    txtAr.value = sect1 + openTag+sect2 + closeTag+sect3;
	txtAr.selectionEnd = selEnd + openTag.length + closeTag.length;
	txtAr.selectionStart = txtAr.selectionEnd;

    txtAr.focus();

  }
 else
  {
  	  txtAr.focus();
	  txtAr.value = txtAr.value + openTag + closeTag;
  }
}

Sound = {
  tracks: {},
  _enabled: true,
  template:
    new Template('<embed style="height:0" id="sound_#{track}_#{id}" src="#{url}" loop="false" autostart="true" hidden="true"/>'),
  enable: function(){
    Sound._enabled = true;
  },
  disable: function(){
    Sound._enabled = false;
  },
  play: function(url){
    if(!Sound._enabled) return;
    var options = Object.extend({
      track: 'global', url: url, replace: false
    }, arguments[1] || {});
 
    if(options.replace && this.tracks[options.track]) {
      $R(0, this.tracks[options.track].id).each(function(id){
        var sound = $('sound_'+options.track+'_'+id);
        sound.Stop && sound.Stop();
        sound.remove();
      });
      this.tracks[options.track] = null;
    }
 
    if(!this.tracks[options.track])
      this.tracks[options.track] = { id: 0 };
    else
      this.tracks[options.track].id++;
 
    options.id = this.tracks[options.track].id;
    $$('body')[0].insert(
      Prototype.Browser.IE ? new Element('bgsound',{
        id: 'sound_'+options.track+'_'+options.id,
        src: options.url, loop: 1, autostart: true
      }) : Sound.template.evaluate(options));
  }
};
 
if(Prototype.Browser.Gecko && navigator.userAgent.indexOf("Win") > 0){
  if(navigator.plugins && $A(navigator.plugins).detect(function(p){ return p.name.indexOf('QuickTime') != -1 }))
    Sound.template = new Template('<object id="sound_#{track}_#{id}" width="0" height="0" type="audio/mpeg" data="#{url}"/>');
  else if(navigator.plugins && $A(navigator.plugins).detect(function(p){ return p.name.indexOf('Windows Media') != -1 }))
    Sound.template = new Template('<object id="sound_#{track}_#{id}" type="application/x-mplayer2" data="#{url}"></object>');
  else if(navigator.plugins && $A(navigator.plugins).detect(function(p){ return p.name.indexOf('RealPlayer') != -1 }))
    Sound.template = new Template('<embed type="audio/x-pn-realaudio-plugin" style="height:0" id="sound_#{track}_#{id}" src="#{url}" loop="false" autostart="true" hidden="true"/>');
  else
    Sound.play = function(){};
} 
