//var active_questionaire_tab = 1;
$(document).ready(function(){
		
		$("#faq_search").focus(function (){
				$(this).attr("value", "");
		});
		
		$(".div-searchbox-results-pil").toggle(function (){
				$(this).parent().find(".div-searchbox-results-text").slideDown("fast");
				//$(this).find("img").attr("src", "fileadmin/templates/page/images/search_arrow_down.gif");
		},function(){
			$(this).parent().find(".div-searchbox-results-text").slideUp("fast");
			//$(this).find("img").attr("src", "fileadmin/templates/page/images/search_arrow_left.gif");
		});
		/*
		$(".div-searchbox-results-row").click(function (){
		window.location=$(this).find("a").attr("href");
		});
		*/	
		$(".div-questionaire-tab").click(function(){
				$(".div-questionaire-tab-act").removeClass("div-questionaire-tab-act");
				$(this).addClass("div-questionaire-tab-act");
				$(this).parent().parent().find(".div-questionaire-cnt").css("display","none");
				$(this).parent().parent().find("#div-questionaire-cnt"+$(this).attr("tab")).css("display","block");
		});
		$(".div-questionaire-tab:first").addClass("div-questionaire-tab-act");
		$(".div-questionaire-cnt:first").css("display","block");
		
		$(".div-searchprofile-tab").click(function(){
				$(this).parent().find(".div-searchprofile-tab-inner-act,.div-searchprofile-tab-inner").attr("class","div-searchprofile-tab-inner");
				$(this).find(".div-searchprofile-tab-inner").attr("class","div-searchprofile-tab-inner-act");
				//$(this).parent().parent().find(".div-searchprofile-tabcontent").css("display","none");
				$(this).parent().parent().find(".div-searchprofile-tabcontent-act,.div-searchprofile-tabcontent").attr("class","div-searchprofile-tabcontent");
				//$(this).parent().parent().find("#div-searchprofile-tab"+$(this).attr("tab")).css("display","block");
				$(this).parent().parent().find("#div-searchprofile-tab"+$(this).attr("tab")).attr("class","div-searchprofile-tabcontent-act");
		});
		//$(".div-searchprofile-tab:first").find(".div-searchprofile-tab-inner").attr("class","div-searchprofile-tab-inner-act");
		//$(".div-searchprofile-tabcontent:first").css("display","block");
		
		//$("#ul-edit-management-list li").height($("#ul-edit-management-list li").height());
		if($("#ul-edit-management-list")){
			$("#ul-edit-management-list").sortable({
					handle : '.div-edit-management-handle',
					update : function(){
						arrange_management_members();
					}
			});
		}
/*
		$("#div-add-management-team-member a").click(function(){
				var n = $("#ul-edit-management-list li").length + 1;
				//$("#ul-edit-management-list").append('<li><div class="div-edit-management-row"><div class="div-edit-management-row-inner"><input type="hidden" name="tx_bee3tcg_pi8[team]['+n+'][uid]" value="0" /><input type="hidden" name="tx_bee3tcg_pi8[team]['+n+'][sort]" value="'+n+'" /><div class="div-edit-management-handle"><img src="/fileadmin/templates/page/images/move.gif" /></div><div class="div-edit-management-delete"><img src="/fileadmin/templates/page/images/delete.gif" /></div><div class="div-clr"></div><div class="div-edit-management-img"><a href="#"><img src="/fileadmin/templates/page/images/management_thumb.gif" border="0" /></a></div><div class="div-edit-management-title">Title</div><div class="div-edit-management-field"><input type="text" name="tx_bee3tcg_pi8[team]['+n+'][title]"></div><div class="div-edit-management-name">Name</div><div class="div-edit-management-field"><input type="text" name="tx_bee3tcg_pi8[team]['+n+'][name]"></div><div class="div-edit-management-video">Video</div><div class="div-edit-management-field"><input size="13" type="file" name="tx_bee3tcg_pi8[team]['+n+'][video]"></div><div class="div-edit-management-cv">CV</div><div class="div-edit-management-field"><input size="13" type="file" name="tx_bee3tcg_pi8[team]['+n+'][cv]"></div><div class="div-clr"></div></div></div></li>');
				$("#ul-edit-management-list").append('<li><div class="div-edit-management-row"><div class="div-edit-management-row-inner"><input type="hidden" name="tx_bee3tcg_pi8[team]['+n+'][uid]" value="0" /><input type="hidden" name="tx_bee3tcg_pi8[team]['+n+'][sort]" value="'+n+'" /><div class="div-edit-management-handle"><img src="/fileadmin/templates/page/images/move.gif" /></div><div class="div-edit-management-delete"><img src="/fileadmin/templates/page/images/delete.gif" /></div><div class="div-clr"></div><div class="div-edit-management-img"><a href="#"><img src="/fileadmin/templates/page/images/management_thumb.gif" border="0" /></a></div><div class="div-edit-management-name">Name</div><div class="div-edit-management-field"><input type="text" name="tx_bee3tcg_pi8[team]['+n+'][name]"></div><div class="div-edit-management-title">Title</div><div class="div-edit-management-field"><input type="text" name="tx_bee3tcg_pi8[team]['+n+'][title]"></div><div class="div-clr"></div></div></div></li>');
				$(".div-edit-management-delete").click(function(){
						delete_management_member($(this));
				});
				return false;
		});
		$(".div-edit-management-delete").click(function(){
				delete_management_member($(this));
		});
*/

	$("input").mousedown(function(){
		//this.style.backgroundColor = "#00ff00";
		this.focus();
	});


});
$(function() {
		$(window).bind('resize', function() {
				preview_player_arrange();
				popup_arrange();
		}).trigger('resize');
		$(window).bind('scroll', function() {
				preview_player_arrange();
				popup_arrange();
		}).trigger('scroll');
});
function preview_player_arrange(){
	$("#div-lightbox-mov").css("left", ($(document).width()-395)/2);
	$("#div-lightbox-mov").css("top", (($(window).height()-295)/2)+$(document).scrollTop());
	if ($("#table-container").height() > $(document).height()){
		$(".div-lightbox-overlay").height($("#table-container").height());
	}else{
		$(".div-lightbox-overlay").height($(document).height());
	}
}
function preview_player_remove(){
	$("#div-lightbox-mov").remove();
	$(".div-lightbox-overlay").remove();
}
function preview_player(player_src, player_vars){
	$("body").prepend('<div id="div-lightbox-mov"></div>');
	$("#div-lightbox-mov").flash(
		{
			src: player_src,
			width: 335,
			height: 230,
			wmode: "transparent",
			flashvars: { playlisturl: player_vars }
		},
		{ version: 7 }
		);
	$("body").prepend('<div class="div-lightbox-overlay"></div>');
	preview_player_arrange();
	$(".div-lightbox-overlay").click(function(){
			preview_player_remove();
	});
	return false;
}
function popup_arrange(){
	$("#div-lightbox-popup").css("left", ($(document).width()-$("#div-lightbox-popup").find("iframe").width())/2);
	$("#div-lightbox-popup").css("top", (($(window).height()-$("#div-lightbox-popup").find("iframe").height())/2)+$(document).scrollTop());
	if ($("#table-container").height() > $(document).height()){
		$(".div-lightbox-overlay").height($("#table-container").height());
	}else{
		$(".div-lightbox-overlay").height($(document).height());
	}
}

function accept_terms() {
	if ($("#acceptterms").attr("checked")){
		$("#fake-continue-button").css("display", "none");
		$("#continue-button").css("display", "block");
	}
	else {
		$("#fake-continue-button").css("display", "block");
		$("#continue-button").css("display", "none");
	}
}


function popup_remove(){
	
	//UGLY selectbox fix for the bastard IE browser
	if (jQuery.browser.msie) {
		if(parseInt(jQuery.browser.version) == 6) {
			$("select").each(function(i){
					$(this).css("display", "block");
			});
		}
	}
	
	$("#div-lightbox-popup").remove();
	$(".div-lightbox-overlay").remove();
//	$("#tx-bee3tcg-pi8-country").focus();
}

function popup_request_win(popup_src, popup_width, popup_height){
	
	//UGLY selectbox fix for the bastard IE browser
	if (jQuery.browser.msie) {
		if(parseInt(jQuery.browser.version) == 6) {
			$("select").each(function(i){
					$(this).css("display", "none");
			});
		}
	}
	$("body").prepend('<div id="div-lightbox-popup"></div>');
	$("#div-lightbox-popup").html('<div id="div-lightbox-popup-inner" style="width: ' + popup_width + 'px; height: ' + popup_height + 'px;"><img src="/fileadmin/templates/page/images/requestsender-wait.gif" width="220" height="19" border="0" /></div>');
	//$("#div-lightbox-popup").html('<div src="'+popup_src+'">);
	$("body").prepend('<div class="div-lightbox-overlay"></div>');
	popup_arrange();
	$(".div-lightbox-overlay").click(function(){
			popup_remove();
	});
	$("#div-lightbox-popup-close").click(function(){
			popup_remove();
	});
	$("#div-lightbox-popup-inner").load(popup_src + ' div.div-sendrequest-failure, div.div-sendrequest-success');
	
	return false;
}


function popup_win(popup_src, popup_width, popup_height){
	
	//UGLY selectbox fix for the bastard IE browser
	if (jQuery.browser.msie) {
		if(parseInt(jQuery.browser.version) == 6) {
			$("select").each(function(i){
					$(this).css("display", "none");
			});
		}
	}

	var iframe_height = popup_height - 30;
	$("body").prepend('<div id="div-lightbox-popup"></div>');
	$("#div-lightbox-popup").html('<iframe src="'+popup_src+'" width="'+popup_width+'" height="'+iframe_height+'" frameborder="0" scrolling="auto" allowTransparency="true"></iframe><div id="div-lightbox-popup-close" style="align: right;"><img src="fileadmin/templates/page/images/close_popup.gif"></div>');
	//$("#div-lightbox-popup").html('<div src="'+popup_src+'">);
	$("body").prepend('<div class="div-lightbox-overlay"></div>');
	popup_arrange();
	$(".div-lightbox-overlay").click(function(){
			popup_remove();
	});
	$("#div-lightbox-popup-close").click(function(){
			popup_remove();
	});
	return false;
}
function delete_management_member(obj){
	var obj_id = $(obj).parent().find("input[name^='tx_bee3tcg_pi8[team]['][name$='][uid]']").val();
	
	if($("#f_management_deleted").val() == "" && obj_id != 0){
		$("#f_management_deleted").val(obj_id);
	}else if(obj_id != 0){
		$("#f_management_deleted").val($("#f_management_deleted").val()+","+obj_id);
	}
	$(obj).parent().parent().parent().remove();
	arrange_management_members();
	// #tx_bee3tcg_pi8[team]_deleted
}
function arrange_management_members(){
	$("#ul-edit-management-list li").each(function(i){
			$(this).find("input[name^='tx_bee3tcg_pi8[team]['][name$='][uid]']").attr("name","tx_bee3tcg_pi8[team]["+i+"][uid]");
			$(this).find("input[name^='tx_bee3tcg_pi8[team]['][name$='][sort]']").attr("name","tx_bee3tcg_pi8[team]["+i+"][sort]").val(i);
			$(this).find("input[name^='tx_bee3tcg_pi8[team]['][name$='][title]']").attr("name","tx_bee3tcg_pi8[team]["+i+"][title]");
			$(this).find("input[name^='tx_bee3tcg_pi8[team]['][name$='][name]']").attr("name","tx_bee3tcg_pi8[team]["+i+"][name]");
			$(this).find("input[name^='tx_bee3tcg_pi8[team]['][name$='][video]']").attr("name","tx_bee3tcg_pi8[team]["+i+"][video]");
			$(this).find("input[name^='tx_bee3tcg_pi8[team]['][name$='][cv]']").attr("name","tx_bee3tcg_pi8[team]["+i+"][cv]");
	});
}

function toggleQuestionDisplay(nr) {
	$("#questionaire"+nr).slideToggle('normal');
}

function doPreview() {
	// clone each form field and rename the clones to the proper preview prefix
	$("[name^=tx_bee3tcg_pi8]").clone().each(function() {
		$(this).attr("name", $(this).attr("name").replace("tx_bee3tcg_pi8", "tx_bee3tcg_pi16"))
	}).appendTo("#previewform");

	return false;
}


function submitOnpi11() {
	
	
	$('#inputs').hide('fast');
	$('#progressbar').show('fast');
	
}












