function HTMLDisplayItem(data,element){
	this.maxTitleLength = 31;
	this.maxCaptionLength = 35;
	this.data = data;
	this.element = element;
}
pt = HTMLDisplayItem.prototype;
pt.renderSmall = function(){
	var table = this.element.appendChild(document.createElement('TABLE'));
	table.className = 'wbds_Videoplayer_content_smallitem';
	table.insertRow(0);
	table.rows[0].insertCell(0);
	table.rows[0].cells[0].appendChild(document.createElement('IMG'));
	var t = this;
	table.rows[0].cells[0].onclick = function(e){
		if(e == null){
			e = window.event;
		}
		e.cancelBubble = true;
		
		wbds_PlayInit(t.data.video_link,t.data.id,t.data.targeting);
		
	}
	table.rows[0].cells[0].firstChild.src = this.data.thumb_link;
	table.rows[0].cells[0].className = 'wbds_Videoplayer_content_smallitem_thumbcell';
	table.rows[0].cells[0].title = this.data.title;
	
	table.rows[0].insertCell(1);
	table.rows[0].cells[1].className = 'wbds_Videoplayer_content_smallitem_cont';
	table.rows[0].cells[1].onclick = table.rows[0].cells[0].onclick;
	table.rows[0].cells[1].title = this.data.title;
	
	var title,content,html;
	if(this.data.title.length > this.maxTitleLength && this.data.caption.length>0){
		title = this.data.title.substring(0,this.maxTitleLength-3)+'...';
	}else if(this.data.title.length > (this.maxTitleLength*2) && this.data.caption.length<=0){
		title = this.data.title.substring(0,(this.maxTitleLength*2)-3)+'...';
	}else{
		title = this.data.title;
	}
	
	if(this.data.caption.length > this.maxCaptionLength+20){
		content = this.data.caption.substring(0,(20+this.maxTitleLength)-3)+'...';
	}else{
		content = this.data.caption;
	}
	html = '<div class="wbds_Videoplayer_content_smallitem_title"><b>'+title+'</b></div>';
	html += '<div class="wbds_Videoplayer_content_smallitem_cont">'+content+'</div>';
	table.rows[0].cells[1].innerHTML = html;
	
}
pt.renderItem = function(){
	var html = '<img src="'+this.owner.bullit+'" class="wbds_Videoplayer_content_headeritem"/>';
	var title;
	if(this.data.title.length > this.maxTitleLength){
		title =  this.data.title.substring(0,this.maxTitleLength-3)+'...';
	}else{
		title =  this.data.title;
	}	
	this.element.innerHTML = html+'<a href="#" class="wbds_Videoplayer_content_headeritem" title="'+this.data.title+'" onclick="wbds_PlayInit(\''+this.data.video_link+'\','+this.data.id+',\''+this.data.targeting+'\');">'+title+'</a>';
}
pt.renderFull = function(){
	var table = this.element.appendChild(document.createElement('TABLE'));
	table.className = 'wbds_Videoplayer_content_fullitem';
	table.insertRow(0);
	table.rows[0].insertCell(0);
	table.rows[0].cells[0].appendChild(document.createElement('IMG'));
	var t = this;
	table.rows[0].cells[0].onclick = function(e){
		if(e == null){
			e = window.event;
		}
		e.cancelBubble = true;		
		wbds_PlayInit(t.data.video_link,t.data.id,t.data.targeting);
	}
	table.rows[0].cells[0].firstChild.src = this.data.thumb_link;
	table.rows[0].cells[0].className = 'wbds_Videoplayer_content_fullitem_thumbcell';
	table.rows[0].cells[0].title = this.data.title;
	
	
	table.rows[0].insertCell(1);
	table.rows[0].cells[1].onclick = table.rows[0].cells[0].onclick;
	table.rows[0].cells[1].className = 'wbds_Videoplayer_content_fullitem_title';
	var title,content,html;
	table.rows[0].cells[1].innerHTML = this.data.title.replace(/&/,'&amp;');
	table.rows[0].cells[1].title = this.data.title;
	
	if(this.data.caption != ''){
		table.insertRow(1);
		table.rows[1].insertCell(0);
		table.rows[1].cells[0].innerHTML = this.data.caption;
		table.rows[1].cells[0].className = 'wbds_Videoplayer_content_fullitem_cont';
		table.rows[1].cells[0].colSpan = 2;
	}
}


function HTMLDisplayItems(data,element,render,ids,bullit){
	this.elements = [];
	this.data = data;
	this.bullit = bullit;
	this.element = element;
	this.__render = this._render = render;
	this.render(render,ids);
}
pt = HTMLDisplayItems.prototype;
pt.setIds = function(ids){
	this.clear();
	this.render(this._render,ids);		
}
pt.clear = function(){
	//for(var i=0;i<this.table.rows.length;i++){
	//	this.table.rows[i].parentNode.removeChild(this.table.rows[i]);
	//}
	this.element.removeChild(this.table);
	this.elements = [];
}
pt.search = function(lookup){
	var ids = [];
	for(var i=0;i<this.data.length;i++){
		if(this.data[i].title.toLowerCase().indexOf(lookup)>=0 || this.data[i].caption.toLowerCase().indexOf(lookup)>=0){
			ids.push(this.data[i].id);
		}
	}
	this.clear();
	if(ids.length > 0 && ids.length <= 5){
		this._render = 'renderSmall';
	}else{
		this.restoreRender();
	}
	this.render(this._render,{ids:ids});
}
pt.render = function(render,ids){
	var data = this.data;
	var table = this.element.appendChild(document.createElement('TABLE'));
	var length = data.length,i,found,j,r=0;
	this.table = table;
	for(i=0;i<length;i++){
		found = false;
		if(ids == null || ids.ids.length == 0){
			found = true;
		}else{
			for(j=0;j<ids.ids.length;j++){
				if(ids.ids[j] == data[i].id){
					found = true;
					break;
				}
			}			
		}
		table.style.width="100%";
		table.style.paddingRight= "0px";
		table.style.marginRight= "0px";
		if(found){
			table.insertRow(r);
			table.rows[r].insertCell(0);
			table.rows[r].cells[0].appendChild(document.createElement('DIV'));
			table.rows[r].cells[0].style.width="100%";
			table.rows[r].cells[0].style.paddingRight= "0px";
			table.rows[r].cells[0].style.marginRight= "0px";
			table.rows[r].cells[0].firstChild.style.width="100%";
			table.rows[r].cells[0].firstChild.style.paddingRight= "0px";
			table.rows[r].cells[0].firstChild.style.marginRight= "0px";
			this.elements[r] = new HTMLDisplayItem(data[i],table.rows[r].cells[0].firstChild);
			this.elements[r].owner = this;
			this.elements[r][render]();
			r++;
		}
	}
}
pt.restoreRender = function(){
	this._render = this.__render;
}
function HTMLArchiveItem(data,element,owner,id){
	this.data = data;
	this.element = element;
	this.owner = owner;
	this.id = id;
}
pt = HTMLArchiveItem.prototype;
pt.normal = function(){
	var a  = this.element.appendChild(document.createElement('A'));
	a.innerHTML = this.data[0]+" ("+(this.data.length-1)+")";
	a.onclick = this.onClick;
	a.className = "wbds_Videoplayer_archive_cats";
	a.title = this.data[0];
	a.href = "#"
	a.owner = this;
}
pt.onClick = function(){
	var own = this.owner.owner;
	own.displayitems.restoreRender();
	own.displayitems.setIds(own.ids[this.owner.id]);
}
function HTMLArchive(data,element,render,displayitems,searchform,tab,tabinx){
	this.displayitems = displayitems;
	this.ids = [];
	this.elements = [];
	this.tab = tab;	
	this.tabinx = tabinx;
	var length = data.length,i,c=0,r=-1;
	
	var th = this;
	searchform =document.getElementById(searchform);
	searchform.onsubmit = function(e){
		e = e || window.event;
		th.dosearch(this.elements['searchfld'].value);
		return false;
	}
	
	var table = element.appendChild(document.createElement('TABLE'));
	this.table_cats = table;
	this.table_cats.className = "wbds_Videoplayer_archive_cats";
	
	for(i=0;i<length;i++){
		if(c%3==0){
			r++;
			table.insertRow(r);
			c=0;
		}
		table.rows[r].insertCell(c);
		table.rows[r].cells[c].appendChild(document.createElement('DIV'));
		this.elements[i] = new HTMLArchiveItem(data[i],table.rows[r].cells[c].firstChild,this,i);
		this.elements[i][render]();
		data[i].shift();
		this.ids[i] = {ids:data[i]};
		c++;
	}
}
pt = HTMLArchive.prototype;
pt.search = function(){
}
pt.dosearch = function(arg){
	this.tab.switchTab(this.tabinx);
	this.displayitems.search(arg);
}
