
	var counter = 0;
	var current_headline = 0;
	var headline_count = images.length;
	var cw = 0;
	var ch = 0;

	function imageresize(aktimg) {

		iw = parseInt(aktimg.width());
		ih = parseInt(aktimg.height());

		if(iw && ih) {

			// WIDTH
			if((iw<cw && ih>ch) || (ih==ch && iw<cw) || ((ih>ch && iw>cw) && ((ih>=iw && ch<cw) || (ih>iw && ch>cw))) || ((ih<ch && iw<cw) && ((ih<=iw && ch>cw) || (ih<iw && ch<cw)))) {

				aktimg.css("width",cw);
				aktimg.css("height","auto");

				ih = parseInt(aktimg.height());
				aktimg.css("margin-top",-((ih-ch)/2));

			// HEIGTH
			} else if ((ih<ch && iw>cw) || (iw==cw && ih<ch) || ((ih>ch && iw>cw) && ((ih<=iw && ch>cw) || (ih<iw && ch<cw))) || ((ih<ch && iw<cw) && ((ih>=iw && ch<cw) || (ih>iw && ch>cw)))) {

				aktimg.css("height",ch)
				aktimg.css("width","auto");

				iw = parseInt(aktimg.width());
				aktimg.css("margin-left",-((iw-cw)/2));
			}
		}

	}

	function headline_rotate(rot_num) {

		clearTimeout(waitper);

		$jquery("div.ad:eq(" + current_headline + ")").animate({left: (-1 * parseInt($jquery('.sliderCont').width()))},"slow", function() {
			
			$jquery(this).css('left', $jquery('.sliderCont').width());
			if( $jquery(this).find("object").length ) {
				id=($jquery(this).find("object").attr("id"));
				eval("document."+id+".GotoFrame(0)");
			}
		});
		
		$jquery("div.ad:eq(" + rot_num + ")").animate({left: 0},"slow", function() {
			
			if( $jquery(this).find("object").length ) {

				id=($jquery(this).find("object").attr("id"));
				eval("document."+id+".Play()");
			
			} else {

				waitper = setTimeout(playnext,4000);
			
			}
		}); 

		$jquery("div.ad_numbering a:eq(" + current_headline + ")").css("cursor", "pointer");
		$jquery("div.ad_numbering a:eq(" + current_headline + ")").removeClass("selected");

		$jquery("div.ad_numbering a:eq(" + rot_num + ")").css("cursor", "default");
		$jquery("div.ad_numbering a:eq(" + rot_num + ")").addClass("selected");

		current_headline = rot_num;
	}

	function playnext() {
		if((current_headline+1) == headline_count)
			headline_rotate(0);
		else
			headline_rotate(current_headline+1);
	}

	function loadimage() {

		if(counter<images.length) {

			$jquery.get('/php/slideshow_ajax.php', { "image": images[counter] }, function(data) {
				$jquery('.ad_cont').append(data);
				$jquery('.ad_cont .ad:eq('+counter+') img').load(function(){

					$jquery('.ad_cont .ad:eq('+counter+')').css("left",cw);
					$jquery('.ad_cont .ad:eq('+counter+')').css("width",cw);

					imageresize($jquery('.ad_cont .ad:eq('+counter+') img'));
					
					if(counter==0) {
						$jquery("div.ad_numbering").append('<a class="selected" onclick="headline_rotate('+counter+')">'+(counter+1)+'</a>')
						$jquery('.ad_cont .ad:eq('+counter+')').css('left', 0);
					} else {
						$jquery("div.ad_numbering").append('<a style="cursor: pointer" onclick="headline_rotate('+counter+')">'+(counter+1)+'</a>')
					}

					counter++;

					loadimage();

				});

			});

		} else {

			$jquery(".ad_numbering").css("margin-top",(parseInt($jquery(".sliderCont").height())-parseInt($jquery(".ad_numbering").height()))-10);
			waitper = setTimeout(playnext,4000);

		}

	}


	$jquery(window).load(function(){

		cw = parseInt($jquery('.sliderCont').width());
		ch = parseInt($jquery('.sliderCont').height());

		loadimage();

	});
