/*
 * jQuery show/hide concern Layer
*/
$(document).ready(function(){
	
	$('a.concern').toggle(
			function() {
				$('div.footerline, div.footer-concern').show();
				$('a.concern').css({
					'font-weight': 'bold',
					'color': '#000066'
			});
		},
		function() {
			$('div.footerline, div.footer-concern').hide();
			$('a.concern').css({
				'color': '#666666',
				'font-weight': 'normal'	
			});
		}
	);
/*
 * jQuery show/hide country/language Layer
*/
	
	$('p.country-choice').click(
		function() {
			$('div.country-choice-content').show();
			return false;
		}
	);
	
	$('p.language-choice').click(function() {
		$('div.language-choice-content').show();
	});

	$('div.country-choice-content li, div.language-choice-content li').bind (
	    'click',
	    function() {
	        $( this )
	        	.closest( 'div' )
	        	.hide()
	        	.closest( 'form' )
	        	.find ( 'input[name=languageId]')
	        		.attr ( 'value', this.id )
	        	.end ()
	        	.trigger ( 'submit' );
	    }
	);
	
	$('div.country-choice-content, div.language-choice-content').mouseleave(function() {
		$('div.country-choice-content, div.language-choice-content').hide();
	});
	
	
	/*
	 * jQuery show/hide Successtories Layer
	*/
	
	$('div.success-stories a.content-headline').toggle(
			function() {
				$(this).parent().parent().children('div.success-stories div.content-data').show();
				$(this).css({
					'background-image': 'url(/LFT-theme/images/lft/icon_dropdown_darkgrey.gif)'
				});
			},
			function() {
				$(this).parent().parent().children('div.success-stories div.content-data').hide();
				$(this).css({
					'background-image': 'url(/LFT-theme/images/lft/listpoint.gif)'
				});
			}
		);
	
	/*
	 * jQuery show/hide Ansprechspartner Layer
	*/
	
	$('div.ansprechpartner-textbock h2').toggle(
			function() {
				$(this).parent().children('div.ansprechpartner-textbock p').show();
				$(this).css({
					'background-image': 'url(/LFT-theme/images/lft/icon_dropdown_darkgrey.gif)'
				});
			},
			function() {
				$(this).parent().children('div.ansprechpartner-textbock p').hide();
				$(this).css({
					'background-image': 'url(/LFT-theme/images/lft/listpoint.gif)'
				});
			}
		);
	
	/*
	 * jQuery show/hide Expandable Layer
	*/
	
	// Read the cookie of accordion menu states
	var sAccordionCookie = ( $.cookie ) ? $.cookie( 'AccordionCookie' ) : false;
	// cookie doesn't exist or is empty
	if ( !sAccordionCookie ) {
		sAccordionCookie = false;
	}
	var aAccordionStates = new Object;
	// Add click event listener
	$('div.expand a.content-headline').click( toggleAccordion );
	
	// Initialize accordion states
	function accordionInit() {
		if ( sAccordionCookie ) {
			// Transform string into JSON object
			aAccordionStates = $.parseJSON( sAccordionCookie );
			// Parse all menus on the page
			var aAccordionMenus = $('div.expand a.content-headline'), i = 0;
			while ( aAccordionMenus[i] ) {
				if ( aAccordionMenus[i].id !== '' ) {
					var oMenu = $( '#' + aAccordionMenus[i].id );
					// The menu exists in the JSON object and it's state is '1': open it
					if ( typeof aAccordionStates[ aAccordionMenus[i].id ] !== 'undefined' ) {
						if ( aAccordionStates[ aAccordionMenus[i].id ] === 1 ) {
							toggleAccordion( null, oMenu, 'open' );
						}
						// otherwise close it
						else {
							toggleAccordion( null, oMenu, 'close' );
						}
					}
				}
				i++;
			}
		}
	}
	// Open or close (toggle) accordion menus, can be triggered by click event or by function call
	function toggleAccordion( event, oTarget, action ) {
		// oTarget is optional, if it's not defined, take the event object
		oTarget = ( oTarget ) ? oTarget :  $( this );
		action = ( typeof action === undefined ) ? false : action;
		// Get the content that is associated with this control
		var aKids =	oTarget.parent().siblings('div.content-data');
		// Close content if it's open and the action doesn't define anything different
		if ( ( oTarget.hasClass( 'open' ) && !action ) || action === 'close' ) {
			oTarget.removeClass( 'open' );
			aKids.css( 'display', 'none' );
			writeAccordionCookie( oTarget.attr( 'id' ), 0 );
		}
		// Open the content
		else {
			oTarget.addClass( 'open' );
			aKids.css( 'display', 'block' );
			writeAccordionCookie( oTarget.attr( 'id' ), 1 );
		}
	}
	// Write the cookie
	function writeAccordionCookie( sId, action ) {
		// Update the associative array
		aAccordionStates[ sId ] = action;
		if ( $.cookie && typeof JSON !== undefined ) {
			$.cookie( 'AccordionCookie', JSON.stringify( aAccordionStates ) );
		}
	}
	// Initialize accordion states
	accordionInit();
	

	/*
	 * jQuery selectbox Kontakt
	*/
	
	$('fieldset select.aui-field-input-select').selectbox();
	
	/*
	 * jQuery selectbox MySIM
	*/
	
	$('.session-table .selectbox').selectbox();
	
	/*
	 * jQuery input fields
	*/
	defaultText = $('#meta-login input#_58_login').val();
	
	$('#meta-login input#_58_login').focus(function() {
		if(this.value == defaultText) this.value='';
	});
	
	$('#meta-login input#_58_login').blur(function() {
		if(this.value == '') this.value=defaultText;
	});


	/*
	 * jQuery input fields wrapper
	*/
	$('input#keywords').wrap('<div class="wrapper-keywords" />');
	$('input#search').wrap('<div class="wrapper-search" />');
	
	$('#signup-table input.aui-field-input-text').wrap('<div class="wrapper-signup-text" />');
	$('#contact-table input.aui-field-input-text').wrap('<div class="wrapper-contact-text" />');
	$('#contact-table textarea.aui-field-input-text').wrap('<div class="wrapper-contact-textarea" />');

	$('#proposal-table input.aui-field-input-text').wrap('<div class="wrapper-proposal-text" />');
	$('#proposal-table textarea.aui-field-input-text').wrap('<div class="wrapper-proposal-textarea" />');

	$('#bookingRequestFF .sessions input.aui-field-input-text').wrap('<div class="wrapper-contact-text" />');
	$('#bookingRequestFF .sessions input.date-input').wrap('<div class="wrapper-contact-text" />');
	

	if ( typeof SimulatorSelector !== 'undefined' ) {
		SimulatorSelector.init ();
	}
	
	
	
	/*
	 * jQuery mysim Filter
	*/

	$('.content-fieldset img.label').toggle(
		function() {
			
			$(this).attr( 'src','/LFT-theme/images/lft/mysim/btn_close.gif' )
				.closest( '.content-fieldset' )
				.find('.scrolloptions').show ();
		},
		function() {
			
			$(this).attr('src','/LFT-theme/images/lft/mysim/btn_open.gif')
				.closest( '.content-fieldset' )
				.find('.scrolloptions').hide();
		}
	);
	
	
	
	$('input[name=check_all]').click(
		function(){
			$(this).closest( '.content-fieldset' )
				.find('.scrolloptions input:checkbox')
				.attr( 'checked', $(this).attr('checked') );
		}
	);
	
	$('div.btn-filter-reset').click(
			function(){
				$(this).closest( 'div.expand' )
					.find( 'input:checkbox' )
					.attr( 'checked', true );
			}
		);
	
	
	
	
	
	$('.scrolloptions input[type="checkbox"]').click(
			function() {
				
				$(this).closest( '.content-fieldset' )
					.find('.choice-all input:checkbox')
					.attr( 'checked', false );
			}
		);

	
	$( 'body' ).append ( '<div class="tooltip"></div>' );
	
	$( '.sim-schicht .timeslot' ).bind ('mouseover', function () {
			var position = $(this).offset();
			var text =  $(this).attr('title');
			$('.tooltip').css(
						{ 'top' : ( parseInt ( position.top ) - 5 ) + 'px',
						  'left' : ( parseInt ( position.left ) + parseInt ( ( $( this ).hasClass ( 'monthly') ) ? 30 : 110 ) ) + 'px'
						});
			$('.tooltip').html($(this).attr('title'));
			$( this ).attr ( 'title', '' );
			if (text.length > 1) {
				$('.tooltip').show();
			}	
		}
	);
	$( '.sim-schicht .timeslot' ).bind ('mouseout', function () {
			$( this ).attr ( 'title', $( '.tooltip' ).html() );
			$( '.tooltip' ).hide ();
		}
	);
	
	
	
	
	
		
});




