var pcHeight;
var pcWidth;
var midPoint;
var remWidth;
var speed = 500;
var slowSpeed = 50;
var percentVal = 40;
var fadeInSpeed = 500;
var navFadeSpeed = 500;
var navBarWidth = 200;
var easingType = 'swing';
var remainder;
var iWidth;
//
function resizer() {
	pcHeight = $(window).height();
	pcWidth = $(window).width();
	setValues();
	if (pcHeight>500) {
		$('img.source-left').attr({ height: pcHeight });
		$('img.source-right').attr({ height: pcHeight });
	}
	iWidth = $('img.source-left').width();
	remainder = iWidth - midPoint;	
	$('#bgLeft').css({'top':0,'left':0,'width':midPoint,'height':pcHeight});
	$('#bgRight').css({'top':0,'left':midPoint,'width':remWidth,'height':pcHeight});
	$('#navbar:not(.sidebar)').css({'left':midPoint - navBarWidth });
	$('#section').css({'left':midPoint + 'px'});
	$('img.source-left').css({'margin-left':-remainder +'px'});
	//alert(iWidth);
}

function animateIn() {
	$('#navbar, #section, img.source-left, img.source-right').css({'display':'none'});
	//$('#section').css({'display':'none'});
	$('img.source-left').fadeIn(fadeInSpeed/2, function() {
		$('#navbar').fadeIn(navFadeSpeed);
		$('#section').delay(200).fadeIn(navFadeSpeed);
	});
	$('img.source-right').delay(100).fadeIn(fadeInSpeed);
	
}

function animateOut() {
	$('#navbar').fadeOut(500);
	$('#section').delay(200).fadeOut(500);
	$('img.source-left, img.source-right').fadeOut(navFadeSpeed);

}


function animateOutLink(link) {
	$('#navbar, img.source-left, img.source-right').fadeOut(navFadeSpeed);
	$('#section').delay(200).fadeOut(navFadeSpeed, function() {
		window.location.href=link;
	});
	$('img.source-left, img.source-right').fadeOut(navFadeSpeed);
		
}

function animateMovement(num) {

	percentVal = num;
	
	setValues();
	
	$('#section').animate({ 'left': midPoint }, speed, easingType);
	$('#navbar').animate({ 'left': midPoint - navBarWidth  }, speed, easingType);
	$('#bgLeft').animate({'top':0,'left':0,'width':midPoint,'height':pcHeight}, speed, easingType);
	$('#bgRight').animate({'top':0,'left':midPoint,'width':remWidth,'height':pcHeight}, speed, easingType);
	
}

function animateOutMovement(num, link) {
	
	percentVal = num;	
	setValues();
	iWidth = $('img.source-left').width();
	remainder = iWidth - midPoint;	
	$('#section').animate({ 'left': midPoint }, speed, easingType);
	$('#navbar').animate({ 'left': midPoint - navBarWidth  }, speed, easingType);
	$('#bgLeft').animate({'top':0,'left':0,'width':midPoint,'height':pcHeight}, speed, easingType);
	$('img.source-left').animate({'margin-left':-remainder +'px'}, speed, easingType);
	
	$('#bgRight').animate({'top':0,'left':midPoint,'width':remWidth,'height':pcHeight}, speed, easingType, function() {
		
		$('#navbar, img.source-left, img.source-right').fadeOut(navFadeSpeed);
		$('#section').delay(200).fadeOut(navFadeSpeed, function() {
			window.location.href=link;
		});
		$('img.source-left, img.source-right').fadeOut(navFadeSpeed);
	});
	
	$('#navbar, img.source-left, img.source-right').fadeOut(navFadeSpeed);
	$('#section').delay(200).fadeOut(navFadeSpeed, function() {
		window.location.href=link;
	});
	$('img.source-left, img.source-right').fadeOut(navFadeSpeed);
	
	
}



function animateLeftImage(num, scrollSpeed) {
	if (scrollSpeed == 0) {
		$('img.source-left').animate({'margin-left':num}, speed, easingType);
	}else {
		$('img.source-left').animate({'margin-left':num}, scrollSpeed, easingType);
	}
}

function animateRightImage(num, scrollSpeed) {
	if (scrollSpeed == 0) {
	$('img.source-right').animate({'margin-left':num}, speed, easingType);
	} else {
	$('img.source-right').animate({'margin-left':num}, scrollSpeed, easingType);
	}

}
function fadeNav(val) {
	$('#navbar').animate({'opacity':val}, speed, easingType);
}
function fadeSection(val) {
	$('#section').animate({'opacity':val}, speed, easingType);
}
function changeLeftImage(link) {
	$('.source-left').animate({'opacity':0}, speed, function() {
		$(".source-left").attr("src",link).animate({'opacity':1},speed);
	});
}
function changeRightImage(link) {
	$('.source-right').animate({'opacity':0}, speed, function() {
		$(".source-right").attr("src",link).animate({'opacity':1},speed);
	});
}
function setValues() {
	// get the midPoint and remaining values based on the screen size
	// get the value from the movePoint function
	midPoint = movePoint(percentVal);
	// find out the remaining width
	remWidth = pcWidth - midPoint;
}

function movePoint(pc) {
	return(pcWidth/100 * pc);	
}

jQuery(document).ready(function() {
	resizer();
   		$(window).resize(function() {
  				resizer();
   		});
   		    			
});

$(window).load(function() {
   			iWidth = $('.source-left').width(); 
   			remainder = iWidth - midPoint;
   			resizer();
   		});

