$(function () {
			
	$('ul.spy').simpleSpy();
	
});
(function ($) {
	$.fn.simpleSpy = function (limit, interval) {
		if($(this).length == 0) return;
		limit = limit || 2;
		interval = interval || 5500;
		var speed = 250;
		return this.each(function () {
			var $list = $(this),
				items = [],
				currentItem = limit,
				total = 0,
				lock = false,
				width = $list.find('> li:first').width(),
				height = $list.find('> li:first').height();
			$list.find('> li').each(function () {
				items.push('<li>' + $(this).html() + '</li>');
			});
			total = items.length;
			$list.wrap('<div class="spyWrapper" />').parent().css({ width:(width*limit+20) });
			var listCounter = $list.find('li').length;
			
			$('a.link_adslider').click().toggle(function () {
				//$('#adSlider').css({ height : (height * Math.round(total / 2)) });
				clickTracker('Adslider Anzeigen - Startseite');
				$(this).text('Schließen');
				clearTimeout(timer);
				lock = true;
				// remove all items
				$list.find('> li').each(function () {
					$(this).remove();
				});
				// add all items again
				var i = 0;
				function addItem() {
					$(items[i]).css({ 'float' : 'left', 'margin-bottom' : '5px' }).prependTo($list);
					i++;
					if(i < total) {
						setTimeout(addItem, 0);
					}
				}
				addItem();
			}, function () {
				$list.find('> li').css({ 'float' : 'right', 'margin-bottom' : '0px' });
				$(this).text('Alle Angebote auf einen Blick');
				lock = false;
				timer = setTimeout(spy, interval);
				
				if(listCounter > limit){
					$list.find('> li').filter(':gt(' + (limit - 1) + ')').remove();
				}
			});
			
			if(listCounter > limit){
				$list.find('> li').filter(':gt(' + (limit - 1) + ')').remove();
				function spy() {
					var $insert = $(items[currentItem]).css({
						width : 0,
						opacity : 0,
						display : 'none'
					}).prependTo($list);
					$list.find('> li:last').animate({ opacity : 0}, speed/2, function () {
						$insert.animate({ width : width }, speed).animate({ opacity : 1 }, speed/2);
						$(this).remove();
					});
					currentItem++;
					if (currentItem >= total) {
						currentItem = 0;
					}
					if(lock != true) {
						timer = setTimeout(spy, interval)
					}
				}
				spy();
			}
		});
	};
	
})(jQuery);
function adSliderHideObjects(trigger,idActivePopup,linkPopup) {
	var setSate = 'visible';
	var tsActiveObject = idActivePopup;
	if (trigger) {
		setSate = 'hidden';
	}
	var tsObject = document.getElementsByTagName('object');
	if (tsObject != null) {
		var apNum = tsObject.length;
		for (var i = 0; i < apNum; i++) {
			tsObject[i].style.visibility = setSate;
		}
		if (tsActiveObject.length > 0 && trigger) {
			document.getElementById(tsActiveObject).style.visibility = 'visible';
			$('div#adSlider').append('<iframe name=\'azframe'+idActivePopup+'\' id=\'azframe'+idActivePopup+'\' width=\'0\' height=\'0\' src=\''+linkPopup+'\' style=\'display:none;\'></iframe>');
		}
	}
	return(true);
}