var ardCommentObj = {
	init: function() {
	   this.createToggleLink();
	   this.createCharCounter();
	},
	createToggleLink: function() {
		 if(location.hash != '\#ardCommentMsg'
		 || document.getElementById('ardCommentSuccessMsg')) {
	      document.getElementById('ardAddComment').className = 'inv'; 
	   }
	   /* create link element */ 
	   var tmpObj = document.createElement('p');
	   tmpObj.setAttribute('id','ardCommmentToggleNav');
	   tmpObj.innerHTML = '<img alt="Link: " class="ardIcon" src="/sp/layout/img/general/ardpfeil.gif" />';	   
	   tmpObj.appendChild(document.createElement('a'));
	   tmpObj.getElementsByTagName('a')[0].innerHTML = document.getElementById('ardCommentHeader').innerHTML;
	   /* remove redundant description */
	   document.getElementById('ardAddComment').removeChild(document.getElementById('ardCommentHeader'));
	   /* set onclick */
	   tmpObj.getElementsByTagName('a')[0].onclick = function() {
	   	  ardCommentObj.toggleComment();
	   	  return false;
	   };
	   /* insert new link element */
	   document.getElementById('ardAddComment').parentNode.insertBefore(tmpObj,document.getElementById('ardAddComment'));
	},
	toggleComment: function() {
		 /* function to togle visibility */
	   if(document.getElementById('ardAddComment')
	   && document.getElementById('ardAddComment').className == 'inv') { document.getElementById('ardAddComment').className = ''; }
	   else { document.getElementById('ardAddComment').className = 'inv'; }	   	   
	},
	createCharCounter: function() {   
	   /* create charCounter */
	   var tmpObj = document.createElement('p');
	   tmpObj.setAttribute('id','ardCommmentCharCounter');
	   tmpObj.className = 'ardDescLink';
	   tmpObj.style.textAlign = 'center'
	   tmpObj.innerHTML = 'noch 1000 Zeichen verbleibend';
	   document.getElementById('ardCommentText').parentNode.insertBefore(tmpObj,document.getElementById('ardCommentText').nextSibling);
	   document.getElementById('ardCommentText').onkeyup = function() {
		 	  ardCommentObj.countChars();
		 };
	},
	countChars: function() {
		 /* function to count and display chars */
		 var diffCount = this.maxChars - document.getElementById('ardCommentText').value.length;
		 if(diffCount < 0) {
				document.getElementById('ardCommentText').value = document.getElementById('ardCommentText').value.substr(0,this.maxChars);
				diffCount = 0;
		 }
		 document.getElementById('ardCommmentCharCounter').innerHTML = 'noch ' + diffCount + ' Zeichen verbleibend';
	},
	maxChars: 1000
}
/* initialisation via jQuery DOM ready */
$j(document).ready(function() {
   ardCommentObj.init();
});
