$(function() {
	setup_page();
	setupMenu();
});

function setup_page() {
	$(".accordion").accordion();
	$(".tabs").tabs();
	$('#main').css('display', 'none').delay(100).fadeIn(800); 
  $('a.fancybox.info').fancybox({
    'width':550,
    'height':'auto',
    'autoDimensions':false,
    'transitionIn'  : 'fade',
    'transitionOut' : 'fade',
    'cyclic'    : false,
    'titlePosition' : 'over'    
  });
}
function setupMenu() {
	$('#menutop > li').each(function() {
	  var li = $(this);
	  var div = li.find('div');
	  li.hover(function() {
	    div.fadeIn(250);
	  },
	  function() {
	    div.fadeOut(150);
	  });
	});
	
}
function dialogMessage(text, typ) {
	var $div = $('<p>').css({'margin-top':'7px'});
	var $icon = $('<span>');
	var className = '';
	switch(typ) {
		case "":
			break;
		case "alert":
			className = "ui-icon ui-icon-alert";
			break;
	}
	$div.text(text);
	$icon.addClass(className).css({'float':'left', 'margin':'0 7px 20px 0'}).prependTo($div);
	var options = {
		buttons: { 
			"OK": function() {
				$(this).dialog("close");
			}
		},
		resizable:false,
		draggable:false,
		title: "Meldung",
		modal:true
	}
	$div.dialog(options);
}

function dialogJaNein(frage, typ, beiJa, beiNein) {
	var $div = $('<p>').css({'margin-top':'7px'});
	var $icon = $('<span>');
	var className = '';
	switch(typ) {
		case "":
			break;
		case "alert":
			className = "ui-icon ui-icon-alert"
			break;
	}
	$div.text(frage);
	$icon.addClass(className).css({'float':'left', 'margin':'0 7px 20px 0'}).prependTo($div);
	var options = {
		buttons: { 
			"Ja": function() {
				$(this).dialog("close");
				beiJa();
			},
			"Nein": function() {
				$(this).dialog("close");
				beiNein();
			}
			
		},
		resizable:false,
		draggable:false,
		title: "Achtung",
		modal:true
	}
	$div.dialog(options);
}
function fadeInBody() {
	fadeIn('main', '0');
}
function fadeOutBody(i) {
	fadeOut('main', '100');
}

function rest() {
}

function makeGaleryFancybox(g) {
	$(g).fancybox({
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'cyclic'		: true,
		'titlePosition' : 'over'		
	});
	$(g).opacityrollover();
	
}
function bitte_warten(d) {
	var t='<img src="Bilder/Progress.gif">';
	show_html_fade(d, t);
}
function show_html_fade(d, t) {
	$(d).innerHTML = t;
	fadeIn(d, 0);
}
function show_html(d, t) {
	$(d).innerHTML = t;
}
function get_html(d, f, asp, r) {
	var e='';
	var myAjax = new Ajax.Request(asp, {
		parameters: $(f).serialize(true),
		onSuccess: function xyz_success(transport) {
		//								  	$(d).innerHTML = 'xyz_success';
		  e = transport.responseText;
		  show_html_fade(d, e);
		},
		onFailure: function xyz_failure(transport) {
		//								  	$(d).innerHTML = 'xyz_failure';
		  e = 'es trat ein Fehler auf<br><br>' + transport.responseText;
		  show_html(d, e);
		}
	});
}
function do_login(d, f, r) {
	get_html(d, f, "A/Login.asp", r);
}
function setupBeispiel(id) {
	$('input[type=submit]').button();
	var div = $('#'+id);
	var div2=null;
	switch(id) {
		case 'aaa':
			div2 = div.find('div.a');
			div2.find('img.b1').opacityrollover({
				mouseOutOpacity: 1,
				mouseOverOpacity: 0
			});
			div2.find('img.b2').opacityrollover({
				mouseOutOpacity: 1,
				mouseOverOpacity: 0.3
			});
			div2.find('img.b3').opacityrollover({
				mouseOutOpacity: 1,
				mouseOverOpacity: 0.7
			});
			div2.find('img.b4').opacityrollover({
				mouseOutOpacity: 0,
				mouseOverOpacity: 1
			});
			div2.find('img.b5').opacityrollover({
				mouseOutOpacity: 0.3,
				mouseOverOpacity: 1
			});
			div2.find('img.b6').opacityrollover({
				mouseOutOpacity: 0.7,
				mouseOverOpacity: 1
			});

			div2 = div.find('div.b');
			div2.find('img').hover(function() {
				$(this).css({'z-index': '100'});
			}, function() {
				$(this).css({'z-index': '0'});
			});
			div2.find('img.b1').hover(function() {
				$(this).animate({rotate: '10'});
			}, function() {
				$(this).animate({rotate: '0'});
			});
			div2.find('img.b2').hover(function() {
				$(this).animate({rotate: '-20'});
			}, function() {
				$(this).animate({rotate: '0'});
			});
			div2.find('img.b3').hover(function() {
				$(this).animate({rotate: '180'});
			}, function() {
				$(this).animate({rotate: '360'});
			});
			div2.find('img.b3').hover(function() {
				$(this).animate({scale: '1.2'});
			}, function() {
				$(this).animate({scale: '1'});
			});
			div2.find('img.b4').hover(function() {
				$(this).animate({scale: '0.6'});
			}, function() {
				$(this).animate({scale: '1'});
			});
			div2.find('img.b5').hover(function() {
				$(this).animate({scale: '1.4', rotate: '+=5'});
			}, function() {
				$(this).animate({scale:'1', rotate: '+=355'});
			});
			div2.find('img.b6').hover(function() {
				$(this).transform({skewX: 5}).animate({translate: '15 -15', skewX: 0}, {
					duration: 600,
					easing: 'easeOutSine'
				});			
			}, function() {
				$(this).transform({skewX: -5}).animate({translate: '0 0', skewX: 0}, {
					duration: 600,
					easing: 'easeOutSine'
				});			
			});
			div2.find('img.b7').hover(function() {
				$(this).animate({rotate: '+=270', scale: 2}, {
					duration: 2500,
					easing: 'easeOutSine'
				});			
			}, function() {
				$(this).animate({rotate: '+=450', scale:1}, {
					duration: 2500,
					easing: 'easeOutSine'
				});			
			});

			div2 = div.find('div.c');
			div2.find('img').resizeOnApproach(null);


			break;
		case 'aab':
			div2 = div.find('div.a');
			div2.find('img').hover(
				function() {
					$(this).clearQueue().animate({'height':'20','border-width':'31'});
				},
				function() {
					$(this).clearQueue().animate({'height':'80','border-width':'2'});
					
				}
			);
			div2 = div.find('div.b');
			div2.find('img').hover(
				function() {
					$(this).clearQueue().animate({'height':'100','margin':'-10px'}, {'easing':'easeOutBack'});
				},
				function() {
					$(this).clearQueue().animate({'height':'80','margin':'0'});
					
				}
			);
			div2 = div.find('div.c');
			div2.find('img').hover(
				function() {
					$(this).clearQueue().animate({'height':'200','margin':'-60px'}, {'easing':'easeOutBounce'});
				},
				function() {
					$(this).clearQueue().animate({'height':'80','margin':'0'});
					
				}
			);
			div2 = div.find('div.d');
			div2.find('img').hover(
				function() {
					if(!$(this).hasClass('hover')) {
						$(this).addClass('hover');
						$(this).animate({'height':'200','margin':'-60px'}, 2000, 'easeOutBack', function() {
							$(this).delay(300).animate({'height':'80','margin':'0'}, 1600, 'easeInOutElastic', function() {
								$(this).delay(1000).effect('explode', null, 800, function() {
									$(this).delay(4500).animate({'left':'0', 'height':'0','margin':'40', 'border-width':'2'},1, function() {
										$(this).fadeIn(600, function() {
											$(this).animate({'height':'80','margin':'0', 'border-width':'2'}, 600, function() {
												$(this).delay(1000).removeClass('hover');
											});
										});
									});
								});
							});
						});
					}
				},
				function() {
					$(this).clearQueue().stop().removeClass('hover').animate({'left':'0', 'height':'80','margin':'0', 'border-width':'2'}).fadeIn(400);
				}
			);
			div2 = div.find('div.e');
			div2.find('img').resizeOnApproach(null);
			break;
		case 'baa':
			div2 = div.find('div.a');
			div2.galleryView({
				panel_width: 750,
				panel_height: 400,
				frame_width: 70,
				frame_height: 70,
				transition_speed: 1200,
				easing: 'easeOutBounce'
			});

			div2 = div.find('div.b');
			div2.find('ul').PikaChoose();

			div2 = div.find('div.c');
			div2.CloudCarousel({	
				minScale:0.2,
				reflHeight:80,
				reflOpacity:0.9,
				reflGap:20,
				yRadius:400,
				xRadius:900,
				xPos:350,
				yPos:80,
				buttonLeft: $('#b1'),
				buttonRight: $('#b2'),
				FPS:80,
				autoRotate: 'right',
				autoRotateDelay: 1000,
				speed:0.1,
				mouseWheel:true
			});

			div2 = div.find('div.d');
			div2.find('img').addClass('tdc-element');
			div2.carousel3D({
		        speed: 900,
		        perspectiveZoom: 40,
		        sideOffset: 50,
		        topOffset:20,
		        secondaryOpacity: .45,
		        emClass:'tdc-element'
		    });
			break;
		case 'daa':
			div2 = div.find('form.a');
			div2.submit(function() {
				var div2=$(this);
				var i = div2.find('input[name=vorname]');
				if(i.val()=='') {
					dialogMessage('Der Vorname darf nicht leer sein', 'alert');
					return(false);
				}
				i = div2.find('input[name=nachname]');
				if(i.val()=='') {
					dialogMessage('Der Nachname darf auch nicht leer sein', 'alert');
					return(false);
				}
				i = div2.find('input[name=password]');
				if(i.val()!='geheim') {
					dialogMessage('Das Passwort ist nicht korrekt! (probieren Sie mal "geheim")', 'alert');
					return(false);
				}
				div2.find('input').not('[type=submit]').val('');
				div2.fadeOut(500, function() {
					div2.fadeTo(500, 1, function() {
						dialogMessage('OK jetzt stimmt alles', '');						
					});
					
				})
				return(false);
				
			});
			var arrHaustiere = ['Affe', 'Igel', 'Schlange', 
			'Hamster', 'Hund', 'Katze', 'Maus', 'Meerschweinchen', 'Ratte', 
			'Wellensittich','Papagei', 'Vogel', 
			'Fische', 'Goldfisch'];
			arrHaustiere.sort();
			div2 = div.find('form.b');
			div2.find('input[type=text]').autocomplete({
				source: arrHaustiere
			});
			div2.submit(function() {
				var div2=$(this);
				var i = div2.find('input[name=haustier]');
				if(i.val()=='') {
					dialogMessage('Hallo, bitte geben Sie ein Haustier ein', 'alert');
					return(false);
				}
				dialogMessage('jetzt könnte man die Aktion auswerten, zB als Umfrage...', '');
				return(false);
			});

			$('a.b').click(function() {
				div2.dialog();
			});
			break;
	}
}

