function slideSwitch() {
    var active = $('#portal .bottomarea .teaserbox.left .teaser.active');
    if( active.length == 0 ) {
        active = $('#portal .bottomarea .teaserbox.left .teaser:last');
    }
    var next = active.next().length ? active.next() : $('#portal .bottomarea .teaserbox.left .teaser:first');
    active.addClass('lastActive');
    next.css({ opacity: 0.0 }).addClass('active').animate({ opacity: 1.0 }, 1000, function(){
        active.removeClass('active lastActive');
    });
}

// dom is loaded (incl. all scripts, images, css, ...)
$(window).ready(function(){
	try {

        if( $('#portal .bottomarea .teaserbox.left .teaser')[0] ){
            console.log( 'bin noch immer da!!!!' );
        }
        if( $('#portal .bottomarea .teaserbox.left .teaser')[1] ){
            $(function() {
                setInterval( 'slideSwitch()', 5000 );
            });
        }

		$(".gotolink").openlink();

		protouch.metaNavigation();
		protouch.portal();
		protouch.teamBox();
		protouch.storeLocator();
		protouch.productslider();
		protouch.relatedslider();
		protouch.categoryslider();
		protouch.categorymanager();
		protouch.trikotmanager();

		/**
		 * Additional Flash Videos
		 */
		if ((typeof (flashfiles) != "undefined") && flashfiles.length > 0) {
			$(flashfiles).each(function(i) {
				swfobject.embedSWF(this.swf, this.id, this.width, this.height, "9.0.0", "expressInstall.swf", {} , protouch.settings.flashparams, {});
			});
		}
		/**
		 * ColorBox
		 */
		if (typeof $.fn.colorbox == "function") {
			$("#content a[rel='imagebox']").colorbox({
				transition:"fade",
				slideshow:true,
				slideshowAuto: false,
				slideshowSpeed: 3000,
				current: "Bild {current} von {total}",
				previous: "vorheriges",
				next: "nächstes",
				close: "schließen",
				slideshowStart: "Starte Diashow",
				slideshowStop: "Beende Diashow"

			});

			if (protouchvars.other.jquerzoom != '') {
				$.colorbox({
					href : protouchvars.other.jquerzoom,
					opacity : 0.5
				});
			}

		}
		/**
		 * Image Zoomer
		 */
		if (typeof $.fn.jqzoom == "function") {
			$(function() {
				$(".jqzoom").jqzoom({
					zoomType: 'reverse',
					zoomWidth: 583,
					zoomHeight: 345,
					xOffset: 45,
					yOffset: 35,
					title: false
				});
			});
		}
		/**
		 * Starrating
		 */
		if ($('.userrating').length > 0) {
			$('.avg-wrapper').stars({
			  disabled: true
			});

			$('div.ratings').mouseenter(function(){
				$('div.rating-R').show();
			});

			$('div.ratings').mouseleave(function(){
				$('div.rating-R').hide();
			});
			$('.vote-wrapper').stars({
				cancelShow: false,
				oneVoteOnly: true,
				inputType: 'select',
				callback: function(ui, type, value){
					var objID = ui.$selec.attr('id').substring(6);
					if ($.cookie('vote_'+objID) == "true") {
						$('#message_'+objID).html("schon bewertet!");
					}
					else {
						var ajaxRequest = $.ajax({
							cache:false,
							data: 'obj='+objID+'&rating='+value,
							type:'POST',
							url:'/?controller=vote&action=vote',
							timeout:3000,
							success: function(data,textStatus ){
								var json = jQuery.parseJSON( data );
								if (ajaxRequest.status == 200 && textStatus == 'success' ){
									$('#score_'+objID).html( json.vote.score );
									$('#all_votes_'+objID).html( json.vote.votes );
									$('#all_avg_'+objID).html( json.vote.avg );
									var txt = $('#txt_'+objID).html();
									$('#message_'+objID).html("Danke!");
									$.cookie('vote_'+objID, true, {
										expires: 365,
										path: '/'
									});
								}
							}
						});
					}
				}
			});
			$('.userrating').addClass("active");
		}
		/**
		 * Adjust The Teaser Height
		 */
		if (($("#content").length > 0) && ($("#teaser_left").length > 0)) {
			var newheight = $("#content").height();
			if ($("#imagelayer").height() > 0) {
				newheight = newheight - 400;
			}
			else if ($("#catagorymanager").height() > 0) {
				newheight = newheight -  $("#catagorymanager").height() - 79; /* -20 in Old Form */
			}
			else if ($("#productimages").height() > 0) {
				newheight = newheight -  $("#productimages").height() - 20;
			}
			else if ($("#ideasimages").height() > 0) {
				newheight = newheight -  $("#ideasimages").height() - $("#ideasimages").height();
			}
			$("#teaser_left").height(newheight);

            var animateSujetPaging = setTimeout(function(){
                $('.bottomarea .teaserbox.left .teaser').each(function(i) {
                    var container = $(this);
                    setTimeout(function(){ container.animate({"left": "193px"}, {"duration": 400, "easein": "easeInCubic"}); }, 250*i);
                });
            }, 4000);
		}
	}
	catch (e) {
        console.log(e);
        						console.dir(e);
		$.ajax({
			url : "/?controller=error&action=js",
			data : e,
			type : 'GET',
			dataType : 'json',
			success : function(response) {
				if (response.logger == true) {
					try {
						console.log(e);
						console.dir(e);
					}
					catch (e) {}
				}
			}
		});

	}


    // ------------------------------------------ //
	// CONTENT GALLERY SLIDER:					  //
	// ------------------------------------------ //
	if($("#textarea .gallery .galleryslider").length > 0) {
		var itemWidth = 180;
		var maxItems = 2;
		if ($("#background_contentborders").hasClass("wide")) {
			maxItems = 3;
		}
		var currentId = 0;
		var sliders = $("#textarea .gallery .galleryslider");

		function slide (sliderContainer, targetId) {
			var newSliderPos = targetId * (itemWidth * -1);
			sliderContainer.stop().animate({left:newSliderPos + 'px'},{queue:false,duration:320});
			currentId = targetId;
		}

		sliders.each(function(i) {
			var slideLeft = $(".slideImgleft", $(this));
			var slideRight = $(".slideImgright", $(this));

			var sliderContainer = $(".imagecontainer", $(this));
			var images = $(".img_thumb", $(this));

			slideLeft.bind({
				click: function() {
					if(currentId > 0) {
						slide(sliderContainer, currentId-1);
					}
				}
			});
			slideRight.bind({
				click: function() {
                    if(currentId < images.length - maxItems) {
						slide(sliderContainer, currentId+1);
					}
				}
			});
		});
	}
});



