var mouseX = 0;
var mouseY = 0;




/* !next prev Function */
/* ---------------------------------------------------------------------- */

function nextImage() {
	$('.headerImageItem:last').fadeOut('slow', function () {
		$('#headerImageSlider').prepend($(this));
		$(this).css('display','block');
	});
}

function prevImage() {
	$('.headerImageItem:first').css('display','none');
	$('#headerImageSlider').append($('.headerImageItem:first'));
	$('.headerImageItem:last').fadeIn('slow', function () {
	});
}




/* !teamSlider */
/* ---------------------------------------------------------------------- */

function teamSlider() {

	var sliderCount = $('.teamItem').size();
	var sliderWidth =  sliderCount * 180;
	$('#teamSlider').css('width',sliderWidth);

	var sliderStartPos = (sliderWidth - 1024) / 2


	// slider start position
	$('#teamSlider').css('left',-sliderStartPos);


	// tooltip ie, safari, ff
	if ($.browser.msie && $.browser.version.substr(0,1)<9) {

		var imageHover = 0;
		var boxHover = 0;
		
		// tooltip ie
		$('.teamImage').hover(
			function () {
				$(this).next().css('top', '190');		
			}, 
			function () {
				$(this).next().css('top', '300');
			}
		);

		$('.teaminfobox').hover(
			function () {
				$(this).css('top', '190');	
			}, 
			function () {
				$(this).css('top', '300');
			}
		);
	
	
	
		//tooltip hide
		$('#contentWrapper').hover(
		    function(){
		    	$('.teaminfobox').css('top', '300');
		    }	
		);
		
		$('#overlay').hover(
		    function(){
		    	$('.teaminfobox').css('top', '300');
		    }	
		);	
	
	} else {
		// tooltip safari, ff
		$('.teamImage').hover(
			function () {
	
				$('.teaminfobox').hide();
	
				$(this).mousemove( function(e) {
				    mouseX = e.pageX - (e.page - 1); 
				    mouseY = e.pageY - 60;
				    $(this).next().css('top', mouseY);
				    $(this).next().css('left', mouseX);
				});
					
				$(this).next().fadeIn('300');
				
			}, 
			function () {
				$(this).next().hide();
			}
		);
	
		//tooltip hide
		$('#contentWrapper').hover(
			function(){
				$('.teaminfobox').hide();
			}	
		);
		
		$('#overlay').hover(
			function(){
				$('.teaminfobox').hide();
			}	
		);	
	
	}
	

	$('#teamArrowLeft').hover(
		function(){
			ScrollLeft();
		}, function (){
			$('#teamSlider').stop();
		}
	)

	$('#teamArrowRight').hover(
		function(){
			ScrollRight();
		}, function (){
			$('#teamSlider').stop();
		}
	)

}


function ScrollLeft () {
	$("#teamSlider").stop().animate({left:0}, 3000);
};

function ScrollRight () {
	var sliderCount = $('.teamItem').size();
	var sliderWidth =  sliderCount * 180;
	$("#teamSlider").stop().animate({left:-sliderWidth+1024}, 3000);
};



/* !teamBackButton */
/* ---------------------------------------------------------------------- */

function teamBackButton() {
	$('.teamActive').fadeOut('slow');
	$('#contentTeam').empty();
	$('#contentNormal').fadeIn('slow');
}








/* !documentReady */
/* ---------------------------------------------------------------------- */

$(document).ready(function(){




	$('#ie6WarningClose a').click(function(){
		$('#ie6WarningWrapper').slideUp();
		$('#ie6WarningWrapperBackground').slideUp();
		return false;
	});

	/* !mainMenuHover */
	/* ---------------------------------------------------------------------- */

	$('.mainMenuItem a').hover(
		function() {
			$(this).parent().prev().addClass('mainMenuButtonHoverLeft');
			$(this).parent().addClass('mainMenuButtonHoverMiddle');
			$(this).parent().next().addClass('mainMenuButtonHoverRight');
		},
		function() {
			$(this).parent().prev().removeClass('mainMenuButtonHoverLeft');
			$(this).parent().removeClass('mainMenuButtonHoverMiddle');
			$(this).parent().next().removeClass('mainMenuButtonHoverRight');	
		}	
	);

	/* !headerSlider */
	/* ---------------------------------------------------------------------- */

	if($(".headerImageItem").size() > 1 ){
		
		//$('#headerImageArrowLeft').css('display','block');
		//$('#headerImageArrowRight').css('display','block');
		
		$('#headerImage').hover(
			function() {
				//alert('head');
				$('#headerImageArrowLeft').css('top','160px');
				$('#headerImageArrowRight').css('top','160px');	
			},
			function() {
				$('#headerImageArrowLeft').css('top','-300px');
				$('#headerImageArrowRight').css('top','-300px');	
			}
		);
		
		$('#headerImageArrowLeft').bind("click", function() {
			prevImage();
		});
		
		$('#headerImageArrowRight').bind("click", function() {
			nextImage();
		});		

		$(this).everyTime(7000, 'controlled', function() {
			nextImage();
		});
		
	}

	/* !teamSlider */
	/* ---------------------------------------------------------------------- */

	if( $('#teamSlider').size() > 0) {
		teamSlider();
	}

	$('#headerImage').hover(
	    function() {
	    	//alert('head');
	    	$('#teamArrowLeft').css('top','160px');
	    	$('#teamArrowRight').css('top','160px');	
	    },
	    function() {
	    	$('#teamArrowLeft').css('top','-300px');
	    	$('#teamArrowRight').css('top','-300px');	
	    }
	);

	/* !teamDetail */
	/* ---------------------------------------------------------------------- */
	$('.teamItem').bind('click', function(){
		//teamDetail();
		$('.teamActive').fadeOut('slow');
		$('> div:nth-child(3)', this).fadeIn('slow');
		
		$('#contentNormal').hide();
		$('#contentTeam').empty();
		$('> div:nth-child(2)', this).children('#teaminfoboxMiddle').children('#teamName').clone().appendTo('#contentTeam');
		$('> div:nth-child(4)', this).clone().appendTo('#contentTeam');
		
	});
	
	
	/* !seeing, der weg zur brille */
	/* ---------------------------------------------------------------------- */

	$('.seeingIcon').hover(
		function(){
			$(this).css('border-bottom','3px solid #ff0000');
		}, function(){
			$(this).css('border-bottom','none');
		}
	)

	$('#seeingIcon1').hover(
		function(){
			$('#seeingBottomContent #seeingTop1Text').parent().css('color','#ff0000');
			$('#seeingBottomContent #seeingTop1Text').css('color','#ff0000');
		}, function(){
			$('#seeingBottomContent #seeingTop1Text').parent().css('color','#555555');
			$('#seeingBottomContent #seeingTop1Text').css('color','#555555');
		}
	)

	$('#seeingIcon2').hover(
		function(){
			$('#seeingBottomContent #seeingTop2Text').parent().css('color','#ff0000');
			$('#seeingBottomContent #seeingTop2Text').css('color','#ff0000');
		}, function(){
			$('#seeingBottomContent #seeingTop2Text').parent().css('color','#555555');
			$('#seeingBottomContent #seeingTop2Text').css('color','#555555');
		}
	)

	$('#seeingIcon3').hover(
		function(){
			$('#seeingBottomContent #seeingTop3Text').parent().css('color','#ff0000');
			$('#seeingBottomContent #seeingTop3Text').css('color','#ff0000');
		}, function(){
			$('#seeingBottomContent #seeingTop3Text').parent().css('color','#555555');
			$('#seeingBottomContent #seeingTop3Text').css('color','#555555');
		}
	)

	$('#seeingIcon4').hover(
		function(){
			$('#seeingBottomContent #seeingTop4Text').parent().css('color','#ff0000');
			$('#seeingBottomContent #seeingTop4Text').css('color','#ff0000');
		}, function(){
			$('#seeingBottomContent #seeingTop4Text').parent().css('color','#555555');
			$('#seeingBottomContent #seeingTop4Text').css('color','#555555');
		}
	)

	$('#seeingIcon5').hover(
		function(){
			$('#seeingBottomContent #seeingTop5Text').parent().css('color','#ff0000');
			$('#seeingBottomContent #seeingTop5Text').css('color','#ff0000');
		}, function(){
			$('#seeingBottomContent #seeingTop5Text').parent().css('color','#555555');
			$('#seeingBottomContent #seeingTop5Text').css('color','#555555');
		}
	)	


	$('.seeingIcon').bind('click', function(){
		$(this).addClass('seeingIconAct');
		$('#seeingBottomContentDetail').empty();
		$(this).next().next().clone().appendTo('#seeingBottomContentDetail');
		$('#seeingBottomContentDetail .seeingDetail').css('display','block');
		
		$('#seeingBottomContentHeader').empty();
		$(this).next().children('.seeingTopText').clone().appendTo('#seeingBottomContentHeader');
		
		$('#seeingBottomContent').fadeOut('slow', function(){
			$('#seeingBottomContentDetail').fadeIn('slow');
			$('#seeingBottomContentHeader').fadeIn('slow');
			$('#seeingDetailBack').fadeIn('slow');
		});
	});


	$('.seeingTextWrapper').hover(function(){
		$(this).css('color','#EE1C25');
		$(this).children().css('color','#EE1C25');
	}, function(){
		$(this).css('color','#555555');
		$(this).children().css('color','#555555');
	});

	$('.seeingTextWrapper1').bind('click', function(){
		$('#seeingIcon1').click();
	});

	$('.seeingTextWrapper2').bind('click', function(){
		$('#seeingIcon2').click();
	});
	
	$('.seeingTextWrapper3').bind('click', function(){
		$('#seeingIcon3').click();
	});

	$('.seeingTextWrapper4').bind('click', function(){
		$('#seeingIcon4').click();
	});	

	$('.seeingTextWrapper5').bind('click', function(){
		$('#seeingIcon5').click();
	});


	$('#seeingDetailBack').bind('click', function() {
		$(this).fadeOut('slow');
		$('#seeingBottomContentHeader').fadeOut('slow');
		$('#seeingBottomContentDetail').fadeOut('slow', function(){
			$('#seeingBottomContent').fadeIn('slow');
		});
		$('.seeingIcon').removeClass('seeingIconAct');
	});

	$('#seeingHeader').bind('click', function() {
		
		$('#seeingDetailBack').fadeOut('slow');
		$('#seeingBottomContentHeader').fadeOut('slow');
		$('#seeingBottomContentDetail').fadeOut('slow', function(){
			$('#seeingBottomContent').fadeIn('slow');
		});
	});	
	

	
	/* ! */
	/* ---------------------------------------------------------------------- */
	
	$(".galleryLink").bind('click', function(){
		$(this).next().children().fancybox();
		$(this).next().children(':first').click();
	});

	/* ! */
	/* ---------------------------------------------------------------------- */

	$('.mf-submit').hover( function(){
		$(this).css('color','#cccccc');
	}, function (){
		$(this).css('color','#ffffff');
	});



	/* !formular */
	/* ---------------------------------------------------------------------- */

	var $hiddenBox = $('select[multiple = "multiple"]')
	var $hiddenDiv = $('select[multiple = "multiple"]').parent().parent();
	
	if ($.browser.msie && $.browser.version.substr(0,1)<9) {
		var $hiddenBox = $('select[multiple]')
		var $hiddenDiv = $('select[multiple]').parent().parent();	
		$hiddenBox.removeAttr('multiple');
	}
	
	$hiddenBox.attr('multiple','');
	$hiddenDiv.addClass('hiddenSelectorBox');
	//$hiddenDiv.prev().addClass('SelectorBox');
	//$hiddenDiv.prev().children(':eq(1)').append('<span class="selectMore"><p>+</p></span>');
	
	//$('.hiddenSelectorBox').prev().children(':eq(1)').append('<span class="selectMore"><p>+</p></span>');
	

	$('.hiddenSelectorBox').each(function(){
		$(this).prev().children(':eq(1)').append('<span class="selectMore"><img src="/fileadmin/images/icon_plus.png"></span>');
	});

	
	
	$('.selectMore').toggle(
		function(){
			$(this).parent().parent().next().slideDown();
			$(this).html('<img src="/fileadmin/images/icon_minus.png">');
			$(this).parent().parent().next().children(':eq(1)').children(':eq(0)').children(':eq(0)').attr('selected','selected');
		},
		function(){
			$(this).parent().parent().next().slideUp();
			$(this).html('<img src="/fileadmin/images/icon_plus.png">');
			$(this).parent().parent().next().children(':eq(1)').children(':eq(0)').children(':eq(0)').attr('selected','selected');
		}
	);
	
	

});











