jQuery.noConflict();

// MSIE 6/7 Erkennung
var msie6  = 0;
var msie7  = 0;
var msie8  = 0;
var nomsie = 0;
if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
	var ieversion=new Number(RegExp.$1);
	if (ieversion<7 && ieversion>=6) {
		msie6 = 1;
	} else {
		if (ieversion<8 && ieversion>=7) {
			msie7 = 1;
		} else {
			if (ieversion<9 && ieversion>=8) {
				msie8 = 1;
			}
		}
	}
} else {
	nomsie = 1;
}

// Zufallszahlen
function GetRandom( min, max ) {
	if( min > max ) {
		return( -1 );
	}
	if( min == max ) {
		return( min );
	}
	return( min + parseInt( Math.random() * ( max-min+1 ) ) );
}

// felogin Datenübertragung aus Flash
function tigerlogin(name, password) {
	jQuery('#user').val(name);
	jQuery('#pass').val(password);
	
	alert(name + " - " + password);
	alert(jQuery('#user').val() + " - " + jQuery('#pass').val());
	
	tigersubmit();
}

function libAGENTURNET() {
	jQuery('#agentur_net').hover(
		function() {
			jQuery(this).find('ul li ul').show('slow');
		},
		function() {
			jQuery(this).find('ul li ul').hide('slow');
		}
	);
	
	jQuery('#agentur_net').click(
		function() {
			//alert(jQuery(this).find('a').attr('href'));
			//window.parent.location = jQuery(this).find('a').attr('href');
			window.open(jQuery(this).find('a').attr('href'));
		}
	);
}

function libMENU_PARENTS() {
	// Tiger Animation
	/*
	jQuery('#tiger img').hover(function() {
		jQuery(this).animate({ 
			width: "700px",
			"right": "+=104px",
			"top": "+=54px"
		}, 1500);
	}, function() {
		jQuery(this).animate({ 
			width: "500px",
			"right": "-=104px",
			"top": "-=54px"
		}, 1500);
	});
	*/
	
	// Menü
	// Letzten Menüpunkt unten platzieren
	// jQuery("#menu_parents ul li").last().css('margin-top','100px');
	
	var blatttimeout;
	jQuery('#menu_parents ul li').hover(function() {
		clearTimeout(blatttimeout);
		var position_li    = jQuery(this).position();
		var offset_li      = jQuery(this).offset();
		var offset_content = jQuery('#content').offset();
		var position_menu  = jQuery('#menu_parents').position();
		var position_left  = position_li.left + position_menu.left - 50;
		var position_top   = offset_li.top - offset_content.top;
		
		if (position_menu.left == 280) {
			if (jQuery('#blatt').css('width') == "325px")
				var blatttime = 500;
			else
				var blatttime = 1500;
			
			jQuery('#blatt').stop().animate({ 
				width: "325px"
			}, blatttime);
			jQuery('#blatt img').stop().animate({ 
				width: "101px",
				height: "92px",
				"left": position_left + "px",
				"top": position_top + "px"
			}, blatttime);
		}
	}, function() {
		var position_menu  = jQuery('#menu_parents').position();
		if (position_menu.left == 280) {
			blatttimeout = setTimeout(function(){
				jQuery('#blatt').stop().animate({ 
					width: "280px"
				}, 1500);
				jQuery('#blatt img').stop().animate({ 
					width: "71px",
					height: "64px",
					"left": "20px",
					"top": "180px"
				}, 1500);
			}, 500);
		}
	});
	
/*
	jQuery('#menu_parents ul').hover(function() {
	}, function() {
		var position_menu  = jQuery('#menu_parents').position();
		if (position_menu.left == 280) {
			blatttimeout = setTimeout(function(){
				jQuery('#blatt').animate({ 
					width: "280px"
				}, 1500);
				jQuery('#blatt img').animate({ 
					width: "71px",
					height: "64px",
					"left": "20px",
					"top": "180px"
				}, 1500);
			}, 500);
		}
	});
*/
}

function libMENU_CHILDREN() {
	var tigertimeout;
	jQuery('#menu_children ul li').hover(function() {
		clearTimeout(tigertimeout);
		var position_li    = jQuery(this).position();
		var offset_li      = jQuery(this).offset();
		var offset_content = jQuery('#content').offset();
		var position_menu  = jQuery('#menu_children').position();
		var position_top   = offset_li.top - offset_content.top - 450;
		var position_left = 480 - position_li.left - position_menu.left;
		if (jQuery('#tiger').css('width') == "390px")
			var tigertime = 500;
		else
			var tigertime = 1500;
		
		jQuery('#tiger').stop().animate({ 
			width: "390px",
			height: "675px",
			"left": "605px"
		}, tigertime);
		jQuery('#tiger img').stop().animate({ 
			width: "480px",
			height: "574px",
			"left": position_left + "px",
			"top": position_top + "px"
		}, tigertime);
	}, function() {
		tigertimeout = setTimeout(function(){
			jQuery('#tiger').stop().animate({ 
				width: "280px",
				height: "400px",
				"left": "675px"
			}, 1500);
			jQuery('#tiger img').stop().animate({ 
				width: "455px",
				height: "503px",
				"right": "-180px",
				"top": "-240px"
			}, 1500);
		}, 500);
	});
	
/*
	jQuery('#menu_children ul').hover(function() {
		clearTimeout(tigertimeout);
	}, function() {
		tigertimeout = setTimeout(function(){
			jQuery('#tiger').animate({ 
				width: "280px",
				"left": "675px"
			}, 1500);
			jQuery('#tiger img').animate({ 
				width: "455px",
				height: "503px",
				"right": "-180px",
				"top": "-240px"
			}, 1500);
		}, 500);
	});
*/
	
	/*
	menu_space = 275;
	for (i=0; i<jQuery("#menu_parents ul li").length; i++) {
		r = GetRandom(20, 100);
		if (menu_space < r)
			r = menu_space;
		menu_space = menu_space - r;
		
		jQuery("#menu_parents ul li").eq(i).css('margin-top',r+'px');
	}
	
	menu_space = 135;
	for (i=0; i<jQuery("#menu_children ul li").length; i++) {
		r = GetRandom(20, 70);
		if (menu_space < r)
			r = menu_space;
		menu_space = menu_space - r;
		
		jQuery("#menu_children ul li").eq(i).css('margin-top',r+'px');
	}
	*/
}

function libSUB_MENU_CHILDREN() {
	// Menü
	jQuery('#menu_children li.first a').click(
		function() {
			setTimeout(function(){
				jQuery('#sub_menu_children_tiger').slideDown();
				jQuery('#sub_menu_children_tricks').slideUp();
				
				jQuery('#menu_children li.first').css({'height':'140px'});
			}, 2000);
		}
	);
	
	jQuery('#menu_children li.second a').click(
		function() {
			jQuery('#sub_menu_children_tiger').slideUp();
			jQuery('#sub_menu_children_tricks').slideUp();
			
			jQuery('#menu_children li.first').css({'height':'100px'});
		}
	);
	
	jQuery('#menu_children li.third a').click(
		function() {
			jQuery('#sub_menu_children_tiger').slideUp();
			jQuery('#sub_menu_children_tricks').slideUp();
			
			jQuery('#menu_children li.first').css({'height':'100px'});
		}
	);
	
	jQuery('#menu_children li.last a').click(
		function() {
			setTimeout(function(){
				jQuery('#sub_menu_children_tiger').slideUp();
				jQuery('#sub_menu_children_tricks').slideDown();
				
				jQuery('#menu_children li.first').css({'height':'100px'});
			}, 2000);
		}
	);
}

var sortimentshow = 0;

function BubbleOn(e) {
	jQuery('.children_sortiment').eq(e).show(0);
	jQuery('.children_sortiment').eq(e).stop().animate({
		"top": "20"
	}, 1000);
}

function BubbleOff(e) {
	jQuery('.children_sortiment').eq(e).stop().animate({
		"top": "-286"
	}, 1000);
}

function SubmenuChildren() {
	// Submenü vorhanden?
	if (jQuery('#submenu_children').length) {
		// Drei Menüpunkte
		if (jQuery('#submenu_children li li').length > 2) {
			liheight = jQuery('#submenu_children li li').eq(0).find('img').height() + 20;
			jQuery('#submenu_children li li').eq(2).css({'position':'absolute','top': liheight + 'px'});
		}
		// Vier Menüpunkte
		if (jQuery('#submenu_children li li').length > 3) {
			liheight = jQuery('#submenu_children li li').eq(1).find('img').height() + 20;
			jQuery('#submenu_children li li').eq(3).css({'position':'absolute','top': liheight + 'px','right':'0'});
		}
		
		// Vergrößerung bei Mouseover
		jQuery('#submenu_children li li img').hover(function(){
			liheight = jQuery(this).height() - 10;
			liwidth  = jQuery(this).width() - 10;
			jQuery(this).stop().animate({ 
				height: liheight + 'px',
				width: liwidth + 'px'
			}, 500);
		}, function(){
			liheight = jQuery(this).height() + 10;
			liwidth  = jQuery(this).width() + 10;
			jQuery(this).stop().animate({ 
				height: liheight + 'px',
				width: liwidth + 'px'
			}, 500);
		});
	}
}

function Bubble() {
	jQuery('#children_bubble').click(function() {
		jQuery('#children_bubble').animate({
			"top": "-286"
		}, 1000);
	});
}

function Comics() {
	jQuery('.next').click(function(){
		var items_length = jQuery('.items div').length - 1;
		if (jQuery('.items div').eq(items_length).hasClass('current')) {
		} else {
			var img_width = jQuery('.items').find('.current').find('img').width();
			var position = jQuery('.items').position();
			var position_new = position.left - img_width;
			jQuery('.items').find('.current').next().addClass('current');
			jQuery('.items').find('.current').eq(0).removeClass('current');
			jQuery('.items').animate({
				"left": position_new
			}, 1000);
			if (jQuery('.items div').eq(items_length).hasClass('current'))
				jQuery('.next').hide(0);
			jQuery('.prev').show(0);
		}
	});
	
	jQuery('.prev').click(function(){
		if (jQuery('.items div').eq(0).hasClass('current')) {
		} else {
			var img_width = jQuery('.items').find('.current').prev().find('img').width();
			var position = jQuery('.items').position();
			var position_new = position.left + img_width;
			jQuery('.items').find('.current').prev().addClass('current');
			jQuery('.items').find('.current').eq(1).removeClass('current');
			jQuery('.items').animate({
				"left": position_new
			}, 1000);
			if (jQuery('.items div').eq(0).hasClass('current'))
				jQuery('.prev').hide(0);
			jQuery('.next').show(0);
		}
	});
}

// jQuery Funktionen
jQuery(document).ready(function(){ 
	// AGENTUR.NET Logo in Fußzeile
	libAGENTURNET();
	
	// Tiger und Blatt Animationen (Menü)
	libMENU_PARENTS();
	libMENU_CHILDREN();
	
	// Kinder Hauptmenü
	libSUB_MENU_CHILDREN();
});

