/*
{id:1, thumb:"/assets/images/gallery/photos/crabSpider_sm.jpg", video:"/scripts/js/videoplayers/generic/flash/test.flv", image:"/assets/images/gallery/photos/crabSpider_mid.jpg", duration:"01:30",  description:"xx", name:"fred" },
			        {id:2, thumb:"/assets/images/gallery/photos/crabSpider_sm.jpg",  video:"/scripts/js/videoplayers/generic/flash/test.flv", image:"/assets/images/gallery/photos/crabSpider_mid.jpg", duration:"01:30" , description:"xx", name:"red" },
			        {id:3, thumb:"/assets/images/gallery/photos/crabSpider_sm.jpg", video:"/scripts/js/videoplayers/generic/flash/test.flv", image:"/assets/images/gallery/photos/crabSpider_mid.jpg", duration:"01:30", description:"xx", name:"ed"  },
			        {id:4, thumb:"/assets/images/gallery/photos/crabSpider_sm.jpg", video:"/scripts/js/videoplayers/generic/flash/test.flv", image:"/assets/images/gallery/photos/crabSpider_mid.jpg", duration:"01:30" , description:"xx", name:"ed" },	
			        {id:5, thumb:"/assets/images/gallery/photos/crabSpider_sm.jpg", video:"/scripts/js/videoplayers/generic/flash/test.flv", image:"/assets/images/gallery/photos/crabSpider_mid.jpg", duration:"01:30", description:"xx", name:"ed"  },
			        {id:6, thumb:"/assets/images/gallery/photos/crabSpider_sm.jpg", video:"/scripts/js/videoplayers/generic/flash/test.flv", image:"/assets/images/gallery/photos/crabSpider_mid.jpg", duration:"01:30", description:"xx", name:"ed"  }
*/

tdi_videoViewer = {
	vars:{
		
		mainDisplay:{
			lightBox:{id:"tdi_imageDispDiv_lightBox", css:0},
			mainCon:{id:"tdi_imageDispDiv", css:"#tdi_imageDispDiv"},
			closeBtn:{id:"tdi_imageDispDiv_closeBtn", css:0, script:0},
			
			pageTitle:{id:"tdi_imageDispDiv_pageTitle", css:0},
			videoTitle:{id:"tdi_imageDispDiv_videoTitle", css:0},
			
			largeImg:{id:"tdi_imageDispDiv_mainImage", css:"#tdi_imageDispDiv .mainImage"},
			
			disclaimer_b_title:{id:"tdi_imageDispDiv_disclaimer_b_title", css:0},
			disclaimer_b_copy:{id:"tdi_imageDispDiv_disclaimer_b_copy", css:0},
			captionRight:{id:"tdi_imageDispDiv_CaptionRight", css:0},
			
			
			thumbCon:{id:"tdi_sliderHolderGroupDiv", css:"#tdi_imageDispDiv .sliderHolderGroupDiv"},
			thumbHolder:{id:"tdi_imageDispDiv_sliderHoderDiv", css:"#tdi_imageDispDiv .sliderHoderDiv"},
			thumbSlider:{id:"tdi_imageDispDiv_imageDivSlider", css:"#tdi_imageDispDiv .imageDivSlider"},
			proxySlider:{id:0, css:0},
			groupDisplay:{id:"tdi_imageDispDiv_imageGroupDisplay", css:"#tdi_imageDispDiv .imageGroupDisplay"},
			picCounter:{id:"tdi_imageDispDiv_picCounter", css:"#tdi_imageDispDiv .picCounterText"},
			captionOver:{id:"tdi_imageDispDiv_CaptionOver", css:0},
			captionOverHolder:{id:"tdi_imageDispDiv_CaptionOverHolder", css:"#tdi_imageDispDiv .imageDispDiv_CaptionOverHolder"},
			infoIcon:{id:"tdi_imageDispDiv_infoIcon", css:"#tdi_imageDispDiv .infoIcon"},
			disclaimer_a:{id:"tdi_imageDispDiv_disclaimer_a", css:"#tdi_imageDispDiv .disclaimer"},
			wallpaper:{id:"tdi_magGroup_wallpaper", css:0}
		},
		env:{
			baseDir:0,
			baseImg:0,
			scrollBar:0,
			zoom:0,
			lightBox:0,
			wallPaper:0,
			startImg:0
		},
		videos:0,
		info:{
			imgLut:[],
			flashData:{
		        current:1,
		        autoplay:0,
		        data:[
			        
			    ]
		    },
		    flashObj:0,
		    hasFlash:0
		}
	},
	utils:0,
	autoFuns:{
		
	
		main:function(oPar, sName){
			this.par = oPar
			this.name = sName
			this.site = oPar.par
			this.isLoaded = 0
			
			
			this.inish = function(oSelf){
				this.self = oSelf
				
			}
			
			this.run = function(){
			   
			    var v = this.par.vars
			    var lut = v.info.imgLut
			    
			    var getInfo = v.videos
			    var putInfo = v.info.flashData.data
			    
			    for(var e in getInfo){
			        var n = parseInt(e.split("_").pop())
			        lut.push(e)
			        putInfo.push({id:n,thumb:getInfo[e].thumb,video:getInfo[e].video,image:getInfo[e].image,duration:getInfo[e].duration,description:getInfo[e].description,name:e})
			    }
			    targ = this.par.vars.mainDisplay
			    
			    for(var e in targ) targ[e].obj = document.getElementById(targ[e].id)
			    
			    if(this.par.vars.env.scrollBar){
					this.par.vars.env.scrollBar = this.site[this.par.vars.env.scrollBar].main.run(
						document.getElementById("tdi_imageDispDiv_CaptionRight_scroller_scrollBarDiv"),
						document.getElementById("tdi_imageDispDiv_CaptionRight_scroller"),
						document.getElementById("tdi_imageDispDiv_CaptionRight_scroller_container")
						)
				}
				if(this.par.vars.env.lightBox){
				    this.site[this.par.vars.env.lightBox].main.add(this.par.name, this.par.vars.mainDisplay.lightBox.obj, 0, document.getElementById("tdi_contentBoxHolder"), document.getElementById("tdi_contentBoxHolder"))
				}
				
				var r = new this.par.funs.closeBTN(this.par, this.par.name, this.par.vars.mainDisplay.closeBtn.obj, this.par.vars.mainDisplay.lightBox)
				r.inish(r, this.par.par)
				this.par.vars.mainDisplay.closeBtn.script = r
				
				var r = new this.par.funs.closeBTN(this.par, this.par.name, this.par.vars.mainDisplay.pageTitle.obj, this.par.vars.mainDisplay.lightBox)
				r.inish(r, this.par.par)
				
				r = new this.par.funs.rDisclaim(
					this.par.vars.mainDisplay.disclaimer_b_title.obj,
					this.par.vars.mainDisplay.disclaimer_b_copy.obj,
					this.par.vars.env.scrollBar
				)
				r.inish(r, this.site)
				
				
				if(this.site.vars.flash.getFlash){
					this.par.vars.mainDisplay.largeImg.obj.style.backgroundImage = "url('"+getInfo[lut[v.info.flashData.current]].image+"')"
				} else {
					this.par.vars.info.flashObj = getPackageForName("wtk.widgetInstances").testvid = new com.forddirect.presentation.widget.flvideoplayer.TestVid(this.par.vars.mainDisplay.largeImg.obj , "wtk.widgetInstances.testvid" );
					wtk.widgetInstances.testvid.TheData = this.par.vars.info.flashData
					wtk.widgetInstances.testvid.init("", 590, 332);
				}
			}
			
			this.draw = function(){
			    
			}
			
			this.show = function(param){
				this.site.flipLightBox.main.show(this.par.name)
				
				var info = this.par.vars.info
				if(typeof(param) == "number") param = info.imgLut[param]
				 this.par.controler.displayVideo(param)
				
				//this.par.deepLink.run(iInt)
			}
		},
	    load:function(oPar, sName){
	        this.par = oPar
	        this.name = sName
	        this.inish = function(oSelf){
	            this.self = oSelf
				this.par.par.vars.events.load[this.par.name] = oSelf
            }
			this.run = function(bAllLoad){
			    if(bAllLoad){
				   
                    this.par.main.run()     
				    delete this.par.par.vars.events.load[this.par.name]
				}
			}
	    },	
		
		controler:function(oPar, sName){
			this.par = oPar
			this.site = oPar.par
			this.name = sName
			this.inish = function(oSelf){
				this.self = oSelf
			}
			this.displayVideo = function(sVideo){
					
				var targ = this.par.vars.videos[sVideo]
				var cap = targ.cap
				var md = this.par.vars.mainDisplay
				md.videoTitle.obj.innerHTML = targ.title
				
				md.captionRight.obj.innerHTML = targ.description
				md.disclaimer_b_copy.obj.style.display = "none"
				
				var vis = "hidden"
				if(parseInt(targ.disclaimer.length)){
					vis = "visible"
					vis = ""
					md.disclaimer_b_copy.obj.innerHTML = targ.disclaimer
				}
				
				this.par.vars.mainDisplay.disclaimer_b_title.obj.style.visibility = vis
				if(this.par.vars.env.scrollBar) this.par.vars.env.scrollBar.run(0)	

				if(this.site.vars.flash.getFlash){
					this.par.vars.mainDisplay.largeImg.obj.style.backgroundImage = "url('"+targ.image+"')"
				} else {
					this.par.vars.info.flashObj.launchVideo({id:parseInt(sVideo.split("_").pop())})
				}

				
			}
		}
		
		
		
	},
	funs:{
		closeBTN:function(oPar, sName, oObj, lightBox){
			this.par = oPar
			this.name = sName
			this.obj = oObj
			this.lightBox = lightBox
			this.inish = function(oSelf, oSite){
				this.site = oSite
				var fun = function(){
				
					oSelf.run()
				}
				oSite.utils.addListener(this.obj, ["mouseup"], fun)
			}
			this.run = function(){
			    this.par.vars.env.scrollBar.run(1)
				this.site.flipLightBox.main.hide(this.name)
				if(this.par.vars.info.flashObj) this.par.vars.info.flashObj.stopVideo()
			}
		},
		
		rDisclaim:function(oClick, oDisplay, oScroll){
			this.click = oClick
			this.disp = oDisplay
			this.scroll = oScroll
			this.inish = function(oSelf, oPar){
				var fun = function(event){
					oSelf.run(event)
				}
				oPar.utils.addListener(this.click, ["mouseup"], fun)
			}
			this.run = function(){
				var disp = "none"
				if(this.disp.style.display.length) disp = ""
				this.disp.style.display = disp
				oScroll.run(0)
			}
		}
		
	},
	
	config:function(oSelf){
		this.self = oSelf
		this.vars = oSelf.vars
		
		this.env = function(oAry){
			var targ = this.vars.env
			for(var e in targ){
				var info = oAry[e]
				//if(!info) return alert("missing "+e)
				targ[e] = info
			}
			
		
		}
	},
	inish:tdi_site.funs.genInish
}

tdi_site.autoFuns["videoViewer"] = tdi_videoViewer