jQuery(document).ready(function(){

	/* DropDown bei den Produkten -- Hack for IE6 only */
	$('ul.fx-dropMenu li').hover(function(){
		$(this).find('ul').addClass('fx-dropMenuOver');
	}, function(){
		$(this).find('ul').removeClass('fx-dropMenuOver');
	});

	/* Lightbox prettyPhoto ersetzt Milkbox
	/ Achtung, Plugin ben�tigt */
	if ($.fn.prettyPhoto)
	{
		$("a[rel^='lightbox'],a[rel^='milkbox']").prettyPhoto({
			theme: 'rsLightbox_scope',
			hideflash: true,
			showTitle: true,
			markup: '<div class="pp_pic_holder"> \
						<div class="pp_top"> \
							<div class="pp_left"></div> \
							<div class="pp_middle"> \
							<div class="ppt"></div> \
							</div> \
							<div class="pp_right"></div> \
						</div> \
						<div class="pp_content_container"> \
							<div class="pp_left"> \
							<div class="pp_right"> \
								<div class="pp_content"> \
									<div class="pp_loaderIcon"></div> \
									<div class="pp_fade"> \
										<a href="#" class="pp_expand" title="Expand the image">Expand</a> \
										<div class="pp_hoverContainer"> \
											<a class="pp_next" href="#">next</a> \
											<a class="pp_previous" href="#">previous</a> \
										</div> \
										<div id="pp_full_res"></div> \
										<div class="pp_details clearfix"> \
											<p class="pp_description"></p> \
											<a class="pp_close" href="#">Close</a> \
											<div class="pp_nav"> \
												<a href="#" class="pp_arrow_previous">Previous</a> \
												<p class="currentTextHolder">0/0</p> \
												<a href="#" class="pp_arrow_next">Next</a> \
											</div> \
										</div> \
									</div> \
								</div> \
							</div> \
							</div> \
						</div> \
						<div class="pp_bottom"> \
							<div class="pp_left"></div> \
							<div class="pp_middle"></div> \
							<div class="pp_right"></div> \
						</div> \
					</div> \
					<div class="pp_overlay"></div>'
		});
	}


	/* Topmen� */
	$('#topmenu a').hover(function() {
		var parent = $(this).parent().get(0).tagName.toLowerCase();
		if(parent != 'strong'){
			$(this).animate({
				backgroundColor: '#FF8619',
				height: '18px',
				marginTop: '-3px'
			}, 200);
		}
	}, function() {
		var parent = $(this).parent().get(0).tagName.toLowerCase();
		if(parent != 'strong'){
			$(this).animate({
				backgroundColor: '#8B9196',
				marginTop: '0px',
				height: '15px'
			}, 200);
		}
	});

	/* Mainmen� (Men� links, z.B. unter Produkte) */
	$('#mainmenu li a').hover(function() {
		var parent = $(this).parent().get(0).tagName.toLowerCase();
		if(parent != 'strong'){
			$(this).css('backgroundColor', '#FF8619');
		}
	}, function() {
		var parent = $(this).parent().get(0).tagName.toLowerCase();
		if(parent != 'strong'){
			$(this).animate({
				backgroundColor: '#B6BCC2'
			}, 200);
		}
	});

	/* Accordeon-Funktion (z.B. auf der Technologie-�bersichtsseite: http://www2.rohde-schwarz.com/en/technologies)
	// 1x in Teisnach: http://www.teisnach.rohde-schwarz.com/de/ueber_uns/Meilensteine/
	*/
	$("div.accordion, .fx-accordion").accordion({
		header: 'h3',
		autoHeight: false
	});


	/* Fold-Up/-Down (z.B. auf der Technologie-�bersichtsseite: http://www2.rohde-schwarz.com/en/technologies) */
	$("ul.reduced-section").each(function(){
		var s = $(this).find('li').size();
		if(s > 4){
			// 'more'-Link einf�gen
			$(this).after('<p class="head" style="text-decoration: underline; cursor: pointer;">more...</p>');
			// li's nach dem 4ten ausblenden
			$(this).find('li:gt(4)').hide();
		}
	});

	/* Fold-Up/-Down  */
	$("p.head").toggle(
		function(){
			/* li's einblenden */
			$(this).parent().find('ul.reduced-section li:gt(4)').show('blind', 1000);	/* blind nutzt jQuery UI */
			/* 'more'-Link umbennenen */
			$(this).text('fold up...');
		},
		function(){
			$(this).text('more...');
			$(this).parent().find('ul.reduced-section li:gt(4)').hide('blind', 1000);  /* blind nutzt jQuery UI*/
		}
	);

	/* Slideshow (z.B. auf den Environmental Sites)
	// Achtung, Plugin slideshow.js ben�tigt
	*/
	if ($.fn.slideshow)
	{
		$('div.fx-fader').slideshow({
			timeout: 6000,
			fadetime: 4000,
			type: 'sequence',
			pauselink: 'pause2'
		});
		$('div.fx-fader-fast').slideshow({
			timeout: 6000,
			fadetime: 2000,
			type: 'sequence',
			pauselink: 'pause2'
		});
	}

	/* 2x in Teisnach:
	// - http://www.teisnach.rohde-schwarz.com/de/Unsere_Leistungen/Fertigung/Leiterplatten/Rundgang/
	// - Startseite http://www.teisnach.rohde-schwarz.com
	// Achtung: ben�tigt easySlider-Plugin
	*/
	$("#picture-presenter, #picture-presenter-vertical").easySlider({
		auto: true,
		continuous: true,
		controlsShow: false,
		contentSelector: '#picture-presenter-content',
		contentBoxSelector: 'div.picture-presenter-box',
		speed: 1000,
		pause: 6000
	});


	//*******************************//
	//** For Feedback on this page **//
	//** Start **/
	/* IE davon �berzeugen keine files zu cachen
	*/

	/* Feedback-on-this-page-button einblenden */
	$('#feedback-on-this-page-v4').show();

	$.ajaxSetup({
		cache: false
	});

	var dlg;

	/* H�kchen richtig setzen IE6 only */
	$("label[for='idAnswer'], label[htmlFor='idAnswer']").live('click', function(event) {

       	event.stopPropagation();
       	var myCheckbox = $('#idAnswer');
		var value = myCheckbox.attr('checked');
       	if(value){
           myCheckbox.removeAttr('checked');
           return false;
       	}else{
           $("#idAnswer:checked:enabled");
           return true;
       	}

	});

	/* L�schen der vorbelegten Eingabe im Name-Feld */
	$("#idName").live('click', function() {
		var text = $('#idName').attr('value');
		if(text == 'Name'){
			$('#idName').attr('value', '');
		}
		return true;
	});

	/* L�schen der vorbelegten Eingabe im E-Mail-Feld */
	$("#idEMail").live('click', function() {
		var text = $('#idEMail').attr('value');
		if(text == 'E-Mail address'){
			$('#idEMail').attr('value', '');
		}
		return true;
	});

	/* Starten eines Dialogfensters */
	$('#feedback-on-this-page-v4').click( function(){
		dlg = $('#feedback-on-this-page-v4-content').dialog({height: 400, width: 300, modal: true, title: 'Feedback on this page', resizable: false, hide: 'fold', beforeclose: function(){
			/* Get-Anfrage senden, damit Downloads wieder funktionieren */
			$.get(document.URL);
			return true;
		}});

		/* Seite 1 laden */
		$('#feedback-on-this-page-v4-content').load('/form/feedback-on-this-page-v2 #slide-out-content-inner', '', function(){
			/* http://www2.rohde-schwarz.com/form/feedback-on-this-page-v2 */
			$('#feedback-on-this-page-v4-content').append('<div style="clear:both;" /><input id="feedbackformSendButton" type="submit" value="Send" />');
			/* Ein- und Ausblenden der Name,E-Mail Felder wenn H�kchen gesetzt */
			/*$('#idEMail').parent().hide();
			$('#idName').parent().hide();
			*/
			$('#idEMail').next().hide();
			$('#idName').next().hide();

		});

	});

	/* Wenn jmd. nicht gefunden hat, was er suchte */
	$('#idfoundWhatYoureLookedFor').live('change', function(){
		var LookedFor = $('#idfoundWhatYoureLookedFor').val();
		if(LookedFor == "no"){
			$('#idfoundWhatYoureLookedForText').fadeIn(500);
		} else {
			$('#idfoundWhatYoureLookedForText').fadeOut(500);
		}
	});
	$('#idfoundWhatYoureLookedForText').live('focusin', function(){
		var LookedForText = $('#idfoundWhatYoureLookedForText').val();
		if(LookedForText == "I could'nt find..."){
			$('#idfoundWhatYoureLookedForText').val('');
		}
	});
	$('#idfoundWhatYoureLookedForText').live('focusout', function(){
		var LookedForText = $('#idfoundWhatYoureLookedForText').val();
		if(LookedForText == ''){
			$('#idfoundWhatYoureLookedForText').val("I could'nt find...");
		}
	});

	/* Absenden des 1. Formulars */
	$('#feedbackformSendButton').live('click', function(){
		var textVal = $('#idMessage').val();

		if(textVal != ''){
			/* Alles auslesen.... */
			var valTrace = $('#idtrace').val();
			var valFeedbackReason = $('#idFeedbackReason').val();
			var valMessage = $('#idMessage').val();
			var valLastVisitedPage = $('#lastvisistedpage').val();
			if(valLastVisitedPage == '' || !valLastVisitedPage){
				valLastVisitedPage = document.URL;
			}
			var valFormID = 56;
			var valHash = $('input[name="mdhash"]').val();
			var valName = $('#idName').val();
			var valEMail = $('#idEMail').val();
			if($('#idAnswer').is(':checked')){
				valAnswer = 'yes';
			} else {
				valAnswer = 'no';
			}
			/*... und per POST senden */
			$.post('http://www2.rohde-schwarz.com/form/feedback-on-this-page-v2', {trace: valTrace, FeedbackReason: valFeedbackReason, message: valMessage, name: valName, email: valEMail, 'last-visited-page': valLastVisitedPage, ITS_Formgen_FORMID: valFormID, mdhash: valHash, 'answer-for-this-feedback': valAnswer}, function(data){
				/* Wenn fertig, aktuelles Formular l�schen... */
				$('#feedback-on-this-page-v4-content').text('');
				/* Fenster vergr��ern */
				dlg.dialog("option","height", 450);
				/* ...danach neues Formular laden */
				$('#feedback-on-this-page-v4-content').load('http://www2.rohde-schwarz.com/form/feedback-on-this-page-v2-b #slide-out-content-inner', '', function(){
					$('#feedback-on-this-page-v4-content').append('<div style="clear:both;" /><input id="feedbackformSendButton2" type="submit" value="Send" />');
					$('#idfeedbackid').val(valTrace);
					$.getScript('http://www2.rohde-schwarz.com/live/rs/internet/scripts/forms/feedback-on-this-page-v2b.js');
				});
			});
		}
	});

	/* Formular 2 senden */
	$('#feedbackformSendButton2').live('click', function(){
		/* Texte auslesen... */
		var textFound = $('#idfoundWhatYoureLookedFor').val();
		var valOverallImp = $('input[name=OverallImpression\[\]]:checked').val();
		/* old slider var valOverallImp = $('#idOverallImpression').val(); */
		var valUser = $('#idUser').val();
		var varFeedbackID = $('#idfeedbackid').val();
		var valFormID = 58;
		var valHash = $('input[name="mdhash"]').val();

		if($('#idAnswer').is(':checked')){
			valAnswer = 'yes';
		} else {
			valAnswer = 'no';
		}
		/*... und dann per POST senden */
		$.post('http://www2.rohde-schwarz.com/form/feedback-on-this-page-v2-b', {foundWhatYoureLookedFor: textFound, OverallImpression: valOverallImp, user: valUser, feedbackid: varFeedbackID, ITS_Formgen_FORMID: valFormID, mdhash: valHash}, function(data){
			/* Dankesch�n */
			$('#feedback-on-this-page-v4-content').html('<br /><br /><strong>Thanks for your participation!</strong>').delay(2000);
			/* Dialog schlie�en */
			setTimeout(function() {
				$('#feedback-on-this-page-v4-content').dialog('close');
			}, 2000);
		});

	});
	//** Feedback on this page **//
	//** Ende **//
});