jQuery(function($) {
	
	$('.navigation').each(function() {
		$(this).find('ul li:last').addClass('last');
	});
	
	Cufon.replace('.navigation ul li a, #main #section-gallery-slides a, .to-cufon', {fontFamily: 'Trajan Pro', hover: true});
	Cufon.replace('.gallerypage h2, #notification *, #compliance p, #form-successz p, #about .about-cnt h3', {fontFamily: 'Trajan Pro'});

	$('.popup').each(function() {
		var popup_width = $(this).width();
		var popup_height = $(this).height();
		var screen_width = $(window).width();
		var screen_height = $(window).height();
		$(this).css({'left': screen_width / 2 - popup_width / 2, 'top': screen_height / 2 - popup_height / 2});
	});
	
	$('.compliance-link').click(function() {
		if($('#compliance:animated').length == 0) {
			if($('#compliance:visible').length == 0) {
				$('#compliance').fadeIn('fast');
			} else $('#compliance').fadeOut('fast');			
		}
		return false;
	});
	
	$(document).click(function(e) {
		if (!$('#compliance').is(':animated') && $('#compliance').is(':visible')) {
			$('#compliance').fadeOut('fast');
		}
		if (!$('#form-successz').is(':animated') && $('#form-successz').is(':visible')) {
			$('#form-successz').hide();
		}
		if (!$('#photo-enhancements-upload').is(':animated') && $('#photo-enhancements-upload').is(':visible')) {
			$('#photo-enhancements-upload').hide();
		}
		if (!$('#photo-enhancements-payment').is(':animated') && $('#photo-enhancements-payment').is(':visible')) {
			$('#photo-enhancements-payment').hide();
		}
	});
	
});

(function ($) {
	$(window).load(function () {
		if($('#bg-inner').height() < $(document).height()) {
			$('#bg-inner').height($(document).height());
		}
	});
	
jQuery.fn.center = function(loaded) {
    var obj = this;
    body_width = parseInt($(window).width());
    body_height = parseInt($(window).height());
    block_width = parseInt(obj.width());
    block_height = parseInt(obj.height());
    
    left_position = parseInt((body_width/2) - (block_width/2)  + $(window).scrollLeft());
    if (body_width<block_width) { left_position = 0 + $(window).scrollLeft(); };
    top_position = parseInt((body_height/2) - (block_height/2) + $(window).scrollTop());
    if (body_height<block_height) { top_position = 0 + $(window).scrollTop(); };
    
    if(!loaded) {
        
        obj.css({'position': 'absolute'});
        obj.css({'left': left_position, 'top': top_position});
        $(window).bind('resize', function() { 
            obj.center(!loaded);
        });
        $(window).bind('scroll', function() { 
            obj.center(!loaded);
        });
        
    } else {
        obj.stop();
        obj.css({'position': 'absolute'});
        obj.animate({'left': left_position, 'top': top_position}, 200, 'linear');
    }
}

})(jQuery)