$(document).ready(function() {

	/***************************************************************************
	 * SOCIAL BOOKMARKS
	 **************************************************************************/

//	$("#social_bookmarks").dropShadow();

	/***************************************************************************
	 * SLIDE PANEL
	 **************************************************************************/

	// LEFT PANEL
	// Expand Panel
	$("#open_left").click(function() {
		$("div#panel_right").slideUp('slow', function() {
			$("div#panel_left").slideDown("slow");		
			$("#panel_left_bg").css('height',$("#panel_left_bg .content_panel_right").height()+30+"px");
		});
		$("#open_left").hide();
		$("#close_left").show();
		$("#open_right").show();
		$("#close_right").hide();		
		$('#navi_language').css("z-index", "90");
		$('#logo').css("z-index", "90");
		$('#toppanel').css("z-index", "95");
	});

	// Collapse Panel
	$("#close_left").click(function() {
		$("div#panel_left").slideUp('slow', function() {
			$('#navi_language').css("z-index", "95");
			$('#logo').css("z-index", "95");
			$('#toppanel').css("z-index", "90");
		});
		$("#open_right").show();
		$("#open_left").show();
		$("#close_right").hide();
		$("#close_left").hide();
	});

	// RIGHT PANEL
	// Expand Panel
	$("#open_right").click(function() {		
		$("div#panel_left").slideUp('slow', function() {
			$("div#panel_right").slideDown("slow");			
			$("#panel_right_bg").css('height',$("#panel_right_bg .content_panel_right").height()+30+"px");
		});
		$("#open_right").hide();
		$("#close_right").show();	
		$("#open_left").show();
		$("#close_left").hide();		
		$('#navi_language').css("z-index", "90");
		$('#logo').css("z-index", "90");
		$('#toppanel').css("z-index", "95");
	});

	// Collapse Panel
	$("#close_right").click(function() {
		$("div#panel_right").slideUp('slow', function() {
			$('#navi_language').css("z-index", "95");
			$('#logo').css("z-index", "95");
			$('#toppanel').css("z-index", "90");
		});
		$("#open_right").show();
		$("#open_left").show();
		$("#close_right").hide();
		$("#close_left").hide();		
	});

	/***************************************************************************
	 * NAVIGATION
	 **************************************************************************/

	if ($('.navi').length > 0) {
		var navi_top = $(".navi").css('top');
		var index_of = navi_top.indexOf('px');
		var slice = navi_top.slice(0, index_of);
		var navi_top_new = slice - 123 + 'px';
	}

	/*********** FREELANCER ************/
	
	$('#freelancer .navi').mouseenter(function() {
		$('#freelancer .navi').css("height", 150 + "px");		
		$('#freelancer .navi').css("top", navi_top_new);		
		$('#freelancer .sublevel').slideDown();
	});
	$('#freelancer .navi').mouseleave(function() {
		$('#freelancer .sublevel').stop(true, true).fadeOut("fast", function() {
			$('#freelancer .navi').css("height", 27 + "px");
			$('#freelancer .navi').css("top", navi_top);
		});
	});
	$('#freelancer .submenu').mouseenter(function() {		
		$(this).addClass("submenu_active");
		var index = $('#freelancer .submenu').index($(this));
	});
	$('#freelancer .submenu').mouseleave(function() {
		$(this).removeClass("submenu_active");		
		var index = $('#freelancer .submenu').index($(this));
	});	
	$('#freelancer .menuitem').mouseenter(function() {
		var index = $('#freelancer .menuitem').index($(this));
		$('#freelancer .submenu:eq('+index+')').addClass("submenu_active");
	});
	$('#freelancer .menuitem').mouseleave(function() {
		var index = $('#freelancer .menuitem').index($(this));
		$('#freelancer .submenu:eq('+index+')').removeClass("submenu_active");
	});
	
	/*********** UNTERNEHMEN ************/
	
	$('#unternehmen .navi').mouseenter(function() {
		$('#unternehmen .navi').css("height", 150 + "px");		
		$('#unternehmen .navi').css("top", navi_top_new);		
		$('#unternehmen .sublevel').slideDown();
	});
	$('#unternehmen .navi').mouseleave(function() {
		$('#unternehmen .sublevel').stop(true, true).fadeOut("fast", function() {
			$('#unternehmen .navi').css("height", 27 + "px");
			$('#unternehmen .navi').css("top", navi_top);
		});
	});
	$('#unternehmen .submenu').mouseenter(function() {		
		$(this).addClass("submenu_active");
		var index = $('#unternehmen .submenu').index($(this));
	});
	$('#unternehmen .submenu').mouseleave(function() {
		$(this).removeClass("submenu_active");
		var index = $('#unternehmen .submenu').index($(this));
	});	
	$('#unternehmen .menuitem').mouseenter(function() {
		var index = $('#unternehmen .menuitem').index($(this));
		$('#unternehmen .submenu:eq('+index+')').addClass("submenu_active");
	});
	$('#unternehmen .menuitem').mouseleave(function() {
		var index = $('#unternehmen .menuitem').index($(this));
		$('#unternehmen .submenu:eq('+index+')').removeClass("submenu_active");
	});
	
	/***************************************************************************
	 * TABELLEN
	 **************************************************************************/
	
	$('#uploaded_contracts').addClass('table4').attr('cellspacing','0').attr('cellpadding','0').attr('border','0').attr('width','100%');

	/** table1 **/
	$('table.table1 > tbody > tr:first-child').find('td').addClass('first');
	$('table.table1 > tbody > tr:last-child').find('td').addClass('last');
	$('table.table1 > tbody > tr:nth-child(odd)').find('td').addClass('odd');
	$('table.table1 > tbody > tr > td').find('input:submit').parent().attr('align','right');
	$('table.table1 > tbody > tr').find('td:first-child').attr('align','right');
	
	/** table2 **/
	$('table.table2 > tbody > tr:first-child').find('td').addClass('first');
	$('table.table2 > tbody > tr:last-child').find('td').addClass('last');
	$('table.table2 > tbody > tr:nth-child(odd)').find('td').addClass('odd');
	$('table.table2 > tbody > tr > td').find('input:submit').parent().attr('align','right');
	
	/** table3 **/
	$('table.table3 > tbody > tr:first-child').find('td').addClass('first');
	$('table.table3 > tbody > tr:last-child').find('td').addClass('last');
	$('table.table3 > tbody > tr:nth-child(4n+1)').find('td').addClass('odd');
	$('table.table3 > tbody > tr:nth-child(4n+1)').next().find('td').addClass('odd');
	$('table.table3 > tbody > tr:nth-child(odd)').find('td').addClass('main');
	
	/** table4 **/
	$('table.table4 > tbody > tr:first-child').find('td').addClass('first');
	$('table.table4 > tbody > tr:last-child').find('td').addClass('last');
	$('table.table4 > tbody > tr:nth-child(odd)').find('td').addClass('odd');
	$('table.table4 > tbody > tr > td').find('input:submit').parent().attr('align','right');
	
	/** table5 **/
	$('table.table5 > tbody > tr:first-child').find('td').addClass('first');
	$('table.table5 > tbody > tr:last-child').find('td').addClass('last');
	$('table.table5 > tbody > tr:nth-child(odd)').find('td').addClass('odd');
	$('table.table5 > tbody > tr > td').find('input:submit').parent().attr('align','right');
	
	/***************************************************************************
	 * TEAM BILDER
	 **************************************************************************/
		
	$("ul.teambilder li").hover(function() {
		$(this).css({'z-index' : '10'}); // Add a higher z-index value so this image stays on top	
		var img = $(this).find('img');
		img.addClass("hover")			
			.stop() // Add class of "hover", then stop animation queue buildup			
			.attr('src',(img.attr('src').slice(0,img.attr('src').lastIndexOf('_'))+'_rov.jpg'))
			.animate({
				marginTop: '-29px', // The next 4 lines will vertically align this image 
				marginLeft: '-26px',
				//top: '50%',
				//left: '50%',
				width: '121px', // Set new width 
				height: '169px', // Set new height
				padding: '20px'
			}, 200); // this value of "200" is the speed of how fast/slow this hover animates			 
	}, function() {
		$(this).css({'z-index' : '5'}); // Set z-index back to 0 	
		var img = $(this).find('img');
		img.removeClass("hover")			
			.stop()  // Remove the "hover" class , then stop animation queue buildup
			.attr('src',(img.attr('src').slice(0,img.attr('src').lastIndexOf('_'))+'_nrm.jpg'))
			.animate({
				marginTop: '0', // Set alignment back to default 
				marginLeft: '0',
				top: '0',
				left: '0',
				width: '109px', // Set width back to default 
				height: '152px', // Set height back to default
				padding: '0'
			}, 400, function() { $(this).parent().parent().css({'z-index' : '0'}); } );
	});
	
	/***************************************************************************
	 * Galerie
	 **************************************************************************/
	
	$('#gallery img').hover(function(){
		$(this).css('opacity', 1); 
		$(this).parent().parent().addClass('active') 
	}, function() {
		$(this).parent().parent().removeClass('active')
	});
	
	/***************************************************************************
	 * Lightbox
	 **************************************************************************/
	
	$("a[rel^='prettyPhoto']").live('mouseover', function() {
		$("a[rel^='prettyPhoto']").prettyPhoto({
			theme: 'light_square'
		});
	});
	
	$("#btnbewerben").click(function() {
		$("div#rueckruf").slideUp('slow', function() {
			$("div#bewerben").slideToggle("slow");						
		});
	});
	
	$("#btnrueckruf").click(function() {
		$("div#bewerben").slideUp('slow', function() {
			$("div#rueckruf").slideToggle("slow");						
		});
	});	
	
	$('input#verfuegbarkeit').datepicker({
		dateFormat: 'dd.mm.yy',
		showOn: 'button',
		buttonImageOnly: true,
		buttonImage: 'fileadmin/quest/images/btn_cal.gif',
		changeYear: true,
		changeMonth: true,
		showButtonPanel: true,
		showWeek: true, 
		firstDay: 1,
		buttonText: '',
		weekHeader: 'KW',
		yearRange: 'c-10:c+10',
		dayNames: ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'],
		dayNamesMin: ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'],
		dayNamesShort: ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'],
		monthNames: ['Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'],
		monthNamesShort: ['Jan', 'Feb', 'Mär', 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dez']
	});
	
	
	/***************************************************************************
	 * Sonst.
	 **************************************************************************/
	
	$('.detail, .ref, .detail2').each(function() {
		// speichert das aktuelle Linkziel
		var temp = $(this).attr('href');
	
		// filtert die zu übernehmenden Parameter heraus
		var lang = new RegExp("L=.", "gi");
		var lang_part = lang.exec(temp);
		var ref = new RegExp("ref=[0-9]*", "gi");
		var ref_part = ref.exec(temp);
	
		// erzeugt die neue URL
		var result;
		result  = "index.php?id=106";
		result += "&"+lang_part;
		result += "&"+ref_part;
		result += "&iframe=true&height=650&width=715";		
				
		if($(this).attr('class') == 'detail2') {
			$(this).attr('rel', 'prettyPhoto[job2]');
		} else {
			$(this).attr('rel', 'prettyPhoto[job]');
		}
		$(this).attr('href', result+'');  
		
	});			
	
	$('.tooltip').tooltip({ 
	    delay: 0, 
	    showURL: false, 
	    showBody: " - ", 
	    fade: 250,
	    top: 5, 
	    left: 15 
	});

});



function cpassword(log_form) {
	//alert(jQuery(log_form).find('#user').val());
	jQuery(log_form).find('#pass').val(jQuery(log_form).find('#pass_temp').val()); 
	jQuery(log_form).find('#pass_temp').val(''); 
    //jQuery('#pass').val(jQuery('#pass_temp').val()); 		//Klartextpasswort wird in das hiddenfield kopiert	
    //jQuery('#pass_temp').val(''); 						//Klartextpasswort wird auf leeren String gesetzt
    tx_rsaauth_feencrypt(log_form); 						//rsa Funktion wird aufegrufen
    return true;
}



