$(document).ready(function() {

	/* External Interface for Communication with Flash */
	(function($) {
		$.fn.externalInterface = function(args) {
			this.each(function() {
				if(typeof(args.method) != 'undefined') {
					try {
						if(typeof(args.args) != 'undefined') {
							var data = this[args.method](args.args);
						} else {
							var data = this[args.method]();
						}
						if(typeof(args.success) != 'undefined') {
							args.success(data);
						}
					} catch(error) {
						if(typeof(args.error) != 'undefined') {
							args.error(error);
						}
					}
				}
			});
			return this;
		};
	})(jQuery);

  /* Load and Fade In Background-Image */
	/*
  $('#background_file img').css('display', 'none');
	$('#background_file img').fadeIn(300, function() {
	   $(this).css('display', 'block');
	});
	*/
	var imgSrc = $('#background_file img').attr('src');
	$('img.hintergrundbild').attr('src', imgSrc); //.fadeIn(300, function() {
	$('img.hintergrundbild').load(function() {
        $(this).fadeIn(500, function() {
	       $(this).css('display', 'block');
	  });
	});

	/* Return value from Flash (ExternalInterface) */
	var currentState = 'pause';
	
	sendToJavaScript = function(flashState) {
		if (flashState == 'play')
			currentState = 'play';
		else if (flashState == 'pause')
			currentState = 'pause';
		else
			currentState = 'play';
	}
	
	/* Display Player Control for Background-Flash */
	if (!$('#background_file img').hasClass('hintergrundbild') && $('#background_file').children().size() != 0) {
		$('#player_control').css('display', 'block');
		$('#player_control').html('<img src="fileadmin/images/agentur/07_footer/footer_steuerung_' + currentState +'.png" class="' + currentState + '" />');
	} 
	
	/* Player Control for Background-Flash */
	$('#player_control img').live('click', function() {
		
		if ($(this).hasClass('pause')) {
			$('#background_file').externalInterface({
				method : 'sendToActionScript',
				args : 'pause'
			});
			if (currentState == 'pause') {
				$(this).attr({
					'src' : 'fileadmin/images/agentur/07_footer/footer_steuerung_play.png',
					'class' : 'play'
				}); 
			}
		} else {
			$('#background_file').externalInterface({
				method : 'sendToActionScript',
				args : 'play'
			});
			if (currentState == 'play') {
				$(this).attr({
					'src' : 'fileadmin/images/agentur/07_footer/footer_steuerung_pause.png',
					'class' : 'pause'
				});
			}
		}		
	});
	
	/* Main-Menu */
	$('#navi_main ul li').each(function(index) {
		$(this).hover(
			function() {
				/*if (!$(this).hasClass('active')) {
					$(this).dequeue().stop();
					$(this).delay(0).animate({
						fontSize: '28px',
						weight: '700',
						height: '30px',
						paddingTop: '8px',
						lineHeight: '30px'
					}, 200, "swing", function() {
						$(this).css('font-weight', 'bold');
					});
				}*/
				if (!$(this).hasClass('active')) {
					$(this).dequeue().stop();
					$(this).delay(100).animate({
						fontSize: '28px',
						weight: '700',
						height: '28px',
						paddingTop: '8px',
						lineHeight: '30px'
					}, {
						queue: false,
						duration: 200, 
						easing: 'jswing',
						complete: function() {
							$(this).css('font-weight', 'bold');
						}
					});
				}
			},
			function() {
				/*if (!$(this).hasClass('active')) {
					$(this).dequeue().stop();
					$(this).delay(100).animate({
						fontSize: '14px',
						weight: '400',
						height: '14px',
						paddingTop: '5px',
						paddingBottom: '5px',
						lineHeight: '18px'
					}, 200, function() {
						$(this).css('font-weight', 'normal');
					});
				}*/
				if (!$(this).hasClass('active')) {
					$(this).dequeue().stop();
					$(this).delay(100).animate({
						fontSize: '14px',
						weight: '400',
						height: '14px',
						paddingTop: '5px',
						paddingBottom: '5px',
						lineHeight: '14px'
					}, {
						queue: false,
						duration: 200, 
						easing: 'jswing',
						complete: function() {
							$(this).css('font-weight', 'normal');
						}
					});
				}
		});
	});
	
	
	/* Sub-Menu */
	$('#navi_sub ul li').each(function(index) {
		$(this).hover(
			function() {
				/*if (!$(this).hasClass('active')) {
					$(this).dequeue(0).stop();
					$(this).delay().animate({
						marginTop: '2px',
						fontSize: '24px'
					}, 200, function() {
						$(this).css('font-weight', 'bold');
					});
				}*/
				if (!$(this).hasClass('active')) {
					$(this).dequeue(0).stop();
					$(this).delay().animate({
						marginTop: '2px',
						fontSize: '24px'
					}, {
						queue: false,
						duration: 200, 
						easing: 'jswing',
						complete: function() {
							$(this).css('font-weight', 'bold');
						}
					});
				}
			},
			function() {
				if (!$(this).hasClass('active')) {
					/*if (!$(this).hasClass('active')) {
						$(this).dequeue().stop();
						$(this).delay(0).animate({
							marginTop: '5px',
							fontSize: '12px'
						}, 200, function() {
							$(this).css('font-weight', 'normal');
						});
					}*/
					if (!$(this).hasClass('active')) {
						$(this).dequeue().stop();
						$(this).delay(0).animate({
							marginTop: '5px',
							fontSize: '12px'
						}, {
							queue: false,
							duration: 200, 
							easing: 'jswing',
							complete: function() {
								$(this).css('font-weight', 'normal');
							}
						});
					}
				}
			});
	});
	
	/* FadeIn/-Out Main-Menu */
	$('#content_toggle').toggle(
		function() {
			/*$('#top').animate({
				marginTop: parseInt($('#top').css('marginTop'),10) == 0 ? -$('#top').outerHeight() : 0
			},500,function() {
				$('#content_toggle img').attr('src', 'fileadmin/images/agentur/02_header/header_navi_pfeil_einblenden.png');
			});*/
			$('#top').animate({
				marginTop: parseInt($('#top').css('marginTop'),10) == 0 ? -$('#top').outerHeight() : 0
			}, {
				queue: false,
				duration: 500,
				easing: 'jswing',
				complete: function() {
					$('#content_toggle img').attr('src', 'fileadmin/images/agentur/02_header/header_navi_pfeil_einblenden.png');
				}
			});
		},
		function() {
			/*$('#top').animate({
				marginTop: parseInt($('#top').css('marginTop'),10) == 0 ? $('#top').outerHeight() : 0
			},500,function() {
				$('#content_toggle img').attr('src', 'fileadmin/images/agentur/02_header/header_navi_pfeil_ausblenden.png');
			});*/
			$('#top').animate({
				marginTop: parseInt($('#top').css('marginTop'),10) == 0 ? $('#top').outerHeight() : 0
			}, {
				queue: false,
				duration: 500,
				easing: 'jswing',
				complete: function() {
					$('#content_toggle img').attr('src', 'fileadmin/images/agentur/02_header/header_navi_pfeil_ausblenden.png');
				}
			});
		}
	);
	

	/* Order linked references */
	$('ul#reflist_linkedlogo').css('display', 'none');

	$('ul#reflist_linkedlogo').children().each( function(index) {
    if ((index+1)%2 == 0) {
			$(this).css('margin-right', '0');
		}
	});
	
	$('ul#reflist_linkedlogo').css('display', 'block');
	
	/* Order linked products */
	$('ul#productlist_linkedlogo').css('display', 'none');

	$('ul#productlist_linkedlogo').children().each( function(index) {
    if ((index+1)%2 == 0) {
			$(this).css('margin-right', '0');
		}
	});
	
	$('ul#productlist_linkedlogo').css('display', 'block');
	
	
	
});
