var fix = 0;

function deployFunctions() {
  
  if($('.content').offset().left < ($('#pullimg').offset().left + $('#pullimg').width())) {
    clearTimeout(fix);
    fix = setTimeout(function() { $('#pullimg').css('margin-right', (($('#pullimg').offset().left + $('#pullimg').width()) - $('.content').offset().left) * 3); }, 500);
  }
  
	/**************************************************
		MENU
	**************************************************/
	
	$('.menu').css('top', ($(window).height() - $('.menu').height()) / 2);
	var nl = ($('.menu').offset().top - $('.logo').height()) / 2;
	nl = (nl <= 50) ? nl : 50;
	$('.logo').css('top', nl);
	
	/**************************************************
		SLIDER
	**************************************************/
	
	$(".sliderMask, .jScrollPaneContainer").height($(window).height());
	$('.sliderMask').jScrollPane();
	
	/**************************************************
		NAVIGATION - BLOG
	**************************************************/
	
	$(".nav.blog").height($(window).height());
	
	if ($('.nav.blog .navContent').height() < $(window).height()) {
		$('.nav.blog .navContent').css('top', (($(window).height() - $('.nav.blog .navContent').height()) / 2) - 20);
	}
	
	/**************************************************
		NAVIGATION - PORTFOLIO
	**************************************************/
	
	$(".nav.portfolio").height($(window).height());
	
	if ($('.nav.portfolio .navContent').height() < $(window).height()) {
		$('.nav.portfolio .navContent').css('top', (($(window).height() - $('.nav.portfolio .navContent').height()) / 2) - 20);
	}
	
	/**************************************************
		GOOGLE MAPS
	**************************************************/
	
	if ($.browser.msie && $.browser.version=="6.0") {
		$("#background div.gradient .right, #background div.gradient .left").height($(window).height());
	}
	
}

$(document).ready(function() {

	deployFunctions();
	
	if($('#topbar')) {
  	setTimeout(function() { $('#topbar').animate({top: -370}, {queue:false, duration:1000, easing:"easeOutElastic", complete:addOnClick}); }, 1000);
	}
	
	/**************************************************
		MENU
	**************************************************/
	
	$('.menu ul.list li a').hover(function() {
		$(this).animate({paddingLeft: '20px'}, {queue:false, duration: 100});
	},
	function(){
		$(this).animate({paddingLeft: '10px'}, {queue:false, duration: 100});
	});
	
	/**************************************************
		SEARCH
	**************************************************/
	
	$('.menu .search').hover(function(){
		$(this).animate({left: '0px'}, {queue:false, duration: 100});
	},
	function(){
		$(this).animate({left: '-150px'}, {queue:false, duration: 100});
	});
	
	/**************************************************
		SLIDER
	**************************************************/
	
	$('.sliderMask .sliderContent img').load(function() {
		$(".sliderMask, .jScrollPaneContainer").height($(window).height());
		$('.sliderMask').jScrollPane();
	});
	
	/**************************************************
		NAVIGATION - BLOG
	**************************************************/
	
	$('.nav.blog .navContent li a').hover(function(){
		$(this).animate({paddingRight: '20px'}, {queue:false, duration: 100});
	},
	function(){
		$(this).animate({paddingRight: '10px'}, {queue:false, duration: 100});
	});
	
	$('.nav.blog .navMask ul.navContent').mousemove(function(e) {
		var _top = parseInt($('.nav.blog').offset().top);
		var _contentH = parseInt($('.nav.blog .navMask').height()) + 5;
		var _H = $('.nav.blog').height() - 20;
		var _scH = _contentH - _H;
		var _ypos = e.pageY - _top;
		
		if(_scH > 0) {
			var _contentY = -(_scH / _H)*_ypos + 10;
			$('.nav.blog .navMask .navContent').animate({top: _contentY}, { queue:false, duration: 500 });
		}
	});
	
	/**************************************************
		NAVIGATION - PORTFOLIO
	**************************************************/
	
	$('.nav.portfolio .navMask ul.navContent li').hover(function(){
		$(this).animate({right: '0px'}, {queue:false, duration: 100});
	},
	function(){
		$(this).animate({right: '-10px'}, {queue:false, duration: 100});
	});
	
	$('.nav.portfolio .navMask ul.navContent li p.image img').hover(function(){
		$(this).animate({opacity: '0.5'}, {queue:false, duration: 100});
	},
	function(){
		$(this).animate({opacity: '1'}, {queue:false, duration: 100});
	});
	
	$('.nav.portfolio .navMask ul.navContent').mousemove(function(e) {
		var _top = parseInt($('.nav.portfolio').offset().top);
		var _contentH = parseInt($('.nav.portfolio .navMask').height()) + 5;
		var _H = $('.nav.portfolio').height() - 20;
		var _scH = _contentH - _H;
		var _ypos = e.pageY - _top;
		
		if(_scH > 0) {
			var _contentY = -(_scH / _H)*_ypos + 10;
			$('.nav.portfolio .navMask .navContent').animate({top: _contentY}, { queue:false, duration: 500 });
		}
	});
	
	/**************************************************
		BACKGROUND
	**************************************************/
//	
//    $('#background img').load(function() {
//		$(this).css({
//			top: ($(window).height() - $(this).height()) / 2,
//			display: 'block'
//		});
//    });
//	
//	$('#background img').css({
//		top: ($(window).height() - $('#background img').height()) / 2,
//		display: 'block'
//	});
	
	/**************************************************
		LIGHTBOX
	**************************************************/
	
	$(function() {
		$('.lightbox').lightBox();
	});
	
});