// JavaScript Document

function getWin() {
		winHeight=$(window).height();
		winWidth=$(window).width()-300;
		winAspectRatio=winWidth/winHeight;
	};
function stretchVert(target){
	getWin();
	docHeight=$(document).height();
	if (docHeight>winHeight){
		$(target).css({height: winHeight});
	} else {
		$(target).css({height: docHeight});
	};
	};
function setBase (reference, target){
	refHeight=$(reference).height();
	targetHeight=$(target).outerHeight();
	setHeight=refHeight-targetHeight;
	$(target).css({position: 'relative', top: setHeight});
	};
function setBgImageW(target) {
	setWidth=winWidth;
	$(target).css({width: setWidth,height: winWidth/aspectRatio});
	$('#bg-container').css({height: winHeight,width:winWidth,overflow: 'hidden'});
};
function setBgImageH(target) {
	setWidth=winHeight*aspectRatio;
	$(target).css({width: setWidth,height: winHeight});
	$('#bg-container').css({height: winHeight,width:winWidth,overflow: 'hidden'});
};
function setImg(target) {
	getWin();
	bgWidthInit=$(target).width();
	bgHeightInit=$(target).height();
	aspectRatio=bgWidthInit/bgHeightInit;
	if (winAspectRatio > aspectRatio) {
		setBgImageW(target);
		currentWidth=$(target).width();
		offsetLeft=0;
		setLeft=0;
		offsetRight=winWidth+offsetLeft;
		setClip="rect(0px,"+offsetRight+"px,"+winHeight+"px,"+offsetLeft+"px)";
		$(target).css({clip: setClip,left: setLeft});
	} else {
		setBgImageH(target);
		currentWidth=$(target).width();
		offsetLeft=((winHeight*aspectRatio)-winWidth)/2;
		setLeft=-offsetLeft;
		offsetRight=winWidth+offsetLeft;
		setClip="rect(0px,"+offsetRight+"px,"+winHeight+"px,"+offsetLeft+"px)";
		$(target).css({clip: setClip,left: setLeft});
	};
};
function setSrc(target, src){
	$(target).attr("src", src)
};
