﻿/* ------------------------ QuickList Html actions ---------------------- */
function QuickListHTML() {

	this.getElt=function(str){
		if (this[str]) return true;
		var elt=document.getElementById(str);
		if (!elt) return false;
		this[str]=elt;
		return true;
	};

	
	this.onClickNext=function(){this.scrollVert.onClickNext();};
	this.onClickPrev=function(){this.scrollVert.onClickPrev();};
	
	this.loadScroll=function(count) {
		if (!this.getElt('vidList')) return;
		this.vidList.style.top = '0';
		var paramsVert = new Array();
		paramsVert.items = count; // total number of items
		paramsVert.direction = 'top'; // direction: top/left/right
		paramsVert.itemSize = 56; // elm Height + spacer
		paramsVert.numVidScroll = 5; // number of items to scroll + number of items displayed
		paramsVert.itemsDisplay = 5; // number of items to display
		this.scrollVert = new scroll ('vidList',paramsVert);
	}
	
	this.buildHtml=function() {
		if (!this.getElt('vidList')) return;
		if(QuickList.getAll()) {
			var allItems = QuickList.getAll().split(" ");
			// reset div content
			this.vidList.innerHTML = '';
			for (i=0;i<allItems.length;i++) {
				this.addItemHTML(allItems[i]);
			}
			// update QuickList Count
			this.countItems(allItems.length);
			this.loadScroll(allItems.length);
		} else {
			this.countItems(0);
			this.loadScroll(0);
			this.vidList.innerHTML = '';
		}
		
	};
	
	this.DisplayQuickList=function() {
		if (!this.getElt('QL')) return;
		this.QL.style.visibility = (this.QL.style.visibility == 'visible') ? 'hidden' : 'visible';
	}
	
	this.countItems=function(count) {
		if (!this.getElt('itemsCount')) return;
		this.itemsCount.innerHTML = count;
	}
	
	this.addItemHTML=function(id) {
		if (!this.getElt('vidList')) return;
		var items = QuickList.getItem(id).split("*");
		var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
		
		// creating div item that contains the values
		// Chrome browser
		if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1) {
			var divItem = document.createElement("div");
		} else {
			var divItem = document.createElement("<div>");
		}
		divItem.id = 'vidItem'+id;
		divItem.className = 'vidItem';

		// child Html
		var tblHtml = '';
		tblHtml = "<div class='vidItem'>"
			tblHtml += "<div class='vidImg'>"
				tblHtml += "<img src='"+items[2]+"' class='imgVid' onclick='playMyHot("+id+");'/><img src='/images/hot/play.png' class='play' onclick='playMyHot("+id+")'/>"
			tblHtml += "</div>"
			tblHtml += "<div class='vidText' style='line-height:12px;'>"
				tblHtml += "<div id='vidTxtLim"+id+"'>"
					tblHtml += "<a href='javascript:playMyHot("+id+");' class='quickLnk'>"+items[1]+"</a>"
				tblHtml += "</div>"
				tblHtml += "<a href='javascript:removeItem_QL("+id+");' class='delLink'><img src='/images/hot/x.gif' style='border:0;'/></a> <a href='javascript:removeItem_QL("+id+");' class='delLink'>הסר</a>"
			tblHtml += "</div>"
		tblHtml += "</div>"

		divItem.innerHTML = tblHtml;

		// creating div seperator
		if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1) {
			var divSep = document.createElement("div");
		} else {
			var divSep = document.createElement("<div>");
		}
		divSep.id = 'sep'+id;
		divSep.className = 'seperator';
		
		this.vidList.appendChild(divItem);
		this.vidList.appendChild(divSep);
		this.adjustTextDiv('vidTxtLim'+id);
		this.pngFix();
	};

	this.pngFix=function() {
		var arVersion = navigator.appVersion.split("MSIE")
		var versionId = parseFloat(arVersion[1])

		if ((versionId >= 5.5) && (document.body.filters)) 
		{
		   for(var i=0; i<document.images.length; i++)
		   {
			  var img = document.images[i]
			  var imgName = img.src.toUpperCase()
			  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
			  {
				 var imgID = (img.id) ? "id='" + img.id + "' " : ""
				 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
				 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
				 var imgStyle = "display:inline-block;" + img.style.cssText 
				 if (img.align == "left") imgStyle = "float:left;" + imgStyle
				 if (img.align == "right") imgStyle = "float:right;" + imgStyle
				 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
				 var strNewHTML = "<span " + imgID + imgClass + imgTitle
				 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
				 + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
				 + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
				 img.outerHTML = strNewHTML
				 i = i-1
			  }
		   }
		}
	}
	
	this.adjustTextDiv=function(str) {		
		if (navigator.appName == 'Netscape') {
			maxHeight = 30;
			margin = "-3 0 -1 0"
		} else {
			maxHeight = 31;
			margin = "-3 0 -1 0"
		}
		
		var obj = document.getElementById(str);
		if (obj) {
			obj.style.height = Math.min(parseInt(obj.offsetHeight),maxHeight);
			obj.style.overflow = 'hidden';
			obj.style.margin = margin;
		}
	};
};

