// live load dojo
//var scr=document.createElement('script'); scr.src="http://o.aolcdn.com/dojo/0.9.0/dojo/dojo.xd.js"; document.documentElement.appendChild(scr)

var loader=function() {
  dojo.query('.createdate').forEach(function(item){
    item.innerHTML=item.innerHTML.replace(/\b[a-z]/g,function(m0) {return m0.toUpperCase()})
  })

  // rss icons
  dojo.query('.buttonheading').forEach(function(item) {
      if(!dojo.query('a[title=PDF]',item).length) return 
      var tr=item.parentNode

      var rss=dojo.clone(item)
      tr.insertBefore(rss,item)
      dojo.query('img',rss)[0].src="images.php/icona_rss.gif"
      dojo.query('a',rss)[0].href='index.php?option=com_rd_rss&id=2'
      dojo.query('a',rss)[0].onclick=''
  })

  if (!location.href.match(/task=view/)) {
    dojo.query('.contentheading').forEach(function(item) {
      var tr=item.parentNode
    
      var tr1=dojo.doc.createElement('tr')
      var tds=dojo.query('td',tr)
      tds.shift()
      tds.forEach(function (item) {tr1.appendChild(item)})

      var tr2=dojo.doc.createElement('tr')
      var td2=dojo.doc.createElement('td')
      tr2.appendChild(td2)
      td2.style.height='8px'
      td2.style.background='url(images.php/sep_oriz.gif) no-repeat center'
      td2.colSpan=4
      
      tr.parentNode.appendChild(tr1)
      tr.parentNode.appendChild(tr2)
  
    })
  } else {
    var tbody=dojo.query('.createdate')[0].parentNode.parentNode
    dojo.query('tr:first-child',tbody).orphan()
    dojo.query('tr:first-child',tbody).orphan()
  }
  
  if (location.href.match(/task=view/) || !location.href.match(/com_content/))
    dojo.query('.contentheading').style('paddingBottom',"20px")

  dojo.query('.moduletable').forEach(function(item) {
    var tr=dojo.doc.createElement('tr')
    var td=dojo.doc.createElement('td')
    td.style.height='8px'
    td.style.background='url(images.php/bottom_dx.gif) no-repeat center top'
    tr.appendChild(td)
    dojo.query('tr',item)[0].parentNode.appendChild(tr)
  })
  
  dojo.query('.moduletable li').forEach(function(item) {
    var img=dojo.doc.createElement('img')
    item.style.display="block"
    item.style.listStyle="none"
    img.src="images.php/icona_freccia.gif"
    img.style.width="10px"
    img.style.height="10px"
    img.style.verticalAlign="middle"
    img.style.marginRight="4px"
    var data=dojo.query(item).query('*').orphan()
    dojo.query(item).adopt(img)
    dojo.query(item).adopt(data)
  })

  // ponygallery
  var table=dojo.query('table.newspane > tbody > tr:nth-child(2) table')[0]
  //var sec=dojo.query(dojo.query('tr.sectiontableentry')[0]).orphan()
  //dojo.query('.newspane').adopt(sec)
  if(table) {
    /*dojo.query(table).style('display','none')*/
    dojo.query('table.newspane > tbody > tr:last-child').style('display','none')
    dojo.query('table.newspane > tbody > tr:first-child').style('display','none')
    var tr=dojo.doc.createElement('tr')
    var td=dojo.doc.createElement('td')
    tr.appendChild(td)
    td.innerHTML="Fotogallery"
    td.className="componentheading";
    var tbody=dojo.query('table.newspane > tbody')[0]
    tbody.insertBefore(tr,tbody.firstChild)
  }
  //var x=dojo.query('table .newspane td:first-child table td:first-child')[0]
  //dojo.query(x).orphan()
}

if(window.addEventListener)
  window.addEventListener('load',loader,false);
else
  window.attachEvent('onload',loader);

