/*
*/
var $jQ = jQuery.noConflict();
var widgetPauseTimer;

function widgetClickAction(id){
	if(gBigOpenWindow){henworx.MapCms.BigWindow.hide();}
	listViewObj.setToMapView();
	_loc=gMapCms.findLocation(id, putMarker=true);
	if(typeof(_loc) != 'undefined')
		henworx.MapCms.MarkerEvent.mouseOver.onMouseOver(_loc, _loc.marker, gMapCms.map);
	return false;
}

function widgetOpenLocation(id){
	_loc=gMapCms.findLocation(id,  putMarker=true);
	if(typeof(_loc) != 'undefined')
		henworx.MapCms.MarkerEvent.mouseClick.onMouseClick(_loc, _loc.marker, gMapCms.map);
	return false;
}


/*
function widgetOverAction(id){

	if(widgetPauseTimer){
		window.clearTimeout(widgetPauseTimer);
	}
	_loc=gMapCms.findLocation(id);
	
	function widgetPauseAction(){
		 henworx.MapCms.Ewindow.hide('immediate'); //hide if old ewindow is open
		_ewindow = new henworx.MapCms.Ewindow(_loc, _loc.marker, gMapCms.map);
		
		if(typeof(gBigOpenWindow.location)!='undefined'){
			henworx.MapCms.BigWindow.hide();	
		}
		emblem=_loc.emblem.split("*");
		emblem=emblem[0];
		_ewindow.color = emblem;
		_ewindow.init();
		_ewindow.show();
	}
	if(typeof(_loc) != 'undefined')
		widgetPauseTimer=window.setTimeout(widgetPauseAction,800);
}*/
function widgetOverAction(id){
	if(gBigOpenWindow){return false;}
	if(widgetPauseTimer){
		window.clearTimeout(widgetPauseTimer);
	}
	_loc=gMapCms.findLocation(id, putMarker=true);
	MarkerEventPause.loc=_loc
	MarkerEventPause.marker=_loc.marker
	
	MarkerEventPause.map=gMapCms.map
	function widgetPauseAction(){
		 henworx.MapCms.Ewindow.hide('immediate'); //hide if old ewindow is open
		MarkerEventPause.onMousePause(true);
	}
	if(typeof(_loc) != 'undefined')
		widgetPauseTimer=window.setTimeout(widgetPauseAction,800);
}



function widgetOutAction(id){

	window.clearTimeout(widgetPauseTimer);
	
	_loc=gMapCms.findLocation(id);
	if(typeof(_loc) != 'undefined')
		henworx.MapCms.MarkerEvent.mouseOut.onMouseOut(_loc, _loc.marker, gMapCms.map);
}

function widgetOpenAction(id){
	window.clearTimeout(widgetPauseTimer);
	listViewObj.setToMapView();
	_loc=gMapCms.findLocation(id);
	henworx.MapCms.MarkerEvent.mouseClick.onMouseClick(_loc, _loc.marker, gMapCms.map);
	return false;
}

if(!henworx.MapCms.Widgets){
	henworx.MapCms.Widgets={}
}
henworx.MapCms.Widgets.Post=function(){
	this.limit=50;
	this.postsPerPage=10;
	this.pageNum=1;
	this.count = 0;
	this.url="";
	this.widgetId = "";
	this.params = '';
	_lang = henworx.MapCms.Lang;
	//this.objName = null;
	/*
	
	makes queystring
	*/
	this.queryString = function (){
		_queyString = '?';
		if(this.limit != ''){
			this.url = this.url+_queyString+'limit='+this.limit;
			_queyString = '&';
		}
		if(this.postsPerPage != ''){
			this.url = this.url+_queyString+'posts_per_page='+this.postsPerPage;
			_queyString = '&';
		}
		if(this.params != ''){
			this.url = this.url+_queyString+this.params;			
		}
	}
	/*
	gets data and writes into div
	*/
	this.getData=function(){		
		this.queryString();			
		$jQ("#"+this.divId).load(this.url);
	}
	//hideAll the data;
	this.hideData = function(){
		for(i=1; i<=this.count; i++){
			$jQ('#henworx_mapcms_widget_'+this.widgetId+'_data_'+i).hide();
		}
	}
	
	this.showData = function(){		
		_from = ((this.pageNum -1)*this.postsPerPage)+1;
		_to = this.pageNum*this.postsPerPage;	
		for(i=_from; i<=_to; i++){
			$jQ('#henworx_mapcms_widget_'+this.widgetId+'_data_'+i).show();
			$jQ('.henworx_mapcms_widget_'+this.widgetId+'_pagination .aligncenter').text(this.pageNum+_lang.getWord(' of ')+this.maxPage);
		}
	}
	
	
	
	//loadData for the first time
	this.loadData = function(){
		
		this.maxPage     = Math.ceil(this.count / this.postsPerPage);
		
		if(this.count > 0){
			this.showData();	
		}
	}
	
	this.refreshData = function(){
		this.hideData();
		this.showData();
	}
	
	//next click event
	this.nextClick = function(){
		 _lastPage = this.pageNum+1;
		 //alert(_lastPage+":"+this.maxPage);
		if(this.maxPage >= _lastPage){
			this.pageNum = _lastPage;
			this.refreshData();
		}
	};
	
	//previous click event
	this.previousClick = function(){
		_lastPage = this.pageNum-1;
		if(_lastPage>=1){
			this.pageNum = _lastPage;
			this.refreshData();
		}
	}
}



function widgetPaginationClick(url,divId){
	widgetData = new henworx.MapCms.Widgets.Post()
	widgetData.url= url;
	widgetData.postsPerPage='';
	widgetData.limit='';	
	widgetData.divId=divId;
	widgetData.getData();
}



