
/**************************************************
	CONTENT HEIGHT
**************************************************/

function content_height() {
	
	$('.sliderContent').css('min-height', $(window).height() - 30);
	$('.sidebar').css('min-height', $(window).height() - 60);
	
	if ($('.sidebar').height() < $('.sliderContent').height()) {
		$('.sidebar').css('min-height', $('.sliderContent').height() - 30);
	}
}


/**************************************************
	BLOG HEIGHT
**************************************************/

function blog_height() {
	
	$('.nav.blog').height($(window).height());

	if ($('.nav.blog .navContent').height() < $(window).height()) {
		$('.nav.blog .navContent').css('top', ($(window).height() - $('.nav.blog .navContent').height()) / 2);
	}
}

/**************************************************
	PORTFOLIO HEIGHT
**************************************************/

function portfolio_height() {
	
	$('.nav.portfolio').height($(window).height());
	
	if ($('.nav.portfolio .navContent').height() < $(window).height()) {
		$('.nav.portfolio .navContent').css('top', ($(window).height() - $('.nav.portfolio .navContent').height()) / 2);
	}
}

/**************************************************
	WIDTH FIX - IE7
**************************************************/

function width_fix() {
	
	var sidebar_width = 0;
	
	if ($.browser.msie && $.browser.version=='7.0') {
		
		if ($('.sliderContent').width() != null) {
			
			if ($('.sidebar').width() != null) {
				sidebar_width = $('.sidebar').width() + 41;
			}
			
			$('.content').width($('.sliderContent').width() + 60 + sidebar_width);
		}
	}
}

/**************************************************
	MENU POSITION
**************************************************/

function menu_pos() {
	
	$('.navigation').css('top', ($(window).height() - $('.navigation').height()) / 2);
	$('.navigation').fadeIn();
}

/**************************************************
	SIDEBAR POSITION
**************************************************/

function sidebar_pos() {
	
	if ($('.widgets').height() < $(window).height() - 60) {
		$('.widgets').css('position', 'fixed');
	}
	
	else {
		$('.widgets').css('position', 'static');
	}
}

/**************************************************
	BACKGROUND
**************************************************/

function background_resize() {
	
	var image = '#background img';
	var ratio = ($(image).height() / $(image).width()).toFixed(2);
	var browserwidth = $(window).width();
	var browserheight = $(window).height();
	var offset;
	
	var min_height = 0;
	var min_width = 0;
	var fit_landscape = 0;
	var fit_portrait = 0;
	var horizontal_center = 1;
	var vertical_center = 1;
	
	if ((browserheight > min_height) || (browserwidth > min_width)){
		if ((browserheight/browserwidth) > ratio){
			if (fit_landscape && ratio <= 1){
				$(image).width(browserwidth);
				$(image).height(browserwidth * ratio);
			}
			
			else{
				$(image).height(browserheight);
				$(image).width(browserheight / ratio);
			}
		}
		
		else {
			if (fit_portrait && ratio > 1){
				$(image).height(browserheight);
				$(image).width(browserheight / ratio);
			}
			
			else{
				$(image).width(browserwidth);
				$(image).height(browserwidth * ratio);
			}
		}
	}
	
	if (horizontal_center){
		$(image).css('left', (browserwidth - $(image).width()) / 2);
	}
	
	if (vertical_center){
		$(image).css('top', (browserheight - $(image).height()) / 2);
	}
	
	$(image).bind("contextmenu",function(){
		return false;
	});
	$(image).bind("mousedown",function(){
		return false;
	});
}

/**************************************************
	DEPLOY
**************************************************/

function deploy() {
	
	content_height();
	blog_height();
	portfolio_height();
	width_fix();
	menu_pos();
	sidebar_pos();
}

/**************************************************
	DOCUMENT RESIZE
**************************************************/

window.onresize = function() {
	
	deploy();
	background_resize();
};

/**************************************************
	SOCIAL ICONS
**************************************************/

function social() {

	$('ul.social li').hover(function() {
		$(this).animate(
			{opacity: '1'}, {queue:false, duration: 200}
		);
	},
	function() {
		$(this).animate(
			{opacity: '0.5'}, {queue:false, duration: 200}
		);
	});
}

/**************************************************
	MENU
**************************************************/

function menu() {
	
	$('ul.menu li').hover(function() {
		$(this).not('ul.sub-menu li').find('a:eq(0)').stop().animate({
			paddingLeft: '20px'}, {queue:false, duration: 200
		}).removeClass('theme_color_1').addClass('theme_color_2');
		
		$(this).find('ul:eq(0)').show();
	},
	function(){
		$(this).not('ul.sub-menu li').find('a:eq(0)').stop().animate({
			paddingLeft: '10px'}, {queue:false, duration: 200
		}).removeClass('theme_color_2').addClass('theme_color_1');
		
		$(this).find('ul').hide();
	});
}

/**************************************************
	MENU - SEARCH
**************************************************/

function menu_search() {
	
	$('.navigation .search').hover(function(){
		$(this).animate({left: '0px'}, {queue:false, duration: 200});
	},
	function(){
		$(this).animate({left: '-150px'}, {queue:false, duration: 200});
	});
}

/**************************************************
	LIGHTBOX - PRETTY PHOTO
**************************************************/

function lightbox() {
	
	$("a[rel^='prettyPhoto'], a[rel^='lightbox']").prettyPhoto({
		showTitle : false,
		theme : 'facebook'
	});
}

/**************************************************
	CONTENT IMAGES
**************************************************/

function image() {

	$("a[rel^='lightbox']").hover(function() {
		$("a[rel^='lightbox']").not(this).animate(
			{opacity: '0.5'}, {queue:false, duration: 100}
		);
	},
	function() {
		$("a[rel^='lightbox']").not(this).animate(
			{opacity: '1'}, {queue:false, duration: 100}
		);
	});
}

/**************************************************
	BLOG
**************************************************/

function blog() {
	
	$('.nav.blog .navContent li a').hover(function() {
		$(this).animate({paddingRight: '20px'}, {queue:false, duration: 200});
	},
	function(){
		$(this).animate({paddingRight: '10px'}, {queue:false, duration: 200});
	});
	
	$('.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: 1000 });
		}
	});
}

/**************************************************
	PORTFOLIO
**************************************************/

function portfolio() {
	
	$('.nav.portfolio .navMask ul.navContent li').not('.paging').hover(function(){
		$(this).animate({right: '0px'}, {queue:false, duration: 200});
	},
	function(){
		$(this).animate({right: '-10px'}, {queue:false, duration: 200});
	});
	
	$('.nav.portfolio .navMask ul.navContent li p.image img').hover(function(){
		$(this).animate({opacity: '0.5'}, {queue:false, duration: 200});
	},
	function(){
		$(this).animate({opacity: '1'}, {queue:false, duration: 200});
	});
	
	$('.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: 1000 });
		}
	});
}

/**************************************************
	BACKGROUND
**************************************************/

function background() {
	
	$(window).load(function() {
		$('#background img').fadeIn();
		background_resize();
	});
}

/**************************************************
	HEADERS
**************************************************/

function headers() {
	
	$('.sliderContent > h1, .sliderContent > h2, .sliderContent > h3').wrapInner('<span class="title"></span>');
}

/**************************************************
	DOCUMENT READY
**************************************************/

$(document).ready(function() {
	
	social();
	menu();
	menu_search();
	lightbox();
	image();
	blog();
	portfolio();
	background();
	headers();
	deploy();
	
	$(window).load(function() {
		deploy();
	});
});
