// FRKN 2010-06-07
jQuery.noConflict();

jQuery(document).ready(function(){
	init(0);
	
	jQuery("body").click(function(event) {
		// Klick in Fußzeile bei Startseite oder auf Logo
		if (jQuery(event.target).is('.footer_links_img_first') || jQuery(event.target).is('.logo')) {
			// var url = jQuery(event.target).parent().attr("href");
			// getContent(url, "#contentarea", "", 0);
			
			// Liane (Ursprung: 320), Background und Menü (Ursprung: 280) verschieben
			jQuery('#liane').animate({
				"left": "320"
			}, 2000);
			
			jQuery('#background').show(0);
			jQuery('#background img').animate({
				"right": "0"
			}, 2000);
			
			jQuery('.menu_parent').removeClass("active");
			jQuery('#menu_parents').show(0);
			jQuery('#menu_parents').animate({
				"left": "280",
				"top": "100"
			}, 2000);
			jQuery('#menu_parents li.fourth').css('margin-top','25px');
			jQuery('.menu_children').removeClass("active");
			jQuery('#menu_children').show(0);
			jQuery("#menu_children").animate({
				"left": "480",
				"top": "170"
			}, 2000);
			
			// Untermenüs Kinder ausblenden
			jQuery('#sub_menu_children_tiger').hide(0);
			jQuery('#sub_menu_children_tricks').hide(0);
			
			// Hintergrund Kinder ausblenden
			jQuery('#children_background img').animate({
				"right": "-1220"
			}, 2000);
			
			// Alte Inhalte ausblenden
			jQuery("#contentarea").hide(0);
			jQuery("#content_parents").hide(0);
			jQuery("#submenu_parents").hide(0);
			jQuery("#content_children").hide(0);
			jQuery("#submenu_children").hide(0);
			jQuery('#children_background img').hide(0);
			
			jQuery('#palme').show(0);
			jQuery('#palme img').animate({
				"right": "-250"
			}, 2000);
			
			jQuery('#fruechte_rechts').show(0);
			jQuery('#fruechte_rechts img').animate({
				"right": "-30"
			}, 2000);
			
			jQuery('#fruechte_links').show(0);
			jQuery('#fruechte_links img').animate({
				"left": "-250"
			}, 2000);
			
			jQuery('#tiger').show(0);
			jQuery('#tiger img').show(0);
			jQuery('#tiger img').animate({
				"right": "-180",
				"top": "-240"
			}, 2000);
			
			jQuery('#blatt').show(0);
			jQuery('#blatt img').show(0);
			jQuery('#blatt img').animate({
				"left": "20",
				"top": "180"
			}, 2000);
			
			jQuery('#teaser').show(0);
			jQuery('#teaser img').animate({
				"left": "0"
			}, 2000);
			
			jQuery('#teaser_game').show(0);
			jQuery('#teaser_game img').animate({
				"right": "0"
			}, 2000);
			
			jQuery('#teaser_cooking').show(0);
			jQuery('#teaser_cooking').animate({
				"left": "100"
			}, 2000);
			
			jQuery('#corner_heart').animate({
				"top": "0"
			}, 2000);
			
			jQuery('#corner_info').animate({
				"top": "0"
			}, 2000);
			
			jQuery('#corner_kids').animate({
				"top": "0"
			}, 2000);
			
			return false;
		}
		
		// Klick bei Eltern Menü oder Aktuelles
		if (jQuery(event.target).is('.menu_parent_img') || jQuery(event.target).is('.parents') || jQuery(event.target).parent().is('.parents') || (jQuery(event.target).is('.news') && jQuery(event.target).attr("target") != "_blank") || (jQuery(event.target).parent().is('.news') && jQuery(event.target).parent().attr("target") != "_blank") || jQuery(event.target).parent().is('.back_to_list') || jQuery(event.target).is('.map_parents')) {
			// URL ermitteln
			if (jQuery(event.target).is('.news') || jQuery(event.target).parent().is('.back_to_list') || jQuery(event.target).is('.parents') || jQuery(event.target).is('.map_parents')) {
				var url = jQuery(event.target).attr("href");
			} else {
				var url = jQuery(event.target).parent().attr("href");
				
				// Aktive Klasse setzen
				jQuery('.menu_parent').removeClass("active");
				jQuery(event.target).parent().addClass("active");
			}
			
			// Inhalte des Links auslesen
			getContent(url, "#contentarea", "60", 1, "parents");
			
			// Progress Bar einblenden
			if (nomsie == 1) {
				jQuery('#progressbar').show(0);
			}
			
			// Alle Kinder Elemente ausblenden
			jQuery("#tiger img").clearQueue();
			jQuery('#tiger img').stop().animate({
				"right": "-360",
				"top": "-480"
			}, 2000);
			
			jQuery("#blatt img").clearQueue();
			jQuery('#blatt img').stop().animate({
				"left": "-71",
				"top": "80"
			}, 2000);
			
			jQuery('#palme img').animate({
				"right": "-428"
			}, 2000);
			
			jQuery('#background img').animate({
				"right": "-540"
			}, 2000);
			
			// Untermenüs Kinder ausblenden
			jQuery('#sub_menu_children_tiger').hide(0);
			jQuery('#sub_menu_children_tricks').hide(0);
			
			// Hintergrund Kinder ausblenden
			jQuery('#children_background img').animate({
				"right": "-1220"
			}, 2000);
			
			// Menü (Ursprung: 480) verschieben
			jQuery('.menu_children').removeClass("active");
			jQuery("#menu_children").animate({
				"left": "955"
			}, 2000);
			
			// Alle Standard Elemente ausblenden
			jQuery('#fruechte_rechts img').animate({
				"right": "-606"
			}, 2000);
			
			jQuery('#fruechte_links img').animate({
				"left": "-536"
			}, 2000);
			
			jQuery('#teaser img').animate({
				"left": "-400"
			}, 2000);
			
			jQuery('#teaser_game img').animate({
				"right": "-351"
			}, 2000);
			
			jQuery('#teaser_cooking').animate({
				"left": "-180"
			}, 2000);
			
			// Liane (Ursprung: 320) und Menü (Ursprung: 280) verschieben
			jQuery('#liane').animate({
				"left": "800"
			}, 2000);
			
			jQuery('#corner_heart').animate({
				"top": "-174"
			}, 2000);
			
			jQuery('#corner_info').animate({
				"top": "-56"
			}, 2000);
			
			jQuery('#corner_kids').animate({
				"top": "-56"
			}, 2000);
			
			jQuery('#menu_parents').show(0);
			jQuery('#menu_parents').animate({
				"left": "740"
			}, 2000);
			jQuery('#menu_parents li.fourth').css('margin-top','0');
			
			// Alle Elemente verstecken
			setTimeout(function(){
				jQuery('#tiger').hide(0);
				jQuery('#tiger img').hide(0);
				jQuery('#blatt').hide(0);
				jQuery('#blatt img').hide(0);
				jQuery('#palme').hide(0);
				jQuery('#background').hide(0);
				jQuery('#menu_children').hide(0);
				jQuery('#fruechte_rechts').hide(0);
				jQuery('#fruechte_links').hide(0);
				jQuery('#teaser').hide(0);
				jQuery('#teaser_game').hide(0);
				jQuery('#teaser_cooking').hide(0);
				jQuery('#children_background img').hide(0);
			}, 2000);
			
			return false;
		}
		// Klick bei Kinder Menü
		if (jQuery(event.target).is('.menu_children_img') || (jQuery(event.target).is('.children') && jQuery(event.target).attr("target") != "_blank") || (jQuery(event.target).parent().is('.children') && jQuery(event.target).parent().attr("target") != "_blank")) {
			// URL ermitteln
			if (jQuery(event.target).is('.children')) {
				var url = jQuery(event.target).attr("href");
			} else {
				var url = jQuery(event.target).parent().attr("href");
				
				// Aktive Klasse setzen
				jQuery('.menu_children').removeClass("active");
				jQuery(event.target).parent().addClass("active");
			}
			
			// Inhalte des Links auslesen
			getContent(url, "#contentarea", "60", 1, "children");
			
			// Progress Bar einblenden
			if (nomsie == 1) {
				jQuery('#progressbar').show(0);
			}
			
			// Alle Eltern Elemente ausblenden
			jQuery("#tiger img").clearQueue();
			jQuery('#tiger img').stop().animate({
				"right": "-360",
				"top": "-480"
			}, 2000);
			
			jQuery("#blatt img").clearQueue();
			jQuery('#blatt img').stop().animate({
				"left": "-71",
				"top": "80"
			}, 2000);
			
			jQuery('#background img').animate({
				"right": "-540"
			}, 2000);
			
			// Menü (Ursprung: 480) verschieben
			jQuery('#menu_children').show(0);
			jQuery("#menu_children").animate({
				"left": "40"
			}, 2000);
			
			// Alle Standard Elemente ausblenden
			jQuery('#fruechte_rechts img').animate({
				"right": "-606"
			}, 2000);
			
			jQuery('#fruechte_links img').animate({
				"left": "-536"
			}, 2000);
			
			jQuery('#teaser img').animate({
				"left": "-400"
			}, 2000);
			
			jQuery('#teaser_game img').animate({
				"right": "-351"
			}, 2000);
			
			jQuery('#teaser_cooking').animate({
				"left": "-180"
			}, 2000);
			
			jQuery('#corner_heart').animate({
				"top": "-174"
			}, 2000);
			
			jQuery('#corner_info').animate({
				"top": "-56"
			}, 2000);
			
			jQuery('#corner_kids').animate({
				"top": "-56"
			}, 2000);
			
			// Liane (Ursprung: 320) und Menü (Ursprung: 280) verschieben
			jQuery('#liane').animate({
				"left": "-120"
			}, 2000);
			
			jQuery('#menu_parents').animate({
				"left": "-190"
			}, 2000);
			
			// Hintergrund einblenden
			jQuery('#children_background img').show(0);
			jQuery('#children_background img').animate({
				"right": "-60"
			}, 2000);
			
			// Alle Elemente verstecken
			setTimeout(function(){
				jQuery('#tiger').hide(0);
				jQuery('#tiger img').hide(0);
				jQuery('#blatt').hide(0);
				jQuery('#blatt img').hide(0);
				jQuery('#background').hide(0);
				jQuery('#menu_parents').hide(0);
				jQuery('#fruechte_rechts').hide(0);
				jQuery('#fruechte_links').hide(0);
				jQuery('#teaser').hide(0);
				jQuery('#teaser_game').hide(0);
				jQuery('#teaser_cooking').hide(0);
			}, 2000);
			
			return false;
		}
		
		// Klick für Lighbox in Fußzeile
		if (jQuery(event.target).hasClass('thickbox') || jQuery(event.target).parent().hasClass('thickbox')) {
			if (!(jQuery(event.target).parent().parent().parent().hasClass('quicklinks'))) {
				// stop default behaviour
				event.preventDefault();
				
				var caption = jQuery(event.target).parent().attr('title') || jQuery(event.target).parent().attr('name') || "";
				// get rel attribute for image groups
				var group = jQuery(event.target).parent().attr('rel') || false;
				// display the box for the elements href
				TB_show(caption, jQuery(event.target).parent().attr('href'), group);
				
				return false;
			}
		}
		
		// Klick Event für Submit Button
		if (jQuery(event.target).is('.submit')) {
			event.preventDefault();
			
			if (jQuery("#mailform").length || jQuery("#datamints_feuser_615_form").length) {
				if (jQuery("#mailform").length ) {
					url = jQuery('#mailform').attr('action') + "&formhandler[step-2]=Absenden";
					data = jQuery('#mailform').serialize();
					form = "mailform";
				}
				if (jQuery("#datamints_feuser_615_form").length ) {
					url = jQuery('#datamints_feuser_615_form').attr('action') + "&type=60";
					data = jQuery('#datamints_feuser_615_form').serialize();
					form = "datamints_feuser";
				}
				
				//send request
				jQuery.ajax({
					//erweitere aufzurufenden Link 
					url: url,
					type: "GET",
					data: data,
					dataType: "html",
					cache: false,
					//wenn es geklappt hat 
					success: function(html) {
						//Inhalt reinschreiben und anzeigen 
						if(parseInt(html)!=0) {
							jQuery('#contentarea').html(html);
							setTimeout(function(){
								if (form == "mailform") {
									jQuery('#content_parents div').eq(0).jScrollPane({showArrows:true, wheelSpeed:10});
									jQuery('#content_parents_small div').eq(0).jScrollPane({showArrows:true, wheelSpeed:10});
								}
								if (form == "datamints_feuser") {
									jQuery('#content_children div').eq(0).jScrollPane({showArrows:true, wheelSpeed:10});
									jQuery('#content_children_small div').eq(0).jScrollPane({showArrows:true, wheelSpeed:10});
									jQuery('#content_children_medium div').eq(0).jScrollPane({showArrows:true, wheelSpeed:10});
								}
							}, 3000);
						}
					},
					error: function (xhr, ajaxOptions, thrownError){
						alert("3: " + url);
						alert("3: " + xhr.status);
						alert("3: " + thrownError);
					}
				});
			} else {
				tigersubmit();
			}
			
			return false;
		}
	});
});

function getContent(url, content, type, fade, successaction) {
	url = jQuery.trim(url);
	
	if (type != "") {
		if (url.indexOf('370') > 0 || url.indexOf('401') > 0 || url.indexOf('403') > 0) {
			url = url+"&type=60";
		} else {
			if (url.slice(-1) == '/')
				url = url+"ajax/"+type;
			else
				url = url+"/ajax/"+type;
		}
	}
	
	jQuery.ajax({
		//erweitere aufzurufenden Link 
		url: url,
		type: "GET",
		data: 'page='+url,
		dataType: "html",
		cache: false,
		//wenn es geklappt hat 
		success: function(data) {
			//Inhalt reinschreiben und anzeigen 
			if(parseInt(data)!=0) {
				jQuery(content).html(data);
				// Einblenden
				if (fade)
					jQuery(content).fadeIn(); 
				// Progress Bar ausblenden
				if (nomsie == 1)
					jQuery('#progressbar').hide(0);
				// Eltern oder Kinder Aktionen
				if (successaction == "parents") {
					setTimeout(function(){
						jQuery('#content_parents div').eq(0).jScrollPane({showArrows:true});
						jQuery('#content_parents_small div').eq(0).jScrollPane({showArrows:true});
					}, 500);
					
					setTimeout(function(){
						if (jQuery('.map_sortiment').length) {
							jQuery('.map_sortiment').maphilight({fade: true});
						}
					}, 1000);
				}
				if (successaction == "children") {
					setTimeout(function(){
						// Submenü korrigieren
						SubmenuChildren();
						// Bubble wegklicken
						Bubble();
						jQuery('#content_children div').eq(0).jScrollPane({showArrows:true});
						jQuery('#content_children_small div').eq(0).jScrollPane({showArrows:true});
						jQuery('#content_children_medium div').eq(0).jScrollPane({showArrows:true});
						jQuery('#content_children_receipt div.csc-textpic').eq(0).jScrollPane({showArrows:true, scrollbarOnLeft: true});
						jQuery('.scrollable').scrollable();
					}, 500);
					
					setTimeout(function(){
						if (jQuery('.map_sortiment').length) {
							jQuery('.map_sortiment').maphilight({fade: true});
						}
					}, 1000);
					
					setTimeout(function(){
						jQuery('#children_bubble').animate({
							"top": "-286"
						}, 1000);
					}, 10000);
					
					if (jQuery("#referenzen").length) {
						var instanceOne = new ImageFlow();
						instanceOne.init({ 
							ImageFlowID: 'referenzen',
							reflections: false,
							reflectionGET: '&bgc=eeeeee',
							circular: true,
							xStep: 100,
							aspectRatio: 2.6,
							imagesHeight: 0.7,
							imagesM: 0.7,
							scrollbarP: 0.9,
							imageFocusM: 1,
							startAnimation: true,
							opacity: true,
							opacityArray: [10,8,6,4,2]
						});
					}
				}
				init(type);
			}
		},
		error: function (xhr, ajaxOptions, thrownError){
			alert("1: " + url);
			alert("1: " + xhr.status);
			alert("1: " + thrownError);
		}
	});
}

function init(type) {
/*
	if(type==60) {
		initLightbox();
	}
*/
}

// felogin Submit Verarbeitung
function tigersubmit() {
	url = jQuery('#felogin').attr('action');
	url = url.replace('de/kinder/tiger-klub/ajax/60 ?', 'index.php?id=404&type=60&L=0&');
	url = url.replace('de/kinder/login/ajax/60 ?', 'index.php?id=404&type=60&L=0&');
	data = jQuery('#felogin').serialize();
	
	//send request
	jQuery.ajax({
		//erweitere aufzurufenden Link 
		url: url,
		type: "GET",
		data: data,
		dataType: "html",
		cache: false,
		//wenn es geklappt hat 
		success: function(html) {
			//Inhalt reinschreiben und anzeigen 
			if(parseInt(html)!=0) {
				jQuery('#contentarea').html(html);
				setTimeout(function(){
					jQuery('#content_children div').eq(0).jScrollPane({showArrows:true});
					jQuery('#content_children_small div').eq(0).jScrollPane({showArrows:true});
					jQuery('#content_children_medium div').eq(0).jScrollPane({showArrows:true});
					jQuery('#content_children_receipt div.csc-textpic').eq(0).jScrollPane({showArrows:true});
				}, 3000);
				
				setTimeout(function(){
					jQuery('#children_bubble img').animate({
						"top": "-286"
					}, 1000);
				}, 10000);
				
				setTimeout(function(){
					jQuery('#children_bubble').hide(0);
				}, 11000);
			}
		},
		error: function (xhr, ajaxOptions, thrownError){
			alert("2: " + url);
			alert("2: " + xhr.status);
			alert("2: " + thrownError);
		}
	});
}
