function f(){
	
}
/*
Shadowbox.init({

    
    language:   "de-DE",
    players: ["qt", "flv", "img"],
    counterType: "skip",
	continuous: true,
	counterLimit: 30,
	autoDimensions: true,
	useSizzle: false
});
*/
function aivao_catch_a(){
	$("a").click(function(e){
		if($.trim($(this).attr("href")) == "#"){
		 	e.preventDefault();
		}
	});
}

function aivao_checkmail(str) {

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length-1
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   return false
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	    return false
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false
	}
	 if (str.indexOf(at,(lat+1))!=-1){
		return false
	 }
	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false
	 }
	 if (str.indexOf(dot,(lat+2))==-1){
		return false
	 }
	 if (str.indexOf(" ")!=-1){
		return false
	 }
	 return true					
}

var pnotify_please_wait = false;
var submitform = true;

function aivao_submitform(options){
	if(submitform){
		if(pnotify_please_wait){
			pnotify_please_wait.pnotify_display();
		}
		else{
			pnotify_please_wait = $.pnotify({
				pnotify_text: "Einen Moment bitte...",
				pnotify_notice_icon: 'picon picon-throbber',
				pnotify_hide: false,
				pnotify_closer: false,
				pnotify_opacity: .75,
				pnotify_history: false,
				pnotify_width: "150px"
			});
	
		}
		var grant = true;
		var error = "";
		
		$(".required").each(function(){ 
			if($(this).val() == ""){
				grant = false;
				error += $(this).attr("name")+"<br />";
				$(this).addClass("error");
			}
		});
		if(!grant){
			pnotify_please_wait.pnotify_remove();
			$.pnotify({
				pnotify_title: 'Bitte füllen Sie noch diese Felder aus:',
				pnotify_text: error,
				pnotify_type: 'error',
				pnotify_history: false
			});
		}
		else{
			if(!aivao_checkmail($("input[name='E-Mail']").val())){
				grant = false;
				pnotify_please_wait.pnotify_remove();
				$("input[name='E-mail']").addClass("error");
				$.pnotify({
					pnotify_title: 'Bitte geben Sie eine korrekte E-mail-Adresse an.',
					pnotify_text: '',
					pnotify_type: 'error',
					pnotify_history: false
				});
			}
			else{
				submitform = false;
				options["formvars"] = "";
				$("input").each(function(){
					options["formvars"] += $(this).attr("name")+"*#*"+$(this).val()+"._.";
				});
				$("textarea").each(function(){
					options["formvars"] += $(this).attr("name")+"*#*"+$(this).val()+"._.";
				});
				$("select").each(function(){
					options["formvars"] += $(this).attr("name")+"*#*"+$(this).val()+"._.";
				});
				options["formvars"] = options["formvars"].substr(0,(options["formvars"].length-3));
				$.post("/cms/front/ajax/"+options["form"]+".php", options, function(data) {
					pnotify_please_wait.pnotify_remove();
					if(data["grant"] < 1){
						
						$.pnotify({
							pnotify_title: data["title"],
							pnotify_text: data["text"],
							pnotify_type: 'error',
							pnotify_history: false

						});
					}
					else{
						if(options["form"] == "geld_spenden"){
							$(".form").html("<p>Vielen Dank für Ihre Spende.</p>");
						}
						else if(options["form"] == "kontakt"){
							$(".form").html("<p>Vielen Dank für Ihre Nachricht.</p>");
						}
					}
				}, "json");
			}
		}
	}
}

//-------------------------------- XXXXXXXXXXXX

function aivao_show_pop(){
	$("#pop").css({ 
		"top" : $(window).scrollTop()+"px"
	});
	
	$("#pop_bg").css({ 
		"height" : $("body").height()+400+"px"
	});
	
	$("#pop_bg").show();
	$("#pop").show();
}

function aivao_close_pop(options){
	
	$("#pop > .box").hide();
	$("#pop").hide();
	$("#pop_bg").hide();
	$("#pop > .box > .content").empty();
	
}

function aivao_refreshpop(options){
	if(!$("#pop").is(":visible")){
		aivao_show_pop();
		$("#pop > .box").fadeIn(500);
	}
}

//-------------------------------- XXXXXXXXXXXX

function aivao_alert(options){
	var h = 152;
	$("#alert .content .ok").hide();
	$("#alert .content .cancel").hide();
	if(options["okbutton"]){
		$("#alert .content .ok").show();
	}
	if(options["cancelbutton"]){
		$("#alert .content .cancel").show();
	}
	
		$("#alert .content .ok").click(
			function() {
				if(options["okfunction"] != undefined){
					options["okfunction"].apply();
				}
			}
		);
	
	
		$("#alert .content .cancel").click(
			function() {
				if(options["okfunction"] != undefined){
					options["cancelfunction"].apply();
				}
			}
		);
	
	$("#alert .content .feedback").html(options["feedback"]);
	
	$("#alert .content").css({ 
		"top" : $(window).scrollTop()+200+"px"
	});
	$("#alert").fadeIn(100);
}


//-------------------------------- XXXXXXXXXXXX

function aivao_close_alert(){
	
	$("#alert").fadeOut(100, function(){
		$("#alert .content .feedback").html("");
	});
	
}


function aivao_login(options){
	$(".onemoment").show();
	options["username"] = $("input[name=username]").val();
	options["password"] = $("input[name=password]").val();
	$.post(aivao_addpath+"/cms/front/ajax/login.php", options, function(data) {
		if(data["grant"] < 1){
			$(".onemoment").hide();
			$(".errortext").html(data["errortext"]);
		}
		else{
			location.reload(true);
		}
	}, "json");

}
function aivao_logout(options){
	$.post(aivao_addpath+"/cms/front/ajax/logout.php", options, function(data) {
		location.reload(true);
	}, "json");

}

function aivao_play(options){
	if(options["format"] == "web"){
		
		Shadowbox.open({
			content:[options["file"]],
			player:"iframe",
			title:"",
			width:1020,
			height:660
		});
	}
	else if(options["format"] == "images"){
		var img_objects = [];
		for(n=0;n<options["file"].length;n++){
			img_objects[n] = {
				content:[options["file"][n]],
				player:"img",
				title:""
			};
		}
		Shadowbox.open(img_objects);
	}
	else{
		var arr = options["file"].split(".");
		var ext = arr[(arr.length)-1].toLowerCase();
		//alert(ext);
		if(ext == "pdf"){
				window.open("/files/media/video/"+options["file"],"awo_pdf");
	
				
				
		}
		else if(ext == "m4v" || ext == "mpg" || ext == "qt" || ext == "wmv" || ext == "mov" || ext == "avi" || ext == "mp4"){
				Shadowbox.open({
					content:["/files/media/video/"+options["file"]],
					player:"qt",
					title:"",
					width:640,
					height:360
				});
				
				
		}
		else if(ext == "mp3"){
				Shadowbox.open({
					content:["/files/media/video/"+options["file"]],
					player:"qt",
					title:"",
					width:640,
					height:1
				});
				
				
		}
		else if(ext == "flv"){
				$("#marginal_"+options["marginal"]).find(".flv").show();
				$("#marginal_"+options["marginal"]).find(".flv").flash(
					{ 
					  src: '/cms/flv/flv.swf',
					  width:384,
					  height:293,
					  flashvars: { movie: "/files/media/video/"+options["file"]}
					},
					{ version: 8 }
				);

				/*
				Shadowbox.open({
					content:["/files/media/video/"+options["file"]],
					player:"flv",
					title:"",
					width:640,
					height:360
				});
				*/
				
		}
	}
}

function aivao_navigategal(options){
	var act = -1;
	var next = -1;
	var total = $("#marginal_"+options["marginal"]).find(".imgs").children().length-1;
	$("#margin").find(".flv").empty();
	var n = 0;
	$("#marginal_"+options["marginal"]).find(".img").each(function (){ 
		if($(this).is(":visible")){
			act = n;
			if(options["mode"] == "arrow"){
				if(options["direction"] == "fwd"){
					if(n == (total-1)){
						next = 0;
					}
					else{
						next = n+1;
					}
				}
				else if(options["direction"] == "back"){
					if(n == 0){
						next = total-1;
					}
					else{
						next = n-1;
					}
				}
			}
		}
		n++;
	});
	if(options["mode"] == "number"){
		next = options["number"];
	}
	//alert(act+" "+next+" "+total);
	$("#marginal_"+options["marginal"]).find(".img_"+act).fadeOut(300);
	$("#marginal_"+options["marginal"]).find(".img_"+next).fadeIn(300);
}


function aivao_uppercase(str){
	
	str = str.toUpperCase();
	arr = [
		["ä", "Ä"], ["ö", "Ö"], ["ü", "Ü"], ["ü", "Ü"]
	];
	for(var n=0;n<arr.length;n++){
		str = str.replace(arr[n][0], arr[n][1]);
	}
	return str;
}
function aivao_jumpto(pane, name, num){
	var $pane = $("#"+pane);
	$pane[0].scrollTo("a[name='"+name+"']");
	$("#navi").find("a").each(function (){ 
		$(this).removeClass("on");
	});
	$("#navi_a_"+num).addClass("on");
}


function aivao_rnd(){ return String((new Date()).getTime()).replace(/\D/gi,'') }



function aivao_opengallery(imgs){


	$.slimbox(imgs, 0, {
		loop: true, 
		initialWidth:605, 
		initialHeight:350,
		counterText:"Bild {x} von {y}"
	});

}

function aivao_close_popalert(){
	$("#pop > .alert").hide();

	if($.browser.name == "msie" && $.browser.version < 7){
		$("#pop_register").find("select").each(function(){
			$(this).show();
		});
		$("#pop_register").find("input").each(function(){
			$(this).hide();
			$(this).show();
		});
	}
	$("#pop > .alert > .alerttxt > .feedback").empty();
	var keep = false;
	$("#pop").find("div").each(function(){
		if($(this).is(":visible") && !$(this).is(".pop_bg")){
			keep = true;
		}
	});
	if(!keep){
		$("#pop").hide();
	}
}





//-------------------------------- XXXXXXXXXXXX



function my_checkempty(mandatory) {

	for(n=0;n<mandatory.length;n++){
		if($("#"+mandatory[n]).val() == ""){
			return false
		}
	}
	 return true					
}

function my_checkmail(str) {

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length-1
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   return false
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	    return false
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false
	}
	 if (str.indexOf(at,(lat+1))!=-1){
		return false
	 }
	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false
	 }
	 if (str.indexOf(dot,(lat+2))==-1){
		return false
	 }
	 if (str.indexOf(" ")!=-1){
		return false
	 }
	 return true					
}



var loadimgs = ["/cms/pix/x.gif"];
for(var n=0;n<loadimgs.length;n++){
	$.preloadImages(loadimgs[n]);
}


$(function() {	
	
	aivao_catch_a();
	
});

