var clickSoundsFlashObj;

$(document).ready(function() {

	$('#fe_menu_wrapper div.level2 a.linklevel2').hover(function() {
			$(this).stop().animate({
				'color': '#FFFFFF'
			}, 100);
		}, function() {
			$(this).stop().animate({
				'color': '#7bbc53'
			}, 1500);
		}
	);


	$('.level3').css({
		'opacity': '0.7'
	});

	$('#fe_menu_wrapper div.level2').hover(function() {
		$(this).stop().animate({
			'height': '250px'
		}, 1000, 'linear');
	}, function() {
		$(this).stop().animate({
			'height': '20px'
		}, 1000, 'linear');
	});

	$('.teaser_title a img').css({
		'opacity': 0.7
	});


	$('.teaser_title a img').hover(function() {
			$(this).stop().animate({
				'opacity': 1
			}, 250);
		}, function() {
			$(this).stop().animate({
				'opacity': 0.7
			}, 300);
		}
	);

	/* Content selectors BEG
	$('.content_selector_overlay').css({
//		'opacity': 0,
//		'display': 'block'
	});

	var content_selectors_timer = new Array();

	$('#content_selector_holder').children().each(function() {
		var i = $(this).attr('id').replace(/content_selector_/, '');

		$(this).hover(function() {
			if (!$(this).hasClass('content_selector_selected')) {
//				clickSoundsFlashObj.playSound('clickSound4');

				$(this).addClass('content_selector_hover');

				var $this = this;
				content_selectors_timer[i] = setTimeout(function() {
					$($this).find('.content_selector_overlay').animate({
//						'opacity': 1
					}).css('display','block');
				}, 750);
			}
		}, function() {
			if (!$(this).hasClass('content_selector_selected')) {
				$(this).removeClass('content_selector_hover');

				clearTimeout(content_selectors_timer[i]);
				$(this).find('.content_selector_overlay').animate({
//					'opacity': 0
				}).css('display','none');
			}
		}).click(function() {
			$('.content_selector_selected').removeClass('content_selector_selected');
			$(this)
				.css('backgroundPosition', (($(this).width() * (i - 1)) * -1) + 'px -304px')
				.addClass('content_selector_selected')
			;
		});
	});*/
	/* Content selectors END */

	/* Sitemap slider BEG */
	$('#sitemap_toggler').click(function() {
		if ($('#fe_inner_subfoot').css('display') == 'none') {
			$('#fe_inner_subfoot').css({
				'display': 'block'
			});
			$('#fe_subfoot').animate({
				'height': '100%'
			}, false, false, function () {
				$('#fe_inner_subfoot').animate({
					'opacity': '1'
				});
			});
		} else {
			$('#fe_inner_subfoot').animate({
				'opacity': '0'
			}, false, false, function () {
				$('#fe_subfoot').animate({
					'height': '0px'
				});
				$('#fe_inner_subfoot').css({
					'display': 'none'
				});
			});
		}
	});
	/* Sitemap slider END */


	/* Top menu BEG */
	$('#menu_layer').animate({
		'left': ($('#fe_top_menue li.level2 a.activated').offset().left - $('#fe_top_menue').offset().left) + 'px',
		'width': '0px'
	});
	$('#fe_top_menue li.level2 a').mouseover(function() {
		$('#menu_layer').animate({
			'left': ($(this).offset().left - $('#fe_top_menue').offset().left) + 'px',
			'width': '94px'
		});
	});
	$('#fe_topliner').mouseleave(function() {
		$('#menu_layer').animate({
			'left': ($('#fe_top_menue li.level2 a.activated').offset().left - $('#fe_top_menue').offset().left) + 'px',
			'width': '0px'
		});
	});
	/* Top menu END */


	/* Doc menu BEG */
	$('.docmenu_itemov').hover(function() {
//		clickSoundsFlashObj.playSound('clickSound5');
		$(this).css('width', '140px');
		$('+div', this).animate({
			'left': '-10px'
		}, 450, 'swing');
	}, function() {
		$(this).css('width', '40px');
		$('+div', this).animate({
			'left': '-110px'
		}, 1000, 'easeOutElastic');
//		clickSoundsFlashObj.playSound('clickSound2');
	});

	$('#legal_docbar_trigger').click(function() {
		window.location.href = '/Impressum/';
	});
	$('#remote_docbar_trigger').click(function() {
		window.location.href = '/Fernzugriff/';
	});
	$('#newsletter_docbar_trigger').click(function() {
		window.location.href = '/Newsletter/';
	});
	/* Doc menu END */




	/* Sub menu BEG */
	$('.sub_menu_itemCl').hover(function() {
//		clickSoundsFlashObj.playSound('clickSound4');
		$(this).toggleClass('sub_menu_itemCl_hover');
	}, function() {
		$(this).toggleClass('sub_menu_itemCl_hover');
	}).click(function(e) {
//		window.location.href = $(this).find('a').attr('href');
	});


	var lastSubMenuItem = false;

	$('.sub_menu_item_container.ajaxBased .sub_menu_itemCl').unbind('click');
	$('.sub_menu_item_container.ajaxBased .sub_menu_itemCl').click(function(event) {
		event.preventDefault();

		$('.sub_menu_item_active').removeClass('sub_menu_item_active').addClass('sub_menu_item');

		if (lastSubMenuItem) {
			$(lastSubMenuItem).trigger('dblclick');
		}

		$this = this;

		var originalPositions = $('.sub_menu_text_div a', $this).offset();

		var titleClone = $('.sub_menu_text_div a', $this)
			.clone()
			.css({
				'position': 'absolute',
				'top': originalPositions.top + 'px',
				'left': originalPositions.left + 'px'
			})
			.appendTo('body')
			.addClass('frontend_title')
			.animate({
				'left': $('#fe_content').offset().left + 'px',
				'top': $('#fe_content').offset().top + 'px'
			})
			.click(function(event) {
				event.preventDefault();
			})
			.dblclick(function(event) {
				event.preventDefault();

				$('.sub_menu_text_div', $this).animate({
					'opacity': 1
				});

				var originalTitle = $('.sub_menu_text_div a', $this);

				var currentOriginalPosition = $(originalTitle).offset();

				$(titleClone).animate({
					'left': originalPositions.left + 'px',
					'top': currentOriginalPosition.top + 'px'
				}, 500, false, function() {
					$(titleClone).empty().remove();
				});
			})
		;


		$('.sub_menu_text_div', $this).animate({
			'opacity': 0.3
		});
		$($this).addClass('sub_menu_item_active');

		lastSubMenuItem = titleClone;

		$.get('/FAjaxContent' + $('.sub_menu_text_div a', $this).attr('href'), {}, function(data) {
			$('#fe_content').animate({
				'opacity': 0
			}, 500, false, function() {
				$(this).html(data).animate({
					'opacity': 1
				});
			});
		});
	});

	/* Sub menu END */


	/* Home overlay BEG */
	$('#logo_hover').css({
		'opacity': 0,
		'display': 'block'
	});

	$('#logo').hover(function() {
		$('#logo_hover').animate({
			'opacity': 1
		});
	}, function() {
		$('#logo_hover').animate({
			'opacity': 0
		});
	});
	/* Home overlay END */




	/* Draggable logo BEG */
	$('#logo').draggable({
		appendTo: 'body',
		containment: 'body',
		helper: 'original',
		zIndex: 9999,
		stop: function() {
			$(this).animate({
				'top': '43px',
				'left': '39px'
			}, 1000, 'easeOutElastic');
		}
	});
	/* Draggable logo END */


	/* Recommendation BEG */
	$("#fe_recommend").click(function () {
		$("#recommendation_container").animate({
			'top': '-420px',
			'height' : '380px'
		}, 700);
	});

	$("#hide_recommendation").click(function () {
		$("#recommendation_container").animate({
			'top': '0px',
			'height' : '0px'
		}, 700);
	});

	var recommendation_message = '';
	$('#recommendation_message').keyup(function(ekey) {
		$('#recommendation_msg_count').text(100 - $(this).val().length);
		if (recommendation_message.length >= 100 && ekey.which != 8 && ekey.which != 46) {
			$(this).val(recommendation_message);
		} else {
			recommendation_message = $(this).val();
		}
	});


	$("#send_recommendation").click(function () {
		$('<input>')
			.css('display', 'none')
			.attr({
				name: 'recommendation_sent',
				value: 'sent_true'
			})
			.appendTo('#form_recommendation')
		;

		$('#form_recommendation').attr({
			'method': 'post'
		}).submit();
	});
	/* Recommendation END */

	$('.sub_menu_text_div a').click(function(e) {
		e.preventDefault();
		$('.subMenuL4Cont').animate({
			'height': '55px'
		});
	});

	$('.sub_sub_menu_text_div').click(function(e) {
		e.stopPropagation();

	});


	$('.subMenuL4Cont').click(function() {
		$('.subContainerOpen').animate({
			'height': '55px'
		});


		var kids = $(this).children().length;
		var heights = 0;

		$(this).children().each(function() {
			heights += $(this).outerHeight();
		});
		$(this).children().show();



		$(this).animate({
			'height': heights + 'px'
		}).addClass('subContainerOpen');

	});


	// Producer
	$('#fe_producer').hover(function() {
		$(this).animate({
			'opacity': 1
		});
	}, function() {
		$(this).animate({
			'opacity': 0.5
		});
	}).css({
		'opacity': 0.5
	});
});


/* IE 6 message */
function checkIE6() {
	if ($.browser.msie && parseInt($.browser.version, 10) < 7) {
		$("#ie6error").css({
			'display': 'block'
		});
		$('#currentBrowserVersion').text($.browser.version);

		$("#ie6error div").click(function () {
			$("#ie6error").css({
				'display': 'none'
			});
		});
	}
}
/* IE 6 message END */

function getMovieObjOfId(movieName) {

	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	var flObj = (isIE) ? window[movieName] : document[movieName];

	return flObj;
}





