(function($){
  $(function() {
    $(window).autoscale('.autoscale');
    
    $("#right_menu").scrollFollow({
      offset:10,
      speed: 1600,
      //delay:1200,
      easing:'easeOutExpo'
    });
    
    $('.iframe').colorbox({
      iframe: true,
      width:  "760px",
      height: "550px"
    });
    
    // transition effect
    style = 'easeOutQuart';

    // if the mouse hover the image
    $('.photo').hover(
      function() {
        //display heading and caption
        $(this).children('div:first').stop(false,true).animate({top:0},{duration:200, easing: style});
        $(this).children('div:last').stop(false,true).animate({bottom:-2},{duration:200, easing: style});
      },
      function() {
        //hide heading and caption
        $(this).children('div:first').stop(false,true).animate({top:-20},{duration:200, easing: style});
        $(this).children('div:last').stop(false,true).animate({bottom:-60},{duration:200, easing: style});
      }
    );

    // News read-more toggle
    $('div.newsbox').each(function () {
        var $this = $(this),
            $more = $this.find('.tail').hide(),
            $button = $this.find('a.btn_more');
        $button.bind('click', function (event) {
            event.preventDefault();
            $more.slideToggle(200, 'easeOutExpo', function () {
                $(window).trigger('resize');
                $button.toggleClass('btn_more_expanded');
            });
            return false;
        });
    });

    // Menu box link
    $('div.menu_box').each(function () {
        var $this = $(this),
            $link = $this.find('p.btn > a'),
            href = $link[0].href,
            $button = $link.find('img'),
            originalButtonUrl = $button.attr('src'),
            rolloverButtonUrl = originalButtonUrl.replace(/(\.gif|\.jpe?g|\.png)$/, '_on$1'),
            rolloverButton = new Image();
        rolloverButton.src = rolloverButtonUrl;
        $this.hover(function () {
            $this.addClass('menu_box_hover');
            $button.attr('src', rolloverButtonUrl);
        }, function () {
            $this.removeClass('menu_box_hover');
            $button.attr('src', originalButtonUrl);
        });
        $this.click(function () {
            location.href = href;
        });
    });

    // jQuery Cycle
    $('#photogallery').cycle({
/*
        after: function (slide) {
            var slideWidth = $(slide).width(),
                parentWidth = $('#photogallery').width();
            $(slide).css('left', (parentWidth - slideWidth) / 2 + 'px');
        },
*/
        fit: 1,
        width: '100%',
        timeout: 0,
        speed: 1000,
        prev: '#photogallery_prev',
        next: '#photogallery_next',
        pager: '#photogallery_thumbs',
        pagerAnchorBuilder: function(i, slide) {
            var $s = $(slide).find('img');
            return '<li><a href="#"><img src="' + $s.attr('src') + '" alt="" width="54" height="29" /></a></li>'; 
        }
    });
    
    /*$('.gallery_demo_unstyled').addClass('gallery_demo'); // adds new class name to maintain degradability
    
    $('ul.gallery_demo').galleria({
      history   : true, // activates the history object for bookmarking, back-button etc.
      clickNext : true, // helper for making the image clickable
      insert    : '#main_image', // the containing selector for our main image
      onImage   : function(image,caption,thumb) { // let's add some image effects for demonstration purposes
        
        // fade in the image & caption
        image.css('display','none').fadeIn(1000);
        caption.css('display','none').fadeIn(1000);
        
        // fetch the thumbnail container
        var _li = thumb.parents('li');
        
        // fade out inactive thumbnail
        _li.siblings().children('img.selected').fadeTo(500,0.3);
        
        // fade in active thumbnail
        thumb.fadeTo('fast',1).addClass('selected');
        
        // add a title for the clickable image
        image.attr('title','Next image >>');
      },
      onThumb : function(thumb) { // thumbnail effects goes here
        
        // fetch the thumbnail container
        var _li = thumb.parents('li');
  
        // if thumbnail is active, fade all the way.
        var _fadeTo = _li.is('.active') ? '1' : '0.3';
        
        // fade in the thumbnail when finnished loading
        thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1500);
        
        // hover effects
        thumb.hover(
          function() { thumb.fadeTo('fast',1); },
          function() { _li.not('.active').children('img').fadeTo('fast',0.3); } // don't fade out if the parent is active
        )
      }
    });*/
  });
})(jQuery);

function effect_bird() {
	if ($.support['opacity']) {
		$('#header p.bird').fadeIn(3000, 'easeInQuad');
	} else {
		$('#header p.bird').show();
	}
}
