$(function(){
	var view = $('.foto .big');
	var current;
	var vImg = new Image();

	view.click(function(){
		$.fancybox({
			'href': $(this).children('img').attr('src')
		});
	});

    $(vImg).load(function() {
		view.removeClass('loading').append(this);

          if ($(this).height() > $(this).width()) {
              $(this).removeAttr('width').attr('height', view.height()).css('margin-top', 0);
          } else {
              $(this).removeAttr('height').attr('width', view.width()).css('margin-top', (view.height() - $(this).height()) / 2);
          }

          $(this).fadeIn();
      }).error(function () {});

	$("#smallImg a, .color a").click(function () {
		if (current == this) return false;

        current = this;

        view.addClass('loading');
		if ( $.browser.msie ) {
			$(vImg).attr('src', $(this).attr('href') + "?" + new Date().getTime()).hide();
		} else {
			$(vImg).attr('src', $(this).attr('href')).hide();
		}
		
		$("#smallImg a").removeClass('active');
		$(this).addClass('active');

        return false;
	});
	
	if (view.length) {
		view.append(vImg);
		$('#smallImg a:first').click();	
	}	
})

