var news_item_detail_ob_arr=new Array()
var news_item_detail_id_arr=new Array()

function news_item_detail_class(_news_item_ID,_atag){
	var _me=this
	this.news_item_ID=_news_item_ID
	this.id="n"+_news_item_ID
	this.xml_loader_ob=0
	this.xml_doc_ob=0
	this.xml_loaded=0
	this.atag=_atag
	//USE THE atag TO FIND THE RELEVANT TAGS
	
	var summary_holder=_me.atag.parentNode.previousSibling
	if(summary_holder.nodeType==3){
		summary_holder=summary_holder.previousSibling
	}
	summary_holder.id=_me.id+"_summary"
	
	//SUMMARY HOLDER IS THE THE PTAG CONTAINING THE DATE AND THE TRUNCATED TEXT
	this.summary_holder=document.getElementById(_me.id+"_summary")

	//CREATE A p tag AFTER THE SUMMARY p tag TO HOLD THE DETAIL
	var detail_holder=this.summary_holder.cloneNode(1)
	detail_holder.id=_me.id+"_detail"
	detail_holder.innerHTML=""
	
	_me.summary_holder.parentNode.insertBefore(detail_holder,_me.atag.parentNode)
	this.detail_holder=document.getElementById(_me.id+"_detail")
	this.detail_holder.style.display="none"
	
	this.get_data=function(){
		if(_me.xml_loaded==0){
			_me.start_load_xml("library/get_news_item_details_xml.asp","data","news_item_ID="+_me.news_item_ID)
		}else{
			_me.show()	
		}
	}
	
	this.start_load_xml=function(thispath,thisname,params){
	
		if(thispath.indexOf(pthstr)==-1){
			xmlpth=pthstr+thispath
		}else{
			xmlpth=thispath
		}
		if(typeof params=="undefined" || !params){
			params=""
		}
	
		xml_mode="ie"
		
		/*@cc_on @*/
		/*@if (@_jscript_version >= 5)
			// JScript gives us Conditional compilation, we can cope with old IE versions.
			// and security blocked creation of the objects.
	
			try {
				_me.xml_loader_ob = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					_me.xml_loader_ob = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (E) {
					_me.xml_loader_ob = false;
				}
			}
	
		/*@end @*/
		
		
		if (!_me.xml_loader_ob && typeof XMLHttpRequest!='undefined') {
			_me.xml_loader_ob = new XMLHttpRequest();
			xml_mode="moz"
		}
		
		if(params==""){
			_me.xml_loader_ob.open("GET", xmlpth,true);
		}else{
			_me.xml_loader_ob.open("POST", xmlpth,true);
			_me.xml_loader_ob.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		}
		
		_me.xml_loader_ob.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
		
		
		if(thisname=="data"){
			_me.xml_loader_ob.onreadystatechange=_me.parse_data_xml
		}
	

		xmlob_loaded_arr[thisname]=0
		
		if(params==""){
		
			_me.xml_loader_ob.send(null)
		}else{
			
			_me.xml_loader_ob.send(params)
		}
	
	}
	
	this.parse_data_xml=function(){
	

	
		if(_me.xml_loader_ob.readyState==4){
			
			if(browser.isIE){
				_me.xml_doc_ob=new ActiveXObject('Microsoft.XMLDOM')
				_me.xml_doc_ob.loadXML(_me.xml_loader_ob.responseText)
			}else{
				_me.xml_doc_ob=new DOMParser().parseFromString(_me.xml_loader_ob.responseText, 'text/xml')
			}
			
			test_nodes=_me.xml_doc_ob.selectNodes("//*")
			


			
			if(test_nodes.length>0){
			
				_me.xml_loaded=1
				
				_me.draw_detail()
			}
	
	
		}
	}
	this.draw_detail=function(){
		var nodes=_me.xml_doc_ob.selectNodes("//news_item")
		
		if(nodes.length>0){
		
			var date_node=_me.summary_holder.getElementsByTagName("strong")[0]	
			var date_str="<strong>"+date_node.innerHTML+"</strong>"
			var long_text=nodes[0].getAttribute("long_text")
				
			long_text=long_text.replace(/<!--StartFragment-->/g,"")
			long_text=long_text.replace(/<!--EndFragment-->/g,"")
			
			var newdiv=document.createElement("div")
			newdiv.innerHTML=date_str+" "+long_text
			//alert(newdiv.innerHTML)
			//if(browser.isIE){
//				_me.xml_doc_ob=new ActiveXObject('Microsoft.XMLDOM')
//				_me.xml_doc_ob.loadXML("<long_text>"+long_text+"</long_text>")
//			}else{
//				_me.xml_doc_ob=new DOMParser().parseFromString("<long_text>"+long_text+"</long_text>", 'text/xml')
//			}
//			var divs=_me.xml_doc_ob.selectNodes("//long_text")[0].childNodes
//			
//			for(var i=0;i<divs.length;i++){
//				switch(divs[i].nodeType){
//					case 3:
//						var txt=document.createTextNode(divs[i].nodeValue)
//						_me.detail_holder.appendChild(txt)
//						
//					break
//					case 1:
//						
//						if(divs[i].childNodes.length>0){
//							var divi=document.createTextNode(divs[i].tagName)
//							for(var j=0;j<divs[i].childNodes.length;j++){
//								switch(divs[i].childNodes[j].nodeType){
//									case 3:
//										var txt=document.createTextNode(divs[i].childNodes[j].nodeValue)
//										divi.appendChild(txt)
//									break
//									case 1:
//										
//										if(divs[i].childNodes[j].childNodes.length>0){
//											var divj=document.createTextNode(divs[j].tagName)
//											for(var k=0;k<divs[i].childNodes[j].childNodes.length;k++){
//												switch(divs[i].childNodes[j].childNodes[k].nodeType){
//													case 3:
//														
//														var txt=document.createTextNode(divs[i].childNodes[j].childNodes[k].nodeValue)
//														divj.appendChild(txt)
//													break
//													case 1:
//														
//														if(divs[i].childNodes[j].childNodes[k].childNodes.length>0){
//															var divk=document.createTextNode(divs[j].tagName)
//															var txt=document.createTextNode(divs[i].childNodes[j].childNodes[k].firstChild.nodeValue)
//															divk.appendChild(txt)
//															divj.appendChild(divk)
//														}
//														
//													break;
//												}
//											}
//											divi.appendChild(divj)
//										}
//										
//									break;
//								}
//							}
//							_me.detail_holder.appendChild(divi)
//						}
//						
//					break;
//				}
//			}
//			newdiv.innerHTML=long_text
//			var divs=newdiv.getElementsByTagName("div")
//			alert(divs.length)



			//if(long_text.indexOf("<div>")>-1){
//				
//				var arr1=long_text.split("<div>")
//				if(arr1.length>0){
//					var str=""
//					for(var i=0;i<arr1.length;i++){
//						str=str+arr1[i]
//					}
//					long_text=str
//				}
//			}
//		
//			if(long_text.indexOf("</div>")>-1){
//				
//				var arr1=long_text.split("</div>")
//				if(arr1.length>0){
//					var str=""
//					for(var i=0;i<arr1.length;i++){
//						str=str+arr1[i]
//					}
//					long_text=str
//				}
//			}
//			
//			var safety=0
//			while(long_text.charCodeAt(0)==10 && safety<10){
//				safety++
//				long_text=long_text.substr(1,long_text.length)
//			}
//				 // alert(long_text.indexOf("<br/>"))
//			//long_text=ltrim(long_text)
//			//long_text=rtrim(long_text)
//			
//			if(long_text.indexOf("<br/>")==0){
//				long_text=long_text.substr(	("<br/>").length,long_text.length)
//			
//			}
			
			_me.detail_holder.appendChild(newdiv) //.innerHTML=date_str+" "+long_text
			
			//OTHER LINKS
			//ATTACHMENTS
			var attachment_nodes=_me.xml_doc_ob.selectNodes("//attachments[@is_admin_only=0]")

			if(attachment_nodes.length>0){
				var attachment_count=0
	
				for(var i=0;i<attachment_nodes.length;i++){
					attachment_count=i
					var n=attachment_nodes[i]
					var att_pth=n.getAttribute("attachment_filename")
					var att_src=""
					if(typeof att_pth!="undefined" && !!att_pth){
						if(att_pth!=""){
							att_src=pthstr+"assets/news_item_attachments/"+nodes[0].getAttribute("news_item_ID")+"/"+att_pth
						}
					}
				}

		
				var att_title=""
				if(typeof n.getAttribute("attachment_title")!="undefined" && !!n.getAttribute("attachment_title")){
					if(n.getAttribute("attachment_title")!=""){
						att_title=n.getAttribute("attachment_title")
					}
				}
				if(att_title==""){
					att_title=att_pth
				}
				var newp=document.createElement("p")
				newp.style.marginTop="10px"
				
				var newa=document.createElement("a")
				newa.href=att_src
				newa.target="_blank"
				newa.innerHTML=att_title
				
				newp.appendChild(newa)
				_me.detail_holder.appendChild(newp)
				
			}
		
			//URLS
			var url_nodes=_me.xml_doc_ob.selectNodes("//urls")
	
			if(url_nodes.length>0){
				var url_count=0
				for(var i=0;i<url_nodes.length;i++){
					url_count=i
					var n=url_nodes[i]
					var url=""
					if(typeof n.getAttribute("url")!="undefined" && !!n.getAttribute("url")){
						if(n.getAttribute("url")!=""){
							url=n.getAttribute("url")
						}
					}
					
					
					var url_title=""
					if(typeof n.getAttribute("url_title")!="undefined" && !!n.getAttribute("url_title")){
						if(n.getAttribute("url_title")!=""){
							url_title=n.getAttribute("url_title")
						}
					}
					
					
					if(url_title==""){
						url_title=url
						 if(url_title.length>50){
							url_title=url_title.substr(0,50)
							if(url_title.lastIndexOf("/")>-1){
								url_title=url_title.substr(0,url_title.lastIndexOf("/")) 
							}
							url_title=url_title+"..."
						 }
					}
					
					if(url.indexOf("://")==-1){
						url="http://"+url
					}
					
					var newp=document.createElement("p")
					newp.style.marginTop="10px"
					newp.style.paddingLeft="0px"
					
					var newa=document.createElement("a")
					newa.href=url
					newa.target="_blank"
					newa.innerHTML=url_title
					
					newp.appendChild(newa)
					_me.detail_holder.appendChild(newp)
			
				}
			}
			
			//CATEGORY LINKS
			var category_links=_me.xml_doc_ob.selectNodes("//news_item_links[@link_type='category']")
			if(category_links.length>0){
				for(var i=0;i<category_links.length;i++){
					var l=category_links[i]
					//THE FULL CATEGORY LIST SHOULD HAVE BEEN LOADED BY THE SEARCH SCRIPTS
					var matching_nodes=search_ob.search_xml.selectNodes("//category[@category_ID="+l.getAttribute("other_ID")+"]")
					var nm=l.getAttribute("other_name")
					if(matching_nodes.length>0){
						var pnode=matching_nodes[0].parentNode
					
						while(pnode.nodeName=="category"){
							if(pnode.getAttribute("category_parent_ID")!="0"){
								if(pnode.getAttribute("category_name").substr(pnode.getAttribute("category_name").length-1,1)!=":"){
									var gap=": "
								}else{
									var gap=" "
								}
			
								nm=pnode.getAttribute("category_name")+gap+nm
							}
							pnode=pnode.parentNode
						}
	
					}
					var newp=document.createElement("p")
					newp.style.marginTop="10px"
					newp.style.paddingLeft="0px"
					
					var newa=document.createElement("a")
					newa.href="results.asp?category="+l.getAttribute("other_ID")
					newa.innerHTML="Search for "+nm+" in the PrintSpeak directory"
					
					newp.appendChild(newa)
					_me.detail_holder.appendChild(newp)
				}
			}
				



			_me.show()
			
		
		}
		
	}
	this.show=function(){
		_me.detail_holder.style.display=""
		_me.summary_holder.style.display="none"
		_me.atag.onclick=_me.hide
		_me.atag.innerHTML="Less..."
	}
	this.hide=function(){
		_me.detail_holder.style.display="none"
		_me.summary_holder.style.display=""
		_me.atag.onclick=_me.show
		_me.atag.innerHTML="More..."
	}
}