﻿// JScript File
        var notPrev;
        var notNext;
        var ListControl;
        function ListingItems(col)
        {
            this.collection = col;
            this.numByPage = 3;
            this.currentPageIdx = 1;
            this.totalPages = (col.length/this.numByPage);
            this.currentPage = document.createElement("div");
            this.numVisible = 0;
        }
        
        function LoadPage()
        {
        
            if ( ListControl.currentPage.hasChildNodes() )
			{
				while ( ListControl.currentPage.childNodes.length >= 1 )
				{
					ListControl.currentPage.removeChild( ListControl.currentPage.firstChild ); 
    			} 
			}
			
			var idxInternal = (ListControl.currentPageIdx-1)*ListControl.numByPage;
			var idx = 0;
			ListControl.numVisible = 0;
			
            while(idxInternal < ListControl.collection.length && idx < ListControl.numByPage )
            {
                if( (ListControl.collection[idxInternal].item.style.visibility == "") || (ListControl.collection[idxInternal].item.style.visibility =="hidden"))
                {
                    ++idxInternal;
                }
                
                else
                {
                    ListControl.currentPage.appendChild(ListControl.collection[idxInternal].item);
                    ++ListControl.numVisible;
                    ++idx;
                    ++idxInternal;
                }
            }
            
            
            
            if(idxInternal == ListControl.collection.length)
            {
                nextLabel.className="PagDisable";
                nextLabel.removeAttribute("href");
                return;
            }
            
                
            while(idxInternal < ListControl.collection.length && idx < ListControl.numByPage )
            {
                if( (ListControl.collection[idxInternal].item.style.visibility != "") && (ListControl.collection[idxInternal].item.style.visibility !="hidden"))
                {
                    nextLabel.className="PagDisable";
                    nextLabel.removeAttribute("href");
                    return;
                }
                ++idxInternal;
                ++idx;
            }
        }
        
        function Prev(elemId, oldsrcImg, srcImg)
        {
            nextLabel.className = "handCursor";
            nextLabel.href=".";
            if(ListControl.totalPages > 1)
            {
                nextLabel.className = "handCursor";
                nextLabel.href=".";
            }
            if(ListControl.currentPageIdx <= 1)
            {   
                prevLabel.className="PagDisable";
                prevLabel.removeAttribute("href");
                return false;
            }
            
            --ListControl.currentPageIdx;
            
            var c = document.getElementById(elemId);
            for(var ci = 0; ci < c.childNodes.length; ++ci)
                c.childNodes[ci].src = oldsrcImg;
            c.childNodes[ListControl.currentPageIdx-1].src = srcImg;
            //alert(c.childNodes[ListControl.currentPageIdx]);
            LoadPage();
            if(ListControl.currentPageIdx <= 1)
            {   
                prevLabel.className="PagDisable";
                prevLabel.removeAttribute("href");
            }
            return false;
        }
        
        function Next(elemId, oldsrcImg, srcImg)
        {
            if(ListControl.currentPageIdx+1>1)
            {
                prevLabel.className = "handCursor";
                prevLabel.href=".";
            }
            if(ListControl.currentPageIdx >= ListControl.totalPages)
                return false;
            if(ListControl.currentPageIdx+1 >= ListControl.totalPages)
            {
                nextLabel.className="PagDisable";
                nextLabel.removeAttribute("href");
            }
            var idxInternal = (ListControl.currentPageIdx)*ListControl.numByPage;
			var idx = 0;
            while(idxInternal < ListControl.collection.length && idx < ListControl.numByPage )
            {
                if( (ListControl.collection[idxInternal].item.style.visibility == "") || (ListControl.collection[idxInternal].item.style.visibility =="hidden"))
                {
                    ++idxInternal;
                }
                else
                {
                    ++ListControl.currentPageIdx;
                    LoadPage();
                    var c = document.getElementById(elemId);
                    for(var ci = 0; ci < c.childNodes.length; ++ci)
                        c.childNodes[ci].src = oldsrcImg;
                    c.childNodes[ListControl.currentPageIdx-1].src = srcImg;
                    return false;
                }
            }
            
            
        }

/**
        function itemClick(item)
        {
            alert('inside click'+item);
        }
**/
       
		function createItem(title, subt, img, desc, entry, styleEntry, styleTitle, styleSubtitle, styleImg, styleDesc, contString, contStyle, outerLString, outerRString, link) 
		{
	
		//div outer
			var _item = document.createElement("div");
			_item.removeAttribute("class");
			_item.className=styleEntry;
           
			//div with img
            var _imgDiv =  document.createElement("div");
            _imgDiv.removeAttribute("class");
			_imgDiv.className=styleImg;
			
			this.imgDiv = _imgDiv;
            if(img.length >0)
            {
                var _imgLink = document.createElement("a");
                _imgLink.href = link;
			    var _img = document.createElement("img");
			    _img.setAttribute("src", img);
			    _img.removeAttribute("class");
			    _img.className=styleImg;
			    _imgDiv.style.width = _img.style.width;

			    //_imgDiv.appendChild(_img);
			    _imgLink.appendChild(_img);
			    _imgDiv.appendChild(_imgLink);
			    _img.style.borderStyle= "none";
			    
			
			}
			_item.appendChild(_imgDiv);
			
			//div with title
			var _header = document.createElement("div");
			var linkTitle =  document.createElement("a");
			linkTitle.href = link;
			linkTitle.appendChild(document.createTextNode(title));
			_header.appendChild(linkTitle);
			
			_header.removeAttribute("class");
			_header.className = styleTitle;
			_item.appendChild(_header);
			
			//div with subtitle
			var _subheader = document.createElement("div");
			_subheader.appendChild(document.createTextNode(subt));
			_subheader.removeAttribute("class");
			_subheader.className = styleSubtitle;
			_item.appendChild(_subheader);
			
			
			//div with desc with link
			var _body = document.createElement("div");
			
			var _bodyInner = document.createElement("div");
			
			_body.removeAttribute("class");
			_body.className=styleDesc;
			
			_bodyInner.removeAttribute("class");
			_bodyInner.style.height="38px";
			_bodyInner.style.bachkgroundColor="red";
			
            var _nameLink = document.createElement("a");
			_nameLink.innerHTML = desc;
			//_nameLink.appendChild(document.createTextNode(outerLString));
			
			_nameLink.href = link;
			//_name.appendChild(_nameLink);
			//_body.appendChild(_nameLink);

			
			var _left = document.createElement("span");
			_left.appendChild(document.createTextNode(outerLString));
			var _leftInside = document.createElement("span");
			_leftInside.appendChild(document.createTextNode(contString));
			_leftInside.className=contStyle;
			_left.appendChild(_leftInside);
			_left.appendChild(document.createTextNode(outerRString));
			
			_nameLink.appendChild(_left);
			
//			var _name = document.createElement("div");
//			var _nameLink = document.createElement("a");
//			_nameLink.appendChild(_left);
			
			_body.appendChild(_nameLink);
			_bodyInner.appendChild(_body);
			_item.appendChild(_bodyInner);
            _item.style.visibility = "visible";
            return _item;
		}
		
			
		function ItemShow(title, subt, img, desc, entry, styleEntry, styleTitle, styleSubtitle, styleImg, styleDesc, contString, contStyle, outerLString, outerRString, link){
			this.title = title;
			this.subtitle = subt;
			this.img = img;
			this.desc = desc;
			this.item = createItem(title, subt, img, desc, entry, styleEntry, styleTitle, styleSubtitle, styleImg, styleDesc, contString, contStyle, outerLString, outerRString, link) 
		}
        
		function LoadItems(){
		    
			var content = document.getElementById("contentDetails");
			if ( content.hasChildNodes() )
			{
				while ( content.childNodes.length >= 1 )
				{
					content.removeChild( content.firstChild );       
				} 
			}
			
			ListControl = new ListingItems(Items);
           
			LoadPage();
			
            prevLabel.className="PagDisable";
            prevLabel.removeAttribute("href");
            
            if(ListControl.totalPages <= 1)
            {
                nextLabel.className="PagDisable";
                nextLabel.removeAttribute("href");
            }
            
            content.appendChild(ListControl.currentPage);
			
		}


