var video_library_ob

function video_library_class(_v_ID){
	var _me=this
	this.xml_loader=0
	this.xml_ob=0
	this.v_ID=_v_ID

	this.default_str='<div id="videoPlayer" style="visibility:hidden"><p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p></div>'
	
	this.setup_interface=function(){
		
	}
	this.change=function(){
		
		val=_me.v_ID	

		
		_me.load_xml("library/get_video_library_xml.asp","video_ID="+val)
		
	}
	
	this.draw_video=function(){
	
		_me.reset_video()

		
		
		videoPlayer_ob=document.getElementById("videoPlayer")

		
		
		//window.open(pthstr+"library/flash_video_player_I/deploy/get_settings_xml.asp?id="+_me.v_ID)
		
		settings_file="get_settings_xml.asp?id="+_me.v_ID
		var flashvars = {
		  htmlPage: document.location,
		 // currVideo: _me.v_pos,
		  settingsFile: settings_file
		};
		var params = {
		  allowFullScreen: "true"
		};
		var ipod=(navigator.userAgent.indexOf('iPhone') != -1) || (navigator.userAgent.indexOf('iPod') != -1) || (navigator.userAgent.indexOf('iPad') != -1)
		if (!ipod) {
			swfobject.embedSWF(pthstr+"library/flash_video_player_I/deploy/videoPlayer.swf", "videoPlayer", "464", "280", "9.0.115", pthstr+"library/flash_video_player_I/deploy/swfobject/expressInstall.swf", flashvars, params);
		}else{
			qt_video_embedder.embed_qt_link(_me.v_ID)
		}
	}
	
	this.reset_video=function(){
		
		//GET DIV THE HOLDS FLV PLAYER
		video_clip_holder_ob=document.getElementById("video_panel")
		video_clip_holder_ob.innerHTML=_me.default_str
		
		
	}
	
	this.draw_text=function(){
		
		var current_node=_me.xml_ob.selectSingleNode(".//item")
		var v_title_node=current_node.selectSingleNode("./title")
		var v_strapline_node=current_node.selectSingleNode("./strapline")
		
		var v_body_nodes=current_node.selectNodes("./body")
		var v_abstract_nodes=current_node.selectNodes("./abstract")
		var v_specs_caption_nodes=current_node.selectNodes("./specifications/caption")
		var v_spec_row_nodes=current_node.selectNodes("./specifications/tabulated/row")
		
		var v_seconds=current_node.getAttribute("video_seconds")
		var v_minutes=((parseInt(v_seconds)*1.0)/60.0).toFixed(0)
		
		document.getElementById("speakabout_title").innerHTML=v_title_node.firstChild.nodeValue
		document.getElementById("speakabout_strapline").innerHTML=v_strapline_node.firstChild.nodeValue
		document.getElementById("video_type").innerHTML=current_node.getAttribute("type")
		document.getElementById("video_minutes").innerHTML=v_minutes+" minute "
		document.getElementById("video_date").innerHTML=current_node.getAttribute("date")
		if(v_body_nodes.length>0){
			document.getElementById("speakabout_body").innerHTML=v_body_nodes[0].firstChild.nodeValue
		}else{
			document.getElementById("speakabout_body").innerHTML=""
		}
		
		if(v_abstract_nodes.length>0){
			document.getElementById("video_abstract").innerHTML=v_abstract_nodes[0].firstChild.nodeValue
		}else{
			document.getElementById("video_abstract").innerHTML=""
		}
		
		var details_holder=document.getElementById("speakabout_details")
		details_holder.innerHTML=""
		
		if(v_specs_caption_nodes.length>0){
			var div=document.createElement("div")
			div.className="speakabout_caption"
			div.innerHTML=v_specs_caption_nodes[0].firstChild.nodeValue
			details_holder.appendChild(div)
		}
		
		
		for(var i=0;i<v_spec_row_nodes.length;i++){
			var cnode=v_spec_row_nodes[i].selectSingleNode("./criteria")
			var div=document.createElement("div")
			div.className="tabulated criteria"
			div.innerHTML=cnode.firstChild.nodeValue
			details_holder.appendChild(div)
			
			var vnode=v_spec_row_nodes[i].selectSingleNode("./value")
			var div=document.createElement("div")
			div.className="tabulated value under"
			div.innerHTML=vnode.firstChild.nodeValue
		details_holder.appendChild(div)
		}
		
		var category_link_holder=document.getElementById("speakabout_category_link")
		category_link_holder.innerHTML=""
		category_link_holder.style.display="none"
		
		var item_link_holder=document.getElementById("video_item_link")
		item_link_holder.innerHTML=""
		item_link_holder.style.display="none"
		
		var supplier_link_holder=document.getElementById("video_supplier_link")
		supplier_link_holder.innerHTML=""
		supplier_link_holder.style.display="none"
		
		current_categories=current_node.selectNodes("./directory_categories/category")
		//if(typeof current_node.getAttribute("category_ID")!="undefined" && !!current_node.getAttribute("category_ID")){
		if(current_categories.length>0){
			for(var cat=0;cat<current_categories.length;cat++){
				//GET CATEGORTY DETAILS FROM SEARCHOB
				var current_cat_id=current_categories[cat].getAttribute("category_ID")
				var matching_nodes=search_ob.search_xml.selectNodes("//category[@category_ID="+current_cat_id+"]")
				
				if(matching_nodes.length>0){
					
					var nm=matching_nodes[0].getAttribute("category_name")
					var pnode=matching_nodes[0].parentNode
					while(pnode.nodeName=="category"){
						if(pnode.getAttribute("category_parent_ID")!="0"){
							var str=pnode.getAttribute("category_name")
							if(str.substr(str.length-1,1)==":"){
								var gap=" "
							}else{
								if(str.substr(str.length-2,2)==": "){
									var gap=""
								}else{
									var gap=": "
								}
							}
						
		
							nm=pnode.getAttribute("category_name")+gap+nm
						}
						pnode=pnode.parentNode
					}
					
					var a=document.createElement("a")
					a.className="search"
					a.href="results.asp?category="+current_cat_id
					a.innerHTML="Search for "+nm+" in the PrintSpeak directory"
					
					a.style.paddingTop="2px"
					
					category_link_holder.appendChild(a)
					category_link_holder.style.display=""
				}
			}
		
		}
		
		if(typeof current_node.getAttribute("item_name")!="undefined" && !!current_node.getAttribute("item_name")){

			var a=document.createElement("a")
			a.className="search"
			a.href="content/item_details.asp?item_ID="+current_node.getAttribute("item_ID")
			a.innerHTML="View the "+current_node.getAttribute("item_man_name")+current_node.getAttribute("item_name")
			item_link_holder.appendChild(a)
			item_link_holder.style.display=""
		
	
		}
		if(typeof current_node.getAttribute("supplier_name")!="undefined" && !!current_node.getAttribute("supplier_name")){

			var a=document.createElement("a")
			a.className="search"
			a.href="results.asp?search="+current_node.getAttribute("supplier_name")
			a.innerHTML="Search for "+current_node.getAttribute("supplier_name")+" in the PrintSpeak directory"
			supplier_link_holder.appendChild(a)
			supplier_link_holder.style.display=""
		
	
		}
	}
	
	
	
	this.load_xml=function(xmlpth,params){

		
		xmlpth=pthstr+xmlpth
		
	
		//window.open(xmlpth+"?"+params)
		/*@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 = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					_me.xml_loader = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (E) {
					_me.xml_loader = false;
				}
			}
	
		/*@end @*/
		
		if (!_me.xml_loader && typeof XMLHttpRequest!='undefined') {
			_me.xml_loader = new XMLHttpRequest();
		}
		
		if(params!=""){
			_me.xml_loader.open("POST", xmlpth,true);
		}else{
			_me.xml_loader.open("GET", xmlpth,true);
		}
		_me.xml_loader.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
		_me.xml_loader.setRequestHeader('Content-Type','application/x-www-form-urlencoded');

		_me.xml_loader.onreadystatechange=function(){_me.xml_loaded()}

		if(params!=""){
			_me.xml_loader.send(params)
		}else{
			_me.xml_loader.send(null)
		}

		
	
	}
	
	this.xml_loaded=function(){
		
		if (_me.xml_loader.readyState==4) {

			
			
			if(browser.isIE){
				var xml_ob=new ActiveXObject('Microsoft.XMLDOM')
				xml_ob.loadXML(_me.xml_loader.responseText)
			}else{
				var xml_ob=new DOMParser().parseFromString(_me.xml_loader.responseText, 'text/xml')
			}
			
			var output_nodes=xml_ob.selectNodes("//item")
				
			if(output_nodes.length>0){
				_me.xml_ob=xml_ob
				_me.draw_video()
				
				_me.video_ID=output_nodes[0].getAttribute("video_ID")
			
				_me.draw_text()

			}


		}
	}
}

function change_video(thisid){
	video_library_ob=new video_library_class(thisid)
	video_library_ob.setup_interface()
	video_library_ob.change()
}

var qt_video_embedder=new function(){
	
	var _me=this
	this.xml_loader=0
	this.xml_ob=0
	
	this.embed_qt_link=function(v_ID){
		
		setup_ajax()
		
		var settings_file="library/flash_video_player_I/deploy/get_settings_xml.asp?id="+v_ID
		
		_me.load_xml(settings_file,"")
	}
	
	this.load_xml=function(xmlpth,params){

		
		xmlpth=pthstr+xmlpth
		
	
		//window.open(xmlpth+"?"+params)
		/*@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 = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					_me.xml_loader = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (E) {
					_me.xml_loader = false;
				}
			}
	
		/*@end @*/
		
		if (!_me.xml_loader && typeof XMLHttpRequest!='undefined') {
			_me.xml_loader = new XMLHttpRequest();
		}
		
		if(params!=""){
			_me.xml_loader.open("POST", xmlpth,true);
		}else{
			_me.xml_loader.open("GET", xmlpth,true);
		}
		_me.xml_loader.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
		_me.xml_loader.setRequestHeader('Content-Type','application/x-www-form-urlencoded');

		_me.xml_loader.onreadystatechange=function(){_me.xml_loaded()}

		if(params!=""){
			_me.xml_loader.send(params)
		}else{
			_me.xml_loader.send(null)
		}

		
	
	}
	
	this.xml_loaded=function(){
		
		if (_me.xml_loader.readyState==4) {

			
			
			if(browser.isIE){
				_me.xml_ob=new ActiveXObject('Microsoft.XMLDOM')
				_me.xml_ob.loadXML(_me.xml_loader.responseText)
			}else{
				_me.xml_ob=new DOMParser().parseFromString(_me.xml_loader.responseText, 'text/xml')
			}
			
			
			//this.draw_preview()
			this.draw_qt("false")
		}
	}
	
	this.draw_preview=function(){
		
		var previewImage=_me.xml_ob.selectSingleNode("//previewImage").getAttribute("value")
		
		var playerWidth =_me.xml_ob.selectSingleNode("//playerWidth").getAttribute("value")
		
		var playerHeight =_me.xml_ob.selectSingleNode("//playerHeight").getAttribute("value")
		
		video_clip_holder_ob=document.getElementById("video_panel")
		video_clip_holder_ob.innerHTML=""
		
	
		var img=document.createElement("img")
		img.id="video_qt_preview"
		img.src=previewImage
		img.width=playerWidth
		img.height=playerHeight
		img.border=0
		img.style.cursor="pointer"
		
		
		video_clip_holder_ob.appendChild(img)
		
		var ob=document.getElementById(img.id)
		if(ob.addEventListener){
			ob.addEventListener('mouseup',_me.draw_qt,false);
			
		}else{
			if(ob.attachEvent) {
				ob.attachEvent('onmouseup',_me.draw_qt,false);
				
			}
		}
		
		
	}
	
	this.draw_qt=function(andplay){
		
		
		
		var videoPath =_me.xml_ob.selectSingleNode("//videoPath").getAttribute("value")
		
		var playerWidth =_me.xml_ob.selectSingleNode("//playerWidth").getAttribute("value")
		
		var playerHeight =parseInt(_me.xml_ob.selectSingleNode("//playerHeight").getAttribute("value"))-20

		var str=""
		str+='<object width="'+playerWidth+'" height="'+playerHeight+'"'
		str+='classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"'
		str+='codebase="http://www.apple.com/qtactivex/qtplugin.cab">'
		str+='<param name="src" value="'+videoPath+'">'
		str+='<param name="autoplay" value="'+andplay+'">'
		str+='<param name="controller" value="true">'
		
		str+='<embed src="'+videoPath+'" width="'+playerWidth+'" height="'+playerHeight+'"'
		str+='autoplay="'+andplay+'" controller="true"'
		str+='pluginspage="http://www.apple.com/quicktime/download/">'
		str+='</embed>'
		
		str+='</object>'
		
		video_clip_holder_ob=document.getElementById("video_panel")
		video_clip_holder_ob.innerHTML=str
		video_clip_holder_ob.style.height=playerHeight+"px"
	}
}