/**
* Full Size Backgrounded
* 
* @version 1.0
* @author Vaska 
*/
(function($)
{
	$.fn.bg_img_resize = function() 
	{
		var w = $(window).width();
		var h = $(window).height();
		var iw = $(this).children('img').attr('width');
		var ih = $(this).children('img').attr('height');
		var rw = iw / ih;
		var rh = ih / iw;
		var sc = h * rw;
		if (sc >= w) {
			nh = h;
			nw = sc;
		} else {
			sc = w * rh;
			nh = sc;
			nw = w;
		}
	
		$(this).children('img').css({height: nh, width: nw});
	}
})(jQuery);

$(document).ready(function(){ $('#the-background').bg_img_resize(); });
$(window).resize(function()
{
	var offset = $('#the-background').children('img').width();
	$('#the-background').bg_img_resize();
	var offset;// = (offset - $('#the-background').children('img').width());//*$("#itemsBackground").children(".backgroundImage").length;
	var first = true;
	$("#itemsBackground").children(".backgroundImage").each(function()
	{
		if (first == true)
		{
			offset = $(this).children('img').width();
			$(this).bg_img_resize();
			offset = (offset - $(this).children('img').width());
			first = false;
		}
		else
		{
			$(this).bg_img_resize();
		}
		$(this).css({width: $(this).children('img').width()+"px", height: $(this).children('img').height()+"px"});
	});
	if ($("#itemsBackground").position().left == 0)
	{
		offset = 0;
	}
										
	$("#itemsBackground").css({height: $('#the-background').height()+"px", left: ($("#itemsBackground").position().left + offset)+"px"});
	$("#projectImages").css({height: $(this).children('img').height()+"px"});
});

