function enhancetextarea(classname){
var alltextareas=document.getElementsByTagName("textarea")
for (var i=0; i<alltextareas.length; i++){
if (alltextareas[i].className=="codecontainer"){
var curtextarea=alltextareas[i]

//Top credit comment

if (i==0 && typeof alltextareas[0]!="undefined" && alltextareas[0].value.indexOf("Credits:")==-1) //Credit Notice
alltextareas[0].value='<style type="text/css">\n\n'+'/*Credits: Dynamic Drive CSS Library */\n/*URL: http://www.dynamicdrive.com/style/ */'+alltextareas[0].value.replace('<style type="text/css">', '')

/*
//Bottom credit link
if (i==1 && typeof alltextareas[1]!="undefined" && alltextareas[1].value.indexOf("Credit:")==-1 && alltextareas[0].className=="codecontainer") //Credit Notice
alltextareas[1].value=alltextareas[1].value+'\n'+'<div style="margin-top: 1em; font-size: 90%">Credit: <a href="http://www.dynamicdrive.com/style/">Dynamic Drive CSS library</a></div>'
*/

var helperbar=document.createElement("div")
helperbar.innerHTML='<div class="selectcode"><a href="#selectcode" class="tabs">Select Code</a> <a href="#expandcode" class="tabs">Expand</a></div>'
var helperbarlinks=helperbar.getElementsByTagName("a")
if (curtextarea.offsetHeight>=curtextarea.scrollHeight){
helperbarlinks[1].style.display="none"
curtextarea.style.overflowY="hidden"
}

helperbarlinks[0].setAttribute("rel", i)

helperbarlinks[0].onclick=function(){
var targettextarea=document.getElementsByTagName("textarea")[parseInt(this.rel)]
targettextarea.select()
return false
}

helperbarlinks[1].setAttribute("rel", i)
helperbarlinks[1].setAttribute("rev", curtextarea.offsetHeight+" defaultHeight")

helperbarlinks[1].onclick=function(){
var targettextarea=document.getElementsByTagName("textarea")[parseInt(this.rel)]
if (this.getAttribute("rev").indexOf("defaultHeight")!=-1){// if textarea is default height
targettextarea.style.height=targettextarea.scrollHeight+"px"
this.innerHTML="Contract"
targettextarea.style.overflowY="hidden"
targettextarea.style.borderStyle="solid"
this.setAttribute("rev", this.getAttribute("rev").replace("defaultHeight", "scrollHeight"))
if (this.scrollIntoView)
this.scrollIntoView()
return false
}
else{
targettextarea.style.height=parseInt(this.getAttribute("rev"))+"px"
this.innerHTML="Expand"
targettextarea.style.overflowY="scroll"
targettextarea.style.borderStyle="dashed"
this.setAttribute("rev", this.getAttribute("rev").replace("scrollHeight", "defaultHeight"))
}
return false
}
curtextarea.style.marginTop=0
curtextarea.parentNode.insertBefore(helperbar, alltextareas[i])
}
}
}

window.onload=function(){
enhancetextarea()
}

function ddbookmarkit(id){
var codetitle=document.getElementById("csscodetitle").innerHTML+" (CSS code)"
if (id=="deli")
window.open('http://del.icio.us/post?&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(codetitle))
else if (id=="furl")
window.open('http://www.furl.net/storeIt.jsp?u='+encodeURIComponent(location.href)+'&t='+encodeURIComponent(codetitle))
else if (id=="digg")
window.open('http://www.digg.com/submit?phase=2&url='+encodeURIComponent(location.href))
return false
}

function html2entities(){
var re=/[(<>"'&]/g
for (i=0; i<arguments.length; i++)
arguments[i].value=arguments[i].value.replace(re, function(m){return replacechar(m)})
}

function replacechar(match){
if (match=="<")
return ""
else if (match==">")
return ""
}