function f(){
	
}
Shadowbox.init({

    
    language:   "de-DE",
    players: ["qt", "flv", "img"]
});

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_close_pop(box){
	$("#"+box).slideUp(500, function(){
		$("#pop").hide();
	});
	
}

function aivao_play(id, soundfile){
	var arr = soundfile.split(".");
	var end = arr[(arr.length-1)];
	if(end == "mp3"){
		if($("#ref_"+id).find(".img_bt").is(".img_bt_stop")){
			$("#ref_"+id).find(".img_bt").removeClass("img_bt_stop");
			$("#iframe_player").attr("src", "/cms/pix/x.gif");
		}
		else{
			$("#margin1").find(".ref").each(function(){
				$(this).find(".img_bt").removeClass("img_bt_stop");
			});
			$("#ref_"+id).find(".img_bt").addClass("img_bt_stop");
			
			$("#iframe_player").attr("src", "/cms/front/flash/player.php?mp3="+soundfile);
		}
	}
	else if(end == "m4v" || end == "qt" || end == "mov" || end == "avi"){
			$("#iframe_player").attr("src", "/cms/pix/x.gif");
			$("#margin1").find(".ref").each(function(){
				$(this).find(".img_bt").removeClass("img_bt_stop");
			});
			Shadowbox.open({
				content:["/files/media/sound/"+soundfile],
				player:"qt",
				title:"",
				width:640,
				height:360
			});
			
			
	}
	else if(end == "flv"){
			$("#iframe_player").attr("src", "/cms/pix/x.gif");
			$("#margin1").find(".ref").each(function(){
				$(this).find(".img_bt").removeClass("img_bt_stop");
			});
			Shadowbox.open({
				content:["/files/media/sound/"+soundfile],
				player:"flv",
				title:"",
				width:640,
				height:360
			});
			
			
	}
}

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 aivao_show_pop(){
	$(".pop_bg").css({ 
		"top" : "0"
	});
	$("#pop").css({ 
		"top" : $(window).scrollTop()+"px"
	});

	$("#pop").show();
}



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

function aivao_alert(str){
	$("#alert_txt").html(str);
	$("#alert").fadeIn(100);
}


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

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

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_refresh_capcha("register");
	aivao_refresh_capcha("reggroup");
	aivao_refresh_capcha("regclass");
	aivao_refresh_capcha("freunde");
	*/
	$("#main-pane").jScrollPane({animateTo:true, animateInterval:50, animateStep:3});
	
	$("#margin1-pane").jScrollPane({animateTo:true, animateInterval:50, animateStep:3});
	
	$("#margin2-pane").jScrollPane({animateTo:true, animateInterval:50, animateStep:3});
	
	$(window).scroll(function () { 
		if($("#pop").is(":visible")){
      		$(".pop_bg").css({ 
				"top" : $(window).scrollTop()+"px"
			});
      	}
    });
    
    

	$(".navbt").hover(
		function () {			
			var newimg = String($(this).find("img").attr("src"));
			newimg = newimg.replace(/\.gif/, "_over.gif");
			$(this).find("img").attr("src", newimg);
			
		}, 
		function () {
			var newimg = String($(this).find("img").attr("src"));
			newimg = newimg.replace(/_over\.gif/, ".gif");
			$(this).find("img").attr("src", newimg);
		}
	);

	$(".button_ok").hover(
		function () {			
			$(this).addClass("button_ok_hover");
		}, 
		function () {
			$(this).removeClass("button_ok_hover");
		}
	);
	$("#alert_okbutton .button_ok").click(
		function () {			
			aivao_close_alert();
		}
	);
	
  	$("#email_input").click(
  		
  		function () {			
  			$(this).removeClass("input_grey");
			if($(this).val() == "E-Mail"){
				$(this).val("");
			}
		}
	);
	
	$("#freunde > .bt").click(
  		
  		function () {	
  			aivao_freunde();
		}
	);
	
	var email_sent = false;
	$("#email .bt, #email .smallbt").click(
  		
  		function () {			
  			if(!email_sent){
				var str = $("#email_input").val();
				if(!my_checkmail(str)){
					aivao_alert("Bitte gib eine E-mail-Adresse ein.");
				}
				else{
					var options = {
						email:str
					};
					
					//$("#email .smallbt").hide();
					$("#email_input").val("E-mail Adresse wurde verschickt");
					
					$.post(urlstr+"cms/front/ajax/submit_email.php", options, function(data) {
						email_sent = true;
						
							
						
					}, "text");
				}
			}
		}
	);
	
	
	var polanum = 0;
	$(".table_polaroid > tbody > tr > td").each(function (){ 
		//alert(polanum);
		polanum++;
		var num = polanum;
		while(num > 3){
			num -= 3;
		}
		var tesastr = "<div class=\"bildtesa"+num+" fix_ie";
		if(!multipages){
			tesastr += " bildtesa"+num+"_moveup";
		}
		tesastr += "\"></div>";
		$(this).prepend(tesastr);
	});
	$("#email .bt").hover(
		function () {			
			$(this).addClass("bt_over");
		}, 
		function () {
			$(this).removeClass("bt_over");
		}
	);

	$("a.link_pdf_list").each(function (){ 
		var link = $(this);
		$.post(aivao_addpath+"/cms/front/ajax/filesize.php", {file:$(this).attr("href")}, function(data) {
			//alert(data["filesize"]);
			link.append(data["filesize"]);
		}, "json");
		
	});
	/*
	var n=0;
	var str = $("#content").html();
	
	var num = (str.split("<a name").length - 1);
	$("#content").find("a").each(function (){ 
		if($(this).attr("name")){
			var addon = "";
			if(n == 0){
				addon = " class=\"on\"";
			}
			$("#navi > div").append("<a href=\"javascript:f()\" onclick=\"aivao_jumpto('main-pane', '"+$(this).attr("name")+"', "+n+")\" id=\"navi_a_"+n+"\""+addon+">"+$(this).attr("name")+"</a>");
			n++;
			if(n < num){
				$("#navi > div").append(": ");
			}
		}
		if($(this).attr("href")){
			if($(this).attr("href").indexOf("/files/downloads/") > -1){
				
				var link = $(this);
				//alert($(this).attr("href"));
				$.post(aivao_addpath+"/cms/front/ajax/filesize.php", {file:$(this).attr("href")}, function(data) {
					//alert(data["filesize"]);
					link.append(data["filesize"]);
				}, "json");
			}
		
			if($(this).attr("href").indexOf("[") > -1 && $(this).attr("href").indexOf("]") > -1){
				
				var link = $(this);
				
				$.post(aivao_addpath+"/cms/front/ajax/loclinks.php", {href:link.attr("href"),location_id:location_id,language_id:language_id}, function(data) {
					//alert(data["href"]);
					link.attr({"href":data["href"]});
		
				}, "json");
			}
		}
	});
	*/
});

