/*
* 	List of postings UI component
*/

var PostingList = {
	
	nextPage : function(){
		Items.page ++;
		Explore.doload(true);
	},
	prevPage : function(){
		Items.page --;
		Explore.doload(true);
	},
	
	/*
	* 	Update list of postings 
	*	Does both list and image strip
	*/
	updatePostings: function(){
		if ((!UIConfig.image_bar_outer) && (!UIConfig.posting_list_container)) return;		

		var image_container = UIConfig.posting_images_container;
		var list_container = UIConfig.posting_list_container;
		
		var outArray = Items.items;
		
		var countI = 0;
		var countL = 0;
		var cdivI = document.createElement('div');
		var cdivL = document.createElement('ul');

		var iMax = Items.items.length;
		for (var i =0 ; i < iMax ; i++){
			var itm= Items.items[i];
			delete itm.dom_element;
			delete itm.dom_element2;
				
			if (itm.inBounds){ 
				if (itm.tmb_path != ''){
					var img = document.createElement('img');
					
					//img.setAttribute('onmouseover','alert('+itm.mIndex+');Markers.hoverOver('+itm.mIndex+');');
					//img.setAttribute('onmouseout','Markers.stopHoverOver('+itm.mIndex+');');
					//img.setAttribute('onclick','Explore.markerClicked('+itm.mIndex+'); return false;');
					img.src = itm.tmb_path;
					img.className = 'image-bar-tmb';
					
					img._ms_id = itm.mIndex;
					img.onclick = ImageBar.imageClicked;
					img.onmouseover = ImageBar.imageHover;
					img.onmouseout = ImageBar.imageUnHover;
				
					
					countI ++;
					//img = '<img onmouseover="Markers.hoverOver('+itm.mIndex+'); " onmouseout="Markers.stopHoverOver('+itm.mIndex+'); " onclick="Explore.markerClicked('+itm.mIndex+'); return false;" width="75" height="75" src="'+itm.tmb_path+'" class="myconB" title="'+itm.title+'" /> ';	
					//div.innerHTML = img;
					itm.dom_element = img;
					cdivI.appendChild(img);
				}

				//Get the class for this type of posting
				var cls = 'sp-misc';
				if (itm.type ==1) 
					cls = 'sp-city';
				else {
					cls = Markers.classes[itm.cat];
					if (itm.cat ==0) cls = 'sp-misc';
				}
				
				
				countL ++;
				var div = document.createElement('li');
				itm.dom_element2 = div;
				div.innerHTML = '<a href="#" class="'+cls+'" onmouseover="Markers.hoverOver('+itm.mIndex+'); " onmouseout="Markers.stopHoverOver('+itm.mIndex+'); " onclick="Explore.markerClicked('+itm.mIndex+'); return false;">&nbsp;'+stringSubstring(itm.title,28)+' ('+Math.min(5,itm.sumv).toFixed(1)+')</a>';
				cdivL.appendChild(div);
			}
		}
		
		/*
		*	Update the image bar
		*/	
		if (UIConfig.image_bar_outer != null) {
			image_container.innerHTML = '';
			image_container.appendChild(cdivI);
			image_container.style.width = (countI*81)+'px';
			ImageBar.constrainToViewport();
			ImageBar.scrollDone();
		}
		
		/*
		*	Update list
		*/
		if ($('more-postings')) $('more-postings').style.display = (iMax == 60) ? 'block' : 'none' ;
		
		if (UIConfig.posting_list_container != null) {
			if (iMax ==0){
				list_container.innerHTML = 'None';
			} else {
				list_container.innerHTML = '';
				list_container.appendChild(cdivL);
			}
		}
	}
	
};

