            $(document).ready(function(){
                // google map & contact animations
                $('a.link').hover(
                    function() { $(this).css('background-position', '0 0'); },
                    function() { $(this).css('background-position', '-3px 0'); }
                );
                $('a.link').click(function(e){
                    e.preventDefault();
                    if (parseInt($(this).parent().css('left')) != 0) {
                        var left = 0; 
                    } else {
                        var left = "-" + $(this).prev().outerWidth();
                    }
                    if (!$(this).parent().is(':animated')) {
                        $(this).parent().animate({
                            left: left
                        }, 500);
                    }
                });
                // contact form
                $('#contact-form').ajaxForm({
                    success: function() { 
                        alert('Your message was send.');
                        $('.contact a.link').click();
                    }
                });
                // doctors info
                $('.doctor').hover(
                    function() {$(this).children('.info').show()},
                    function() {$(this).children('.info').hide()}
                );
				 $('.assistent').hover(
                    function() {$(this).children('.info').show()},
                    function() {$(this).children('.info').hide()}
                );
                // thumbs 
                $('.right').hover(
                    function() { $('a.next-button').toggle(); $('a.prev-button').toggle(); },
                    function() { $('a.next-button').toggle(); $('a.prev-button').toggle(); }
                );
                var height = $('.main').outerHeight();
                var max = 2000 -326 /*- height*/; // there is some kind of bug ?! $('div.thumbnail-scroller').outerHeight() - height;
                $('a.next-button').click(function(e){
					direction = 0;
					timer.reset();
                    scrollerDown(e);
                });
				function scrollerDown(e) {
					if (e!=null) e.preventDefault();
                    var pos = Math.abs(parseInt($('.thumbnail-scroller').css('top')));
                    if (pos < max) {
                        var step = (pos + height < max) ? height : (max - pos);
                        if (!$('.thumbnail-scroller').is(':animated')) {
                            $('.thumbnail-scroller').animate({
                                'top': '-=' + step
                            }, 500, 'swing');
                        }
                    }
				}
				function scrollerUp(e){
					if (e!=null) e.preventDefault();
                    var pos = Math.abs(parseInt($('.thumbnail-scroller').css('top')));
                    if (pos > 0) {
                        var step = (pos - height > 0) ? height :  pos;
                        if (!$('.thumbnail-scroller').is(':animated')) {
                            $('.thumbnail-scroller').animate({
                                'top': '+=' + step
                            }, 500, 'swing');
                        }
                    }
				}
				var timer = $.timer(scrollerSlide, 10000);
				var direction = 0; // 0 = down, 1= up
				function scrollerSlide(){
					var pos = Math.abs(parseInt($('.thumbnail-scroller').css('top')));
					if (pos == 0) {
						direction = 0; 
					}
					if (pos == max) {
						direction = 1; 
					}
			
					if (pos >= 0 && direction==0) scrollerDown(null);
					
					if (pos <= max && direction==1)  scrollerUp(null);
					
					//window.setTimeout(scrollerSlide, 5000);
				}
				//window.setTimeout(scrollerSlide, 5000);
				timer.play();
                $('a.prev-button').click(function(e){
					direction = 1;
					timer.reset();
                    scrollerUp(e);
                });
                // carousel
                $('.carousel-index a.index').click(function(){
					var url = $(this).attr('href').substr(2);
					$.history.load(url);
					//load($(this).attr('href').substr(2));
                    //    window.history.replaceState(this.href, 'title', this.href);
					$('.carousel-index a.active').removeClass('active');
                    $(this).addClass('active');
                });
				
				var timerContent = $.timer(nextContent, 20000);
						///////////////////
				function load(url) {
					//$('#content').load(num +".html");
					$('.carousel-index a.active').removeClass('active');
					if (url.charAt(0)=="!") url = url.substr(1);
					$("#"+url+"-link").addClass('active');
					//carStop();
					timerContent.reset();
                    if ($('.carousel').is(':animated')) {
                        return false;
                    }
                    $.ajax({
                        url: 'load.php?id=' + url,
                        dataType: 'json',
                        success: function(data) {
                            if (data) {
								
                                $('.content').css('background-image', 'url("'+data.image+'") ');
                                $('.carousel').fadeTo(1000, 0, function() {
                                  $('.carousel-text').html(data.text);
                                  $('.carousel').css('background-image', 'url("'+data.image+'")');
                                  $('.carousel').fadeTo(300, 1);
								  $('.carousel').css('visibility','visible');
                                });
                            }
                        },
                    });
					
					//$('#iconImage').attr('href').anchor('http://www.oralchirurgie.ch/neu/favicon.ico');
                    
                   // History.replaceState(null, null, this.href);
				}
		
				$.history.init(function(url) {
						url = (url == "" ? "!zahnarzt-luzern" : url);
						load(url);
						
					});
		
				$('.ajax-links').live('click', function(e) {
						var url = $(this).attr('href').substr(2);
						//url = url.replace(/^.*#/, '');
						//alert(url);
						$.history.load(url);
						return false;
					});
    ///////////////
                // carousel controls
                $('a.next').click(function(e) {
                    e.preventDefault();
                    /*var act = $('.carousel-index a.active');
                    var all = act.parent().children();
                    all.eq((all.index(act) + 1) % all.length).click();*/
					nextContent();
					carStop();
                });
                $('a.back').click(function(e) {
                    e.preventDefault();
                    /*var act = $('.carousel-index a.active');
                    var all = act.parent().children();
                    all.eq((all.index(act) - 1) % all.length).click();*/
					prevContent();
					carStop();
                });
                var carousel_timer = null; 
                $('a.stop').click(function(e) {
                    e.preventDefault();
                    window.clearInterval(carousel_timer);
                    $('a.stop').hide(); $('a.play').show();
                });
				
				
				
                $('a.play').click(function(e) {
                    e.preventDefault();
                   // carousel_timer = window.setInterval(function(){
                    //   nextContent();
                    //}, 20000);
					timerContent.play();
                    $('a.play').hide(); $('a.stop').show();
                });
				function prevContent(){
					var act = $('.carousel-index a.active');
                    var all = act.parent().children();
					var url = (all.eq((all.index(act) - 1) % all.length)).attr('href').substr(2);
					$.history.load(url);
                    //all.eq((all.index(act) + 1) % all.length).click();
				}
				function nextContent(){
					var act = $('.carousel-index a.active');
                    var all = act.parent().children();
					var url = (all.eq((all.index(act) + 1) % all.length)).attr('href').substr(2);
					$.history.load(url);
                    //all.eq((all.index(act) + 1) % all.length).click();
				}
                // carousel autoload
               /* var hash = window.location.hash;
                var con = $('.carousel-index a.index');
                if (con.is('[href="'+hash+'"]')) {
                    con.filter('[href="'+hash+'"]').click();
                } else {
                    con.first().click();
                }*/
                $('a.play').click();
				
			   function carStop(){
				 //e.preventDefault();
                    window.clearInterval(carousel_timer);
                    $('a.stop').hide(); $('a.play').show();
				};
            });
	

