// JavaScript Document

/*
// --------------------------------------------------------------------------
// jQuery.custom.js by orangepointsolutions Ltd., www.orangepointsolutions.de
// --------------------------------------------------------------------------
*/

$(document).ready(function() {

/*
// --------------------------------------------------------------------------
// jQuery.sequence by Yehuda Katz
// http://www.mail-archive.com/discuss@jquery.com/msg10821.html
// --------------------------------------------------------------------------
*/

jQuery.sequence = {
  setTimeoutH: function(f, t) {
    var params = (arguments.length == 3 && arguments[2].constructor ==
Array) ? arguments[2] : jQuery.merge([], arguments).slice(2);
    window.setTimeout(function() { f.apply(f, params) }, t);
  },

  run: function() {
    if(arguments[0]) arguments[0]();
    if(arguments[1]) jQuery.sequence.setTimeoutH(arguments.callee, 700,
jQuery.merge([], arguments).slice(1));
  },

  runArray: function(array, fn, whenDone) {
    if(array[0]) fn.call(array[0], array);
    if(array[1]) jQuery.sequence.setTimeoutH (arguments.callee, 1,
jQuery.merge([], array).slice(1), fn, whenDone);
    else if(whenDone) whenDone();
  }
}

jQuery.fn.sequence = function(fn, whenDone) {
  jQuery.sequence.runArray (this, fn, whenDone);
  return this;
}

// -- end of jQuery.sequence --

	var isIE8 = false;
	if ( $.browser.msie && jQuery.browser.version == '8.0' ) { isIE8 = true; }

	// slide language
	
	function language_close() {
		$('#de').animate({ width: 'hide', opacity: 'hide' }, 'normal');
		$('#en').animate({ width: 'hide', opacity: 'hide' }, 'normal');
		$('#language_navigation').animate({ width: 'hide' }, 'slow');
		$('#language_close').css('background-image','url(images/open.png)');
	}
	
	function language_open() {
		$('#language_navigation').animate({ width: 'show' }, 'fast');
		$('#de').animate({ width: 'show', opacity: 'show' }, 'normal');
		$('#en').animate({ width: 'show', opacity: 'show' }, 'normal');
		$('#language_close').css('background-image','url(images/close.png)');
	}
	
	$("#language_close").click()
		.toggle(function() { language_close(); }, function() { language_open(); });

	// main navigation

	$("#n1")
		.mouseover( function() { $(this).addClass('hover') } )
		.mouseout( function() { $(this).removeClass('hover') } );

	$("#n2")
		.mouseover( function() { $(this).addClass('hover') } )
		.mouseout( function() { $(this).removeClass('hover') } );

	$("#n3")
		.mouseover( function() { $(this).addClass('hover') } )
		.mouseout( function() { $(this).removeClass('hover') } );

	$("#n4").not(".active")
		.mouseover( function() { $(this).addClass('hover'); $("#nlast").addClass('nlastactive') } )
		.mouseout( function() { $(this).removeClass('hover'); $("#nlast").removeClass('nlastactive') } );

	$("#nlast").not(".nlastactive")
		.mouseover( function() { $(this).addClass('nlastactive'); $("#n4").addClass('hover') } )
		.mouseout( function() { $(this).removeClass('nlastactive'); $("#n4").removeClass('hover') } );

	// slide toolbox
	
	$("#toolbox_slider").click().toggle(function() {
		$('#toolbox').animate({ width: 'show', opacity: 'show' }, 'normal');
	}, function() {
		$('#toolbox').animate({ width: 'hide', opacity: 'hide' }, 'normal');
	});


	// slide top toolbox
	
	$("#toolbox_top_slider").click().toggle(function() {
		$('#toolbox_top').animate({ height: 'show', opacity: 'show' }, 'normal');
		$('#references').animate({ opacity: '0.03' }, 'normal');
	}, function() {
		$('#toolbox_top').animate({ height: 'hide', opacity: 'hide' }, 'normal');
		$('#references').animate({ opacity: '1.0' }, 'normal');
	});



	// slide main content
	
	var jsSideContentCloseMode = false;
	
	function side_content_close() {
		$('#inner').css('overflow','hidden');
		$('#navigation>li').animate({ width: 'hide' }, 'normal');
		$('#content').animate({ width: 'hide' }, 'normal');
		$('#toolbox_container').animate({ width: 'hide' }, 'normal');
		$('#main_content>#navigation').animate({ width: 'hide' }, 'slow');
		$('#side_content').animate({ width: 'hide' }, 'normal', function(){
			$('#side_content').animate({ width: 'show', opacity: 'show' }, 'slow');
			$("#side_content_close").css('background-image','url(images/open_sidecontent.gif)');
		});
	}
	
	function side_content_open() {
		$('#side_content').animate({ width: 'hide' }, 'normal', function(){
			$('#main_content>#navigation').animate({ width: 'show' }, 'fast');
			$('#side_content').animate({ width: 'show' }, 'slow');
			$('#navigation>li').animate({ width: 'show' }, 'normal');
			$('#content').animate({ width: 'show' }, 'normal', function() {
				$("#side_content_close").css('background-image','url(images/close_sidecontent.gif)');
				$('#inner').css('overflow','auto');
			});
			$('#toolbox_container').animate({ width: 'show' }, 'normal');
		});
	}
	
	 
	$("#side_content_close").click(function() {
		if ( jsSideContentCloseMode == false ) {
				if ( jsExpandedContentMode == false ) { 
					side_content_close(); 
					jsSideContentCloseMode = true;
				}
		} else {
				side_content_open();
				jsSideContentCloseMode = false;
		}
	});
	
		
	
	// layer more or less
	
	var jsExpandedContentMode = false;
	
	function handle_more_click() {
		var j_height = Number($(window).height()) - 
						Number(6) - // j_pattern_height
						Number(0) - // j_margin_top
						Number(42) - // j_main_navigation
						Number(22) - // inner padding
						Number(0) - // j_margin_bottom
						Number(46); // j_footer_height
		var j_height_content = j_height + "px";
		var j_height_inner = (Number(j_height) - Number(10)) + "px";
		
		language_close();
		$('#content_container').animate({ top: '6px' }, 'normal' );
		$(".more").hide();
		$('#toolbox_container').animate({ width: '0px', opacity: 'hide' }, 'normal' );
		$('.teasertext').animate({ opacity: 'hide' }, 'normal' );
		$('#content').css("background-image","none");
		$('#content').animate({ height: j_height_content, width: '750px' }, 'normal', function() {
			$('.more_content').animate({ opacity: 'show' }, 'normal');
			$(".less").show();
			$('#inner').css("height", j_height_inner );
			$('#inner').jScrollPane({animateTo:false});
			$('#toolbox_container').css('float', 'left');
			$('#content').css('padding-top','15px');
			$('#toolbox_top_container').animate({ opacity: 'show' }, 'normal' );
			// page 04 special
			$('#more_arrows_left').animate({ width: 'hide' }, 'fast');
			$('#more_arrows_right').animate({ width: 'show' }, 'fast');
		});
		$('#side_content').animate({ marginTop: '84px' }, 'normal');
		$('#side_content_close').animate({ opacity: '0.2' }, 'normal');
		$('#logo').animate({ 'left': '+=288px', 'top': '+=42px', width: '237px' }, 'normal');
	}
	
	$(".more").click(function() {
		handle_more_click();
		jsExpandedContentMode = true;
	});
	
	if ( AUTO_HANDLE_MORE_CLICK == true ) { 
		handle_more_click(); 
		jsExpandedContentMode = true;
	}


	var my_content = $('#content_container').contents();
		
	$(".less").click(function() {

		$('.more_content').animate({ opacity: 'hide' }, 'normal');
		$('#toolbox_top_container').animate({ opacity: 'hide' }, 'normal' );
		$('#content').animate({ height: '283px', width: '570px' }, 'normal', function() {
			$('#inner').jScrollPaneRemove();
			$(".less").hide();
			$(".more").show();
			$('.teasertext').animate({ opacity: 'show' }, 'slow');
			// page 04 special
			$('#more_arrows_left').show();
			$('#more_arrows_right').hide();
		});
		$('#toolbox_container').animate({ width: '180px', opacity: 'show' }, 'slow', function() {
			$('#toolbox_container').css('float', 'left');
		});
		$('#content_container').animate({ top: '215px' }, 'normal' );
		$('#content').css('padding-top','0px');
		$('#side_content').animate({ marginTop: '0px' }, 'normal');
		$('#side_content_close').animate({ opacity: '1.0' }, 'normal');
		$('#logo').animate({ 'left': '-=288px', 'top': '-=42px', width: '313px' }, 'normal');
		language_open();
		jsExpandedContentMode = false;
	});


    // form field value swap

    swapValue = $("#pw").val();
    $("#pw").focus(function(){
        if ($(this).val() == swapValue) {
			// $('<input type="password">').appendTo("form"); 
			$(this).val("");
        }
    }).blur(function(){
        if ($.trim($(this).val()) == "") {
            $(this).val(swapValue);
        }
    });


	// wallpaper download
	
	$("#btn_wallpaper").click(function() {
		$('#wallpaper_holder').show();
		$('#wallpaper_holder').animate({ opacity: '0.7' }, 'normal');
		$('#wallpaper').animate({ opacity: 'show' }, 'normal');
	});

	$("#btn_top_wallpaper").click(function() {
		$('#wallpaper_holder').show();
		$('#wallpaper_holder').animate({ opacity: '0.7' }, 'normal');
		$('#wallpaper').animate({ opacity: 'show' }, 'normal');
	});

	$("#wallpaper_fl_close").click(function() {
		$('#wallpaper_holder').animate({ opacity: 'hide' }, 'normal');
		$('#wallpaper').animate({ opacity: 'hide' }, 'normal');
	});



/*	$('#pw').focus(function() {
							$(this).text(''); 
							});
*/

	// slide footer
	
	function footer_close() {
		$('#footer_navigation').animate({ width: 'hide', opacity: 'hide' }, 'normal');
		$('#footer_main').animate({ width: '40px' }, 'slow');
		$('#footer_container #colorbar').animate({ width: 'hide', opacity: 'hide' }, 'normal');
		$('#footer_close').css('background-image','url(images/open.png)');
	}
	
	function footer_open() {
		$('#footer_main').animate({ width: '993px' }, 'fast');
		$('#footer_navigation').animate({ width: 'show', opacity: 'show' }, 'normal');
		$('#footer_container #colorbar').animate({ width: 'show', opacity: 'show' }, 'normal');
		$('#footer_close').css('background-image','url(images/close.png)');
	}
	
	$("#footer_close").click()
		.toggle(function() { footer_close(); }, function() { footer_open(); });

	// imprint slider
	$("#more_info_ga").click(function(){
		$('#more_info_ga').hide();
		$('#more_text_ga').show();
		$('#col3').jScrollPane();
	});

	$("#less_info_ga").click(function(){
		$('#more_text_ga').hide();
		$('#more_info_ga').show();
		$('#col3').jScrollPaneRemove();
	});


	// headlines
	
	$("h1:contains('Management Coaching')").replaceWith('<img class="content_h1" src="images/management-coaching.gif" alt="">'); // 01
	$("h1:contains('Coaching & Diagnostik')").replaceWith('<img class="content_h1" src="images/coaching-diagnostik.gif" alt="">'); // 02
	$("h1:contains('Ihr Management Coach')").replaceWith('<img class="content_h1" src="images/ihr-management-coach.gif" alt="">'); // 03
	$("h1:contains('Unsere Kunden')").replaceWith('<img class="content_h1" src="images/unsere-kunden.gif" alt="">'); // 04
	$("h2:contains('Berufliche Qualifikation')").replaceWith('<img class="content_h2" src="images/berufliche-qualifikation.gif" alt="">'); // 03
	
	$("h1:contains('Coaching & Diagnostics')").replaceWith('<img class="content_h1" src="images/coaching-diagnostics.gif" alt="">'); // 02
	$("h1:contains('Your Management Coach')").replaceWith('<img class="content_h1" src="images/your-management-coach.gif" alt="">'); // 03
	$("h1:contains('Our Clients')").replaceWith('<img class="content_h1" src="images/our-clients.gif" alt="">'); // 04
	$("h2:contains('Professional Qualification')").replaceWith('<img class="content_h2" src="images/professional-qualification.gif" alt="">'); // 03
	
	// quotes
	
	$("#page01 .quote").replaceWith('<img id="quote" src="images/zitat-malik-01.gif" alt="' + $("#page01 .quote").text() + '">');
	$("#page02 .quote").replaceWith('<img id="quote" src="images/zitat-einstein-02.gif" alt="' + $("#page02 .quote").text() + '">');
	$("#page03 .quote").replaceWith('<img id="quote" src="images/zitat-sprenger-03.gif" alt="' + $("#page03 .quote").text() + '">');
	$("#page04 .quote").replaceWith('<img id="quote" src="images/zitat-malik-04.gif" alt="' + $("#page04 .quote").text() + '">');

	$("#page01 .quote_en").replaceWith('<img id="quote" src="images/zitat-malik-en-01.gif" alt="' + $("#page01 .quote_en").text() + '">');
	$("#page02 .quote_en").replaceWith('<img id="quote" src="images/zitat-drucker-02.gif" alt="' + $("#page02 .quote_en").text() + '">');
	$("#page03 .quote_en").replaceWith('<img id="quote" src="images/zitat-banchard-03.gif" alt="' + $("#page03 .quote_en").text() + '">');
	$("#page04 .quote_en").replaceWith('<img id="quote" src="images/zitat-malik-en-04.gif" alt="' + $("#page04 .quote_en").text() + '">');

	// two columns headlines
	
	$("h1:contains('Coaching')").replaceWith('<img class="contenttwocolumns_h1" src="images/coaching.gif" alt="">'); // 02
	$("h1:contains('Diagnostik')").replaceWith('<img class="contenttwocolumns_h1" src="images/diagnostik.gif" alt="">'); // 02
	$("h1:contains('Peter Berger')").replaceWith('<img class="contenttwocolumns_h1" src="images/peter-berger.gif" alt="">'); // 03
	//$("h1:contains('Aufgabenfelder')").replaceWith('<img class="contenttwocolumns_h1" src="images/aufgabenfelder.png" alt="">'); // 03
	$("h1:contains('::.')").replaceWith('<img class="contenttwocolumns_h1" src="images/empty.gif" alt="">'); // 03
	$("h1:contains('Kunde')").replaceWith('<img class="contenttwocolumns_h1" src="images/kunde.gif" alt="Kunde">'); // 04
	$("h1:contains('Leistung')").replaceWith('<img class="contenttwocolumns_h1" src="images/leistung.gif" alt="Leistung">'); // 04

	$("h1:contains('Diagnostics')").replaceWith('<img class="contenttwocolumns_h1" src="images/diagnostics.gif" alt="diagnostics">'); // 02
	//$("h1:contains('Scope of duties')").replaceWith('<img class="contenttwocolumns_h1" src="images/scope-of-duties.png" alt="scope of duties">'); // 03
	$("h1:contains('Client')").replaceWith('<img class="contenttwocolumns_h1" src="images/client.gif" alt="client">'); // 04
	$("h1:contains('Project')").replaceWith('<img class="contenttwocolumns_h1" src="images/project.gif" alt="project">'); // 04

	// wallpaper

	$("h2:contains('Wallpaper Download')").replaceWith('<div class="holder_wallpaper_h2"><img class="wallpaper_h2" src="images/wallpaper-download.png" alt=""></div>');

	// footer

	$("h2:contains('Seite empfehlen')").replaceWith('<div class="holder_footer_h2"><img class="footer_h2" src="images/seite-empfehlen.png" alt="Seite empfehlen"></div>');
	$("h2:contains('Links')").replaceWith('<div class="holder_footer_h2"><img class="footer_h2" src="images/links.png" alt="Links"></div>');
	$("h2:contains('Presse')").replaceWith('<div class="holder_footer_h2"><img class="footer_h2" src="images/presse.png" alt="Presse"></div>');
	$("h2:contains('Kontaktformular')").replaceWith('<div class="holder_footer_h2"><img class="footer_h2" src="images/kontaktformular.png" alt="Kontaktformular"></div>');
	$("h2:contains('Impressum')").replaceWith('<div class="holder_footer_h2"><img class="footer_h2" src="images/impressum.png" alt="Impressum"></div>');

	$("h2:contains('Tell a friend')").replaceWith('<div class="holder_footer_h2"><img class="footer_h2" src="images/tell-a-friend.png" alt="Tell a friend"></div>');
	$("h2:contains('Press')").replaceWith('<div class="holder_footer_h2"><img class="footer_h2" src="images/press.png" alt="Press"></div>');
	$("h2:contains('Contact form')").replaceWith('<div class="holder_footer_h2"><img class="footer_h2" src="images/contact-form.png" alt="Contact form"></div>');
	$("h2:contains('Imprint')").replaceWith('<div class="holder_footer_h2"><img class="footer_h2" src="images/imprint.png" alt="Imprint"></div>');


function callback(eventObject) {
  this; // dom element
}


	function close_all_footer_menu_container() {
		if ( status_taf == true ) { close_taf_container(false); return; }
		if ( status_links == true ) { close_links_container(false); return; }
		if ( status_press == true ) { close_press_container(false); return; }
		if ( status_contact == true ) { close_contact_container(false); return; }
		if ( status_imprint == true ) { close_imprint_container(false); return; }
	}

	// footer menu Tell-a-friend
	
	var status_taf = false;
	
	function open_taf_container() {
		if (isIE8) { $('#side_content').hide(); }
		$('#content_container').animate({ opacity: '0.15' }, 'slow');
		$('#tell_a_friend_container').animate({ height: 'show', opacity: 'show' }, 'slow',
										function() { $('#iform_tell_a_friend').fadeIn('slow'); }
		);
		status_taf = true;
	}

	function close_taf_container( show_content ) {
		$('#iform_tell_a_friend').fadeOut('fast', function() {
			$('#tell_a_friend_container').animate({ height: 'hide', opacity: 'hide' }, 'slow');
			if ( show_content == true ) { 
				if (isIE8) { $('#side_content').show(); }
				$('#content_container').animate({ opacity: '1.0' }, 'slow'); 
			}
		});
		status_taf = false;
	}

	$("#fn_tell_a_friend").click(function() {
		if (status_taf == false) { 
			$.sequence.run(function() { close_all_footer_menu_container(); }, function() { open_taf_container(); });
		} else {
			close_taf_container(true); 
		}
	});
	
	$("#taf_fl_close").click(function() {
		close_taf_container(true);
	});

	function check_send_language_selection() {
		// if ( $("#send_profile:checked").length || $("#send_cv:checked").length ) { // old version incl. CV check
		if ( $("#send_profile:checked").length ) {
			$('#send_language_selection').show();
		} else {
			$('#send_language_selection').hide();
		}
	}
	

	// footer menu Links
	
	var status_links = false;
	
	function open_links_container() {
		if (isIE8) { $('#side_content').hide(); }
		$('#content_container').animate({ opacity: '0.15' }, 'slow'); 
		$('#links_container').animate({ height: 'show', opacity: 'show' }, 'slow');
		$('#links').fadeIn('fast');
		status_links = true;
	}
	
	function close_links_container( show_content ) {
		$('#links').fadeOut('fast', function() {
			$('#links_container').animate({ height: 'hide', opacity: 'hide' }, 'slow');
			if ( show_content == true ) { 
				if (isIE8) { $('#side_content').show(); }
				$('#content_container').animate({ opacity: '1.0' }, 'slow'); 
			}
		});
		status_links = false;
	}
	
	$("#fn_links").click(function() {
		if (status_links == false) { 
			$.sequence.run(function() { close_all_footer_menu_container(); }, function() { open_links_container(); });
		} else {
			close_links_container(true); 
		}
	});

	$("#links_fl_close").click(function() {
		close_links_container(true);
	});


	// footer menu Presse
	
	var status_press = false;
	
	function open_press_container() {
		if (isIE8) { $('#side_content').hide(); }
		$('#content_container').animate({ opacity: '0.15' }, 'slow'); 
		$('#press_container').animate({ height: 'show', opacity: 'show' }, 'slow');
		$('#press').fadeIn('fast');
		status_press = true;
	}
	
	function close_press_container( show_content ) {
		$('#press').fadeOut('fast', function() {
			$('#press_container').animate({ height: 'hide', opacity: 'hide' }, 'slow');
			if ( show_content == true ) { 
				if (isIE8) { $('#side_content').show(); }
				$('#content_container').animate({ opacity: '1.0' }, 'slow'); 
			}
		});
		status_press = false;
	}
	
	$("#fn_press").click(function() {
		if (status_press == false) { 
			$.sequence.run(function() { close_all_footer_menu_container(); }, function() { open_press_container(); });
		} else {
			close_press_container(true); 
		}
	});
	
	$("#press_fl_close").click(function() {
		close_press_container(true);
	});


	// footer menu Kontakt
	
	var status_contact = false;
	
	function open_contact_container() {
		if (isIE8) { $('#side_content').hide(); }
		$('#content_container').animate({ opacity: '0.15' }, 'slow');
		$('#contact_container').animate({ height: 'show', opacity: 'show' }, 'slow',
										function() { $('#iform_contact').fadeIn('slow'); }
		);
		status_contact = true;
	}
	
	function close_contact_container( show_content ) {
		$('#iform_contact').fadeOut('fast', function() {
			$('#contact_container').animate({ height: 'hide', opacity: 'hide' }, 'slow');
			if ( show_content == true ) { 
				if (isIE8) { $('#side_content').show(); }
				$('#content_container').animate({ opacity: '1.0' }, 'slow'); 
			}
		});
		status_contact = false;
	}
	
	function handle_fn_contact_click() {
		if (status_contact == false) { 
			$.sequence.run(function() { close_all_footer_menu_container(); }, function() { open_contact_container(); });
		} else {
			close_contact_container(true); 
		}
	}
	
	$("#fn_contact").click(function() {
		handle_fn_contact_click();
	});

	$("#request_call").click(function() {
		handle_fn_contact_click();
	});

	$("#cc_fl_close").click(function() {
		close_contact_container(true);
	});

	if (isIE8) {
		$('#request_call').hide();
	}

	// footer menu Impressum
	
	var status_imprint = false;
	
	function open_imprint_container() {
		if (isIE8) { $('#side_content').hide(); }
		$('#content_container').animate({ opacity: '0.15' }, 'slow'); 
		$('#imprint_container').animate({ height: 'show', opacity: 'show' }, 'slow',
										function() { 
											// $('#imprint').fadeIn('slow'); 
											$('#col3').show();
										});
		$('#imprint').fadeIn('fast');
		status_imprint = true;
	}
	
	function close_imprint_container( show_content ) {
		$('#imprint').fadeOut('fast', function() {
			$('#col3').hide();
			$('#imprint_container').animate({ height: 'hide', opacity: 'hide' }, 'slow');
			if ( show_content == true ) { 
				if (isIE8) { $('#side_content').show(); }
				$('#content_container').animate({ opacity: '1.0' }, 'slow'); 
			}
		});
		status_imprint = false;
	}
	
	$("#fn_imprint").click(function() {
		if (status_imprint == false) { 
			$.sequence.run(function() { close_all_footer_menu_container(); }, function() { open_imprint_container(); });
		} else {
			close_imprint_container(true); 
		}
	});

	$("#imprint_fl_close").click(function() {
		close_imprint_container(true);
	});


    // handle internal links
	
    $(".internal_link").mouseover(function(){ // mouseover on internal link handler
		$(this).toggleClass('underline');
	});
									
    $(".internal_link").mouseout(function(){ // mouseover on internal link handler
		$(this).toggleClass('underline');
	});
	
	// -----
	// initial page preparation
	// -----
	
	// fade in shapes
	$("#logo").hide();
	$("#logo").fadeIn(1200);
	
	// detect flash
	if ( GetSwfVer() == -1 ) {
		$("#bg_container").css("background", "url(images/bg_splash_sea.JPG) no-repeat top right");
	}

	
    // in memory of IE6 set some elements to document height
/*	$("#bg_container").css( "height", $(document).height()+"px" );
	$("#bg_pattern").css( "height", $(document).height()+"px" );
	$("#tagline_container").css( "height", $(document).height()+"px" );
	$("#content_container").css( "height", $(document).height()+"px" );
*/
 });
 
// --- end of jQuery.custom.js ---
