// File for coverflows

(function($) {




	


	$(document).ready(function() {







		$(window).load(function () {

//  			alert("window is so loaded! and now we can initialize the teaser with real pic sizes .. thanks hmmh delivering teaser that only work in reload--->");

			
			$('.coverflowAktuellTeaser .coverflowPanel').coverflow({

				leftItemCount: 3,

				rightItemCount: 3,

				initialIndex: 0,

				imgSelector: '.cover',

				onInit: function(coverflow) {

					$('.infoContainer',coverflow.elem).each(function() {

						$(coverflow.elem).append($(this).clone());

						$(this).remove();

					});

					$('.detailContainer',coverflow.elem).each(function() {

						$(coverflow.elem).append($(this).clone());

						$(this).remove();

					});

					$('.special',coverflow.elem).each(function() {

						$(coverflow.elem).append($(this).clone());

						$(this).remove();

					});

					$('.navigationContainer .middle a',$(coverflow.elem).closest('.teaserContainer')).each(function(i,e) {

						$(this).click(function(e) {

							coverflow.itemClicked(i);

							return false;

						});

					});

					$('.navigationContainer .rotateLeft',$(coverflow.elem).closest('.teaserContainer')).click(function(e) {

						coverflow.stepRight();

						return false;

					});

					$('.navigationContainer .rotateRight',$(coverflow.elem).closest('.teaserContainer')).click(function(e) {

						coverflow.stepLeft();

						return false;

					});

					$('.hoverButton',coverflow.elem).hoverbutton();

					$('a.detail',coverflow.elem).each(function(i,e) {

						$(this).click(function() {

							$($('.detailContainer',coverflow.elem).get(i)).show();

							return false;

						});

					});

					$('.detailClose',coverflow.elem).each(function(i,e) {

						$(this).click(function() {

							$($('.detailContainer',coverflow.elem).get(i)).hide();

							return false;

						});

					});

					$("a.preview",coverflow.elem).colorbox({

						onOpen: function() {

							$('#colorbox').addClass('coverflowAktuellCbox');

						},

						onComplete: function() {

							$('#colorbox .hoverButton').hoverbutton();



							updateNavigation = function(index) {

								$('#colorbox .middle a').removeClass('active');

								$('#colorbox .middle a img').each(function() {

									var src = $(this).attr('src').replace('_active','_inactive');

									$(this).attr('src',src);

								});



								var link = $('#colorbox .middle a').get(index);

				    			var src = $('img',link).attr('src').replace('_inactive','_active');

				    			$('img',link).attr('src',src);

								$(link).addClass('active');

							};

							$('#colorbox .rotateLeft').click(function() {

								var index = $('#colorbox .content li.active').prevAll().length;

								if (index > 0) {

									$('#colorbox .content li.active').removeClass('active');

									$($('#colorbox .content li').get(index-1)).addClass('active');

									updateNavigation(index-1);

								}

								return false;

							});

							$('#colorbox .rotateRight').click(function() {

								var index = $('#colorbox .content li.active').prevAll().length;

								var nexts = $('#colorbox .content li.active').nextAll().length;

								if (nexts > 0) {

									$('#colorbox .content li.active').removeClass('active');

									$($('#colorbox .content li').get(index+1)).addClass('active');

									updateNavigation(index+1);

								}

								return false;

							});

							$('#colorbox .middle a').click(function() {

								var index = $(this).parent().prevAll().length;

								$('#colorbox .content li.active').removeClass('active');

								$($('#colorbox .content li').get(index)).addClass('active');

								updateNavigation(index);

								return false;

							});

							//var height = $('.coverflowAktuellTeaserPreviewContainer').outerHeight();

							//var width = $('.coverflowAktuellTeaserPreviewContainer').outerWidth();

							//$.colorbox.resize({innerHeight: height+"px",innerWidth: width+"px"});
							$.colorbox.resize();

						},

						onClosed: function() {

							$('#colorbox').removeClass('coverflowAktuellCbox');

						},

						opacity: 0.5



					});

					// f�r IE

					//$('#cboxClose, #cboxTitle').addClass('png');

					//$("#cboxTopLeft, #cboxTopCenter, #cboxTopRight, #cboxBottomLeft, #cboxBottomCenter, #cboxBottomRight").html('<!---->').addClass('png');

				},

				onCalculate: function(offset,style) {

					if (offset > 0) {

						style.left = style.left + 100;

					}

					if (offset < 0) {

						style.left = style.left - 100;

					}

					return style;

				},

				onItemSelected: function(index,coverflow) {

					var item = coverflow.getItem(index);

					var src = $('img',item).attr('src');

					$('.imageContainer',coverflow.elem).html('<img src="'+src+'" />');

					$('.infoContainer',coverflow.elem).hide();

					$($('.infoContainer',coverflow.elem).get(index)).show();



					$($('.special',coverflow.elem).get(index)).show();



					var activatedLink = $('.middle a',$(coverflow.elem).closest('.teaserContainer')).get(index);

	    			var newSrc = $('img',activatedLink).attr('src').replace('inactive','active');

	    			$('img',activatedLink).attr('src',newSrc);

					$(activatedLink).addClass('active');

				},

				onAnimationStart: function(coverflow) {

					$('.special',coverflow.elem).hide();

					$('.detailContainer',coverflow.elem).hide();

					$('.middle img',$(coverflow.elem).closest('.teaserContainer')).each(function(i,e) {

						$(e).attr('src','/_art/img/teaser/rotator/icon_inactive_element.png');

					});

					$('.navigation li',$(coverflow.elem).closest('.teaserContainer')).removeClass('active');

				}

			});	
			

  		$('.coverflowH31Teaser .coverflowPanel').coverflow({

			leftItemCount: 0,

			isInfinite: true,

			onInit: function(coverflow) {

				$('.infoContainer',coverflow.elem).each(function() {

					$(coverflow.elem).append($(this).clone());

					$(this).remove();

				});

			},

			onItemSelected: function(index,coverflow) {

				var item = coverflow.getItem(index);

				$('.infoContainer',coverflow.elem).hide();

				$($('.infoContainer',coverflow.elem).get(index)).show();

			}

		});





		var id = 1;

		$('.coverflowH32Teaser .coverflowPanel').coverflow({

			leftItemCount: 4,

			rightItemCount: 4,

			initialIndex: 4,

			onPrepare: function(coverflow) {

				$('li',coverflow.elem).each(function() {

					var idAttr = 'coverflowH32Teaser-hovertip-'+(id++);

					$('.infoContainer',this).attr('id',idAttr);

					$('.infoContainer',this).hide();

					$('img',this).attr('rel',idAttr);

				});

			},

			onInit: function(coverflow) {

				$('.middle a',coverflow.elem).each(function(i,e) {

					$(this).click(function(e) {

						coverflow.itemClicked(i);

						return false;

					});

				});

				$('.rotateLeft',coverflow.elem).click(function(e) {

					coverflow.stepRight();

					return false;

				});

				$('.rotateRight',coverflow.elem).click(function(e) {

					coverflow.stepLeft();

					return false;

				});

			},

			onItemDeselected: function(index,coverflow) {

				var item = coverflow.getItem(index);

				$('img',item).unhovertip();

			},

			onItemSelected: function(index,coverflow) {

				var item = coverflow.getItem(index);

				var activatedLink = $('.middle a',coverflow.elem).get(index);

    			var newSrc = $('img',activatedLink).attr('src').replace('inactive','active');

    			$('img',activatedLink).attr('src',newSrc);

				$(activatedLink).addClass('active');

				$('img',item).hovertip({

					useRel: true,

					position: {

						my: 'right top',

						at: 'left top',

						offset: '-15px 0'

					}

				});

			},

			onAnimationStart: function(coverflow) {

				$('.middle img',coverflow.elem).each(function(i,e) {

					$(e).attr('src','/_art/img/teaser/rotator/icon_inactive_element.png');

				});

				$('.navigation li',coverflow.elem).removeClass('active');

			}

		});





		// end window load

	});







		$('.coverflowHV2Teaser .coverflowPanel').coverflow({

			leftItemCount: 1,

			rightItemCount: 1,

			initialIndex: 1,

			isInfinite: true,

			imgSelector: '.cover',

			onAnimationStart: function(coverflow) {

				$('.special',coverflow.elem).hide();

			},

			onItemSelected: function(index,coverflow) {

				var item = coverflow.getItem(index);

				var left = ($('.special',item).width()/2)*-1+11;

				var top = ($('.special',item).height()/2)*-1+23;

				$('.special',item).css({

					'left': left,

					'top': top,

					'z-index': 32000

				}).show();

				$('img:not(.special)',item).hovertip({

					additionalStyles: 'coverflowHV2TeaserTooltip',

					position: {

						my: 'top center',

						at: 'bottom center',

						offset: '0 -25px'

					}

				});

			},

			onItemDeselected: function(index,coverflow) {

				var item = coverflow.getItem(index);

				$('img:not(.special)',item).unhovertip();

			}

		});



		



	});



})(jQuery);
