var g_allRssFeedMaxDisplay=4;
var g_allRssFeedMinDisplay=2;
var g_yelpResultsMaxDisplay=parseInt("2");
var g_sUrl='http://'+window.location.host+'/ajax-call/';
var g_map =null;
function setListContainerHeight(listItemClass, listParentId, tagName, maxDisplay ){
	var displayedItems=[];
	var feedHeight=parseInt("0");
	var listItems = YAHOO.util.Dom.getElementsByClassName(listItemClass, tagName,listParentId);
	var listParent=YAHOO.util.Dom.get(listParentId);
	maxDisplay=parseInt(maxDisplay);
	
	for(var i=0;i<listItems.length;i++){
		if(YAHOO.util.Dom.get(listItems[i])==null){
			continue;
		}
		if(displayedItems.length<maxDisplay){
			//show if #displayedItems is less than maxDisplay
			listItems[i].style.display='block';
			displayedItems.push(listItems[i]);
			feedHeight=feedHeight+listItems[i].offsetHeight;
		 }else{
			 //show this list item.but dont add to feedHeight
			 listItems[i].style.display='block';
		 }
	} ///loop
	if(listParent!=null){
	//	alert('feedHeight'+feedHeight);
		YAHOO.util.Dom.setStyle(listParentId,"height", feedHeight + 'px');
		
		/*
		YAHOO.util.Dom.setStyle(listParentId,"overflow-y","scroll");
		YAHOO.util.Dom.setStyle(listParentId,"overflow-x","hidden");
		//get Scrollbar width
		var scrollBarWidth=listParent.offsetWidth-listParent.clientWidth;
		//add scrollBarWidth to height.
		feedHeight=feedHeight+scrollBarWidth;
		YAHOO.util.Dom.setStyle(listParentId,"height", feedHeight + 'px');
		YAHOO.util.Dom.setStyle(listParentId,"overflow-y","scroll");
		YAHOO.util.Dom.setStyle(listParentId,"overflow-x","hidden");
		*/
	}
	
}

function collapseContainerHeight(listItemClass, listParentId, tagName,minDisplay  ) {
	var listItems = YAHOO.util.Dom.getElementsByClassName(listItemClass, tagName,listParentId);
	var listParent=YAHOO.util.Dom.get(listParentId);
	var displayedItems=[];
	var feedHeight=parseInt("0");
	var minDisplay=parseInt(minDisplay);
	for(var i=0;i<listItems.length;i++){
		if(YAHOO.util.Dom.get(listItems[i])==null){
			continue;
		}
		if(displayedItems.length<minDisplay){
			listItems[i].style.display='block';
			displayedItems.push(listItems[i]);
			feedHeight=feedHeight+listItems[i].offsetHeight;
		} else {
			listItems[i].style.display='none';
		}
	}	
	YAHOO.util.Dom.setStyle(listParentId,"height", feedHeight + 'px');
	YAHOO.util.Dom.setStyle(listParentId,"overflow-y","hidden");
	YAHOO.util.Dom.setStyle(listParentId,"overflow-x","hidden");
	
	
}

function ajaxIndicator(){
//isCallInProgress will return true if the transaction has not been completed.
	try{	
		var e=window.event;
		var process=arguments[0];
		var spinnerElem=YAHOO.util.Dom.get('spinnerBox');
		//var eventSrc= YAHOO.util.Event.getTarget(e);
		var eventSrc=arguments[1];
		//alert(' ajax indicator.. event src'+eventSrc.id);
		var callStatus = YAHOO.util.Connect.isCallInProgress(process);
		if(callStatus){ 
			showSpinnerDialog(eventSrc);
		}
		else{
			hideSpinnerDialog();
		}

	}catch(e){
		// alert(e.message);
		}
	
	
	
} //func

function showFlickrDetails(obj,title, author){
	//alert('a '+author+' t'+title+" obj"+ obj.id);
	//YAHOO.util.Dom.get('photoAuthor').innerHTML=unescape(author); //imageItem['author'];
	YAHOO.util.Dom.get('photoTitle').innerHTML= unescape(title); //imageItem['title'];
	//put white border
	YAHOO.util.Dom.setStyle(obj,"border-width","3px");
	YAHOO.util.Dom.setStyle(obj,"border-color","white");
	YAHOO.util.Dom.setStyle(obj,"border-style","solid");

}

function hideFlickrDetails(obj){
	YAHOO.util.Dom.setStyle(obj,"border-width","0px");

	YAHOO.util.Dom.get('photoAuthor').innerHTML="";
	YAHOO.util.Dom.get('photoTitle').innerHTML="";

}
function loadGoogleMap(merchants, mapId) {	
if(merchants == null|| merchants.length==0){
	//	alert('loadGoogleMap merchants null');
		return;
	}
	var map = new google.maps.Map2(document.getElementById(mapId));
	if(map==null){
	//alert('map canvas is null');
	return;
	}
	map.addControl(new GSmallMapControl());
	//alert('lat'+eventItem.merchants[0].latitude+' lngt'+eventItem.merchants[0].longitude);
	//15 max zoom. lower for zooming out for broader look
	map.setCenter(new GLatLng(merchants[0].latitude, merchants[0].longitude), 13);
	
	// Set up our GMarkerOptions object for mouse over event
	for(var i=0;i  < merchants.length;i++){
	 	var point = new GLatLng(merchants[i].latitude, merchants[i].longitude );
        var my_marker_options = {clickable:false, draggable:false};

	 	var seqno=parseInt(i)+1;
		 map.addOverlay(new  GMarker(point,my_marker_options ));
	 }
}



function omnitureObject(key, suffix) {
	this.key=key;
	this.suffix=suffix;
}
		
function attachMouseUpEventToSet(maxIndex, id){
	   for(var j=0;j< maxIndex;j++){
		 	var alink=YAHOO.util.Dom.get( id+j);
		 	var omnObject= new omnitureObject(id, "");
		 	if( alink !=null){
		 			if(alink.getAttribute('omnId')!= null){
		 				omnObject.key = alink.getAttribute('omnId')+ omnObject.key;
		 			}
		 			
		 		YAHOO.util.Event.addListener(alink.id, "mouseup",doOmniture, omnObject);
		 		
		 	} 
		 	
	   }	
}

function attachMouseUpEvent(ids){
	if(isArray(ids)){
		for(var i=0; i<ids.length;i++){
		 	var alink=YAHOO.util.Dom.get( ids[i]);
		 	var omnObject= new omnitureObject(ids[i], "");
		 	//console.debug(" id form array"+ids[i]+" alink for mouse up?"+alink.id);
		 	if( alink !=null){
		 		
		 		if(alink.getAttribute('omnId')!= null){
	 				omnObject.key = alink.getAttribute('omnId')+ omnObject.key;
	 			}
		 		YAHOO.util.Event.addListener(ids[i], "mouseup",doOmniture, omnObject);
		 		
		 	} 
         }
	}else{
			var alink=YAHOO.util.Dom.get( id);
			if( alink !=null){
				var omnObject= new omnitureObject(id, "");
				YAHOO.util.Event.addListener(id, "mouseup",doOmniture, omnObject);
		 	}
		}

}
function doOmniture(e, omnObj){
	//alert(" in doOmniture() target id:"+ this.id+",   omn Obj key"+ omnObj.key+" suffix"+ omnObj.suffix);
	 var lkupKey=omnObj.key;

	 if(omnObj.suffix == null ||  omnObj.suffix == "")
		 omn_rmaction( OmnitureMap['siteIdenifier'],OmnitureMap[lkupKey]);
	 else
		 omn_rmaction( OmnitureMap['siteIdenifier'],OmnitureMap[lkupKey]+ omnObj.suffix);
		
	}
	
function doRollOverForImages(){
	for(var i=0; i<arguments.length;i++){
			var alink = YAHOO.util.Dom.get( arguments[i] );
			//console.debug('doRollOverForImages'+arguments[i]+"\n" );
			YAHOO.util.Event.addListener(alink, "mouseover", linkHighLighterOver);
			YAHOO.util.Event.addListener(alink, "mouseout", linkHighLighterOut);
	}
	}
	
function 	linkHighLighterOver(e, obj){
//	console.debug('linkHighLighterOver'+this.id);
   var img=	this.getElementsByTagName("IMG");
   if(img!=null){
   	img=img[0];
   //	console.debug(this.id+" new src"+img.getAttribute("overSRC"));
   	img.src=img.getAttribute("overSRC");
   }
   
}

function 	linkHighLighterOut(e, obj){
   var img=	this.getElementsByTagName("IMG");
   if(img!=null){
   	img=img[0];
   	if(img != null){
   		img.src=img.getAttribute('outSRC');
   	}
   }
   
}

function popupCloseHandler(e){
	try{
		var elTarget = YAHOO.util.Event.getTarget(e);
	//	if( elTarget!=null && elTarget.id !=null) alert('elTarget id'+ elTarget.id);
		 var calDisp=YAHOO.util.Dom.getStyle('calendarDiv','display');
		 var yelpDisp=yelpDetailsDialog.cfg.getProperty('visible');
		 var eventCalendar=YAHOO.util.Dom.get('eventCalendar');
	 	//alert('cal visible'+calDisp+' yelp visible'+ yelpDisp);
		 var hideCal=true;
		 if(calDisp=='block'){
	 		while(elTarget != null ){
	 			//alert('elTarget.is'+ elTarget.id);
	 			if(elTarget==YAHOO.util.Dom.get('eventCalendar') ||elTarget==YAHOO.util.Dom.get('calendarDiv') || elTarget==YAHOO.util.Dom.get('calendarButton')){
				//alert('elTarget is eventCalendar');
				hideCal=false;
				break;
				}
				elTarget = elTarget.parentNode;
				
			}
			//alert('hide cal'+hideCal);
		 	if(hideCal){
		 		//alert('hide cal now');
		 	YAHOO.util.Dom.setStyle('calendarDiv','display','none');
		 	}
		}
		
		// do the same for yelp overlay
		 var hideYelp=true;
		 if(yelpDisp){
	 		while(elTarget != null ){
	 			//alert('elTarget.is'+ elTarget.id);
	 			if(elTarget==YAHOO.util.Dom.get('dYelpDetails') ||elTarget==YAHOO.util.Dom.get('eventItemList')|| elTarget==YAHOO.util.Dom.get('allEventItemList') ){
				//alert('elTarget is eventCalendar');
				hideYelp=false;
				break;
				}
				elTarget = elTarget.parentNode;
				
			}
			//alert('hide cal'+hideCal);
		 	if(hideYelp){
		 		//alert('hide cal now');
		 		hideYelpOverlay();
		 	}
	}
	} catch(e){
		// alert('popupCloseHandler error '+e.message);
		}
		

}
function setBuzzLogicState(){
	if( g_state =='postshow') {
		// expand feeds
		if(BLDMB!=null){
			BLDMB.collapsed = true;
			BLDMB.toggle();
		}	
		//hide control
		var control =YAHOO.util.Dom.get('bzCollapse');
		if(control!=null) {
			YAHOO.util.Dom.setStyle('bzCollapse','display','none');
		}
		control =YAHOO.util.Dom.get('bzExpand');
		if(control!=null) 
			YAHOO.util.Dom.setStyle('bzExpand','display','none');
	}

}
