try { console.debug('console init...'); } catch(e) { console = { debug: function(){}, log: function(){} };}

		
function hideallbodydiv() {
	$('body > div').hide();
	$('#ie6text').show();
}

var currentview="";

var weiterleitungstartsw = 0;
var weiterleitungdur = 5000;

function willkommen() {
	//Weiterleitung nach x Sekunden
	window.setTimeout("weiterleitungstart()", weiterleitungdur);

	hideallbodydiv();
	$('body > div.start_klinker').show();
	$('body').addClass('start_seite');
	if ($.history.callback) {
		$.history.load('willkommen');
	}
}

function weiterleitungstart() {
	if (weiterleitungstartsw == 0) {
		buch();
	}
}

var weiterleitungsw = 0;

function weiterleitung() {
	if (weiterleitungsw == 0) {
		buchinhalt();
	}
}

function buch() {
	weiterleitungstartsw = 1;
	//Weiterleitung nach x Sekunden
	window.setTimeout("weiterleitung()", weiterleitungdur);
	
	hideallbodydiv();
	$('body > div.start_text').show();
	$('body > div.main_start').show().css("background","url('img/buchzu.png') 390px 0px no-repeat");
	$('body').addClass('start_seite');
	if ($.history.callback) {
		$.history.load('buch');
	}
}

function buchinhalt() {
	
	hideallbodydiv();
	$('body').removeClass('start_seite');
	$('body > div#sprechblase').show();
	$('body > div.pagewrap').show();
	if (weiterleitungsw == 0) {
		$.history.load('inhalt');
		weiterleitungsw = 1;
	}
}

function buchende() {
	hideallbodydiv();
	$('body').addClass('start_seite');
	$('body > div.bodybuchende').show();
	if ($.history.callback) {
		$.history.load('buchende');
	}
}

function activate_tab(tab,notab) {
	var tabs = ['inhalt','newsletter','aktuelles','anmeldung','impressum'];

	if (notab == 1) {
		for ( var i in tabs ) {
			$('#tab_'+tabs[i]).css("background-image",'url("img/tab_'+tabs[i]+'.png")');
		}
	} else {
		for ( var i in tabs ) {
			$('#tab_'+tabs[i]).css("background-image",'url("img/tab_'+tabs[i]+( tabs[i] == tab ? '_active' : '' )+'.png")');
		}
	}

}

$(document).ready(function () {

	var forward_only = 0;
	
	if ($.browser.msie && parseFloat($.browser.version) < 8) {
		forward_only = 1;
	} 

	$('#book').stoneflip({
		forward_only: forward_only
	});
	
	$.history.init(function(hash){
		// console.log('history callback: '+hash);
		if (hash) {
			if (hash == 'buch') {
				buch();
			} else if (hash == 'buchende') {
				buchende();
			} else if (hash == 'willkommen') {
				willkommen();
			} else {
				buchinhalt();
//				$('#book').trigger('gotopage', [ $('#inhalt'), 1 ]);
				$('#book').trigger('history', [ $('#'+hash) ]);
			}
		} else {
			willkommen();
		}
	});

	$('div.start_text, div.backtobook').click(function() {
		if ($.history.callback) {
			$.history.load('inhalt');
		}
		buchinhalt();
	});
	
	$('div.etikett').click(function() {
		buch();
	});
	
});
	
	var openbubble="";
	
	var bubble_opened="";
	var pages_style=new Array();
	var farbe="#d2232a";
	var currentview="";
	
	
	function sprechblase(x,y,t1,t2,tp,farbe) {
	
		hidefullbubble();
		bubble_opened=x;
		currentview=x;
		$("#pdflink1").attr("href", "pdf/"+currentview+".pdf");
		$("#pdflink2").attr("href", "pdf/"+currentview+".pdf");
	
	
		/* NST */
		$('div.pagewrap > div.main').fadeOut();
		/*
		var e=document.getElementById("buchfull");
		e.style.visibility="hidden";
		var e=document.getElementById("myBook");
		e.style.visibility="hidden";
		for(var i=0;i<counter;i++){
			if (e=document.getElementById("flipPage"+i)) {
				pages_style[i]=e.style.visibility;
				e.style.visibility="hidden";
			}
		}
		
		*/
		
		var e=document.getElementById("sprechblase_"+x);
		e.style.visibility="visible";
		
		var e=document.getElementById("spb_title1");
		e.innerHTML=t1;
		e.style.backgroundColor=farbe;
		
		var e=document.getElementById("spb_chapter");
		e.style.backgroundColor=farbe;
		
		var e=document.getElementById("spb_line");
		e.style.borderColor=farbe;
		
		var e=document.getElementById("spb_title2");
		e.innerHTML=t2;
		e.style.color=farbe;
		
		var e=document.getElementById("sprechblase");
		e.style.visibility="visible";
		
		showbubble(y,tp);
		
	
	}
	
	function showbubble(x,tp) {
	
	
		var e=document.getElementById("thebubbletext");
		e.innerHTML=x;
		
		e.style.top=tp+"px";

		var e=document.getElementById("thebubble");	
		if (x!="") {
			e.style.visibility="visible";
		} else {
		e.style.visibility="hidden";
		}		
	}
	
	function hidebubble() {
	
		$(".sprechblase").css("visibility", "hidden");

		
	}
	
	function hidefullbubble() {
	
		hidebubble();
		if (e=document.getElementById("buchfull")) {
			e.style.visibility="visible";
		}
		
		
		/* NST */
		$('div.pagewrap > div.main').fadeIn();
		/*
		if (e=document.getElementById("myBook")) {
			e.style.visibility="visible";
		}
		for(var i=0;i<counter;i++){
			if (e=document.getElementById("flipPage"+i)) {
				if (pages_style[i]!=undefined) {
					
					e.style.visibility=pages_style[i];
				}
			}
		}
		*/
		if (e=document.getElementById("sprechblase_"+bubble_opened)) {
			e.style.visibility="hidden";
		}
		
		
		if (e=document.getElementById("sprechblase")) {
			e.style.visibility="hidden";
		}
		
		
		//Alle Meilensteinsprechblasen-Text auch mit ausblenden (wegen dem neuen Paging)
		$("*[id*=sprechblase_durchbruch_meilensteine_2011]").css("visibility", "hidden");
			
	}
	
	var subname="";
	var parentname="";

	function subbubble(subname, parentname) {
	
		currentview=subname;
		$("#pdflink1").attr("href", "pdf/"+currentview+".pdf");
		$("#pdflink2").attr("href", "pdf/"+currentview+".pdf");

		var mstnew=document.getElementById(subname);
		mstnew.style.visibility="visible";

		openbubble=subname;
		
		var e=document.getElementById(parentname);
		e.style.visibility="hidden";
		
	}

	function closesubbubble(subname, parentname) {

		currentview=parentname;
		$("#pdflink1").attr("href", "pdf/"+currentview+".pdf");
		$("#pdflink2").attr("href", "pdf/"+currentview+".pdf");
		
		var mstnew=document.getElementById(subname);
		mstnew.style.visibility="hidden";
		
		openbubble=parentname;

		var e=document.getElementById(parentname);
		e.style.visibility="visible";
	}
	
	function closebubblejump(dahin) {

		hidefullbubble();
		$('#book').trigger('gotopage', [ $(dahin) ]);
	}

	function bubblejump(a,b,c,d,e,f) {
	
		hidefullbubble();
		sprechblase(a,b,c,d,e,f);
	}
	
	var seminare="";
	
	function in_array(item,arr) {
		for(p=0;p<arr.length;p++) {
			if (item == arr[p]) {
				return true;
			}
		}
		return false;
	}
	
	function seminar_add(x) {
	
		var es=seminare.split("\n");
		
		if (!in_array(x,es)) {
			if (seminare!="") {
				seminare+="\n";
			}
			seminare+="- "+x;
			
			document.seminarform.seminar.value=seminare;
			
		}
		
		/* NST
		autoFlip(39);
		*/
		$('#book').trigger('gotopage', [ $('#anmeldung_2') ]);
	
	
	}
	
	var offsetx=20
	var offsety=0


	
function InfoBoxAusblenden() {
    $('#infobox').hide();
}
function InfoBoxAnzeigen(dump, text, offsetX, offsetY) {
    $('#infobox').show();
    $(document).mousemove(function(e){
        $('#infobox').css("left",e.pageX + offsetX + "px");
        $('#infobox').css("top",e.pageY + offsetY + "px");
        $('#infobox').html(text);
    });
}
