/**
* initial values for latest ads
*/
var last_offset = 0;
var last_limit = 7;

/**
* retrieves latest ads and calls function to display them
* if no more ads are available, 'shoe more' button will be disabled
*/
function getLatestAds()
{
	if (_page_id != 'start') return;

	jQuery.getJSON(_url + '?page=_xmlreq&xml=startpage&action=getLatestAds&offset=' + last_offset + '&limit=' + last_limit, function(data) {
		if(data.length > 0)
		{
			showStartObjects(data);
		}
		else
		{
			jQuery('#morestartobjects').html('');
		}
	});
}

/**
* displays ads retrieved by getLatestAds
*/
function showStartObjects(data)
{
	var sHtml = '';
	jQuery.each(data , function (key, value)
	{
		sHtml = sHtml +
		'<div class="objectteaser">' +
			'<a href="' + value.path + '">' +
			'<img src="' + _url + 'image.php?action=resize&amp;file=' + value.image_path + value.image_name + '&amp;x=120" alt="' + value.id + '" title="' + value.id + '" alt="" />' +
			'<p class="txt1col"><b>' + textLimit(value.title, 70, '') + '</b><br /><br />' + value.city + '<br />' + value.living_space + '<br />' + value.price + '</p>' +
			'</a>' +
		'</div>';
		last_offset++;
	})

	var sOldData = jQuery('#startobjects').html();
	jQuery('#startobjects').html(sOldData + sHtml);
}

/**
* hover on home searchform
*/
function homesearchMark(obj)
{
	var setclass = (jQuery(obj).attr('class') == 'selector') ? 'selector-active' : 'selector';
	jQuery(obj).attr('class', setclass);
}

/**
* selection of home searchform
*/
function homesearchSelect(obj, module)
{
	if (_page_id != 'start') return;

	jQuery('#search-living').hide();
	jQuery('#search-business').hide();
	jQuery('#search-abroad').hide();
	jQuery('.selector-active').attr('class', 'selector');
	jQuery('.selector').attr('onmouseover', "homesearchMark(this);");
	jQuery('.selector').attr('onmouseout', "homesearchMark(this);");
	jQuery('#search-' + module).show('soft');
	jQuery(obj).attr('onmouseover', '//');
	jQuery(obj).attr('onmouseout', '//');
	jQuery(obj).attr('class', 'selector-active');
}

/**
* rewriting of home searchform action on city or category select
*/
function homesearchWith(obid, abroad)
{
	jQuery('#' + obid).attr('action', _url + jQuery('#' + obid + '_p1').val() + '/' + jQuery('#' + obid + '_p2').val());
	jQuery('#' + obid).submit();
}

