// products modal gallery
function checkModalEnvironment()
{
	// check window height + width
	var vp_width = $(window).width();
	var vp_height = $(window).height();
	var interface_width = 1002;
	var interface_height = $('body').height();
	var mc_width = 1002;
	var mc_height = 720;
	var mc_top = Math.floor(Math.abs(vp_height - mc_height)/2);
	var mc_left = Math.floor(Math.abs(vp_width - mc_width)/2);
	
	// position the modal window
	if ( vp_width > interface_width && vp_height < interface_height  )
	{
		$('#modal-content').css({ top: ''+ mc_top +'px', left: ''+ mc_left +'px' });
		$('#modal-overlay').height(interface_height).width(vp_width);
	}
	if ( vp_width > interface_width && vp_height < interface_height && vp_height < mc_height )
	{
		$('#modal-content').css({ top: '10px', left: ''+ mc_left +'px' });
		$('#modal-overlay').height(interface_height).width(vp_width);
	}
	if ( vp_width < interface_width && vp_height > interface_height  )
	{
		$('#modal-content').css({ top: ''+ mc_top +'px', left: '100px' });
		$('#modal-overlay').height(vp_height).width(interface_width);
	}
	if ( vp_width < interface_width && vp_height < interface_height )
	{
		$('#modal-content').css({ top: '10px', left: '100px' });
		$('#modal-overlay').height(interface_height).width(interface_width);
	}
	else if ( vp_width > interface_width && vp_height > interface_height )
	{
		$('#modal-content').css({ top: ''+ mc_top +'px', left: ''+ mc_left +'px' });
		$('#modal-overlay').height(vp_height).width(vp_width);
	}
}

$(window).resize(function(){
	checkModalEnvironment();
}); 

function modalPopup()
{
	checkModalEnvironment();
	
	$('#launch').click(function(){
		$('#modal-overlay').fadeIn(500);
		$('#modal-content').fadeIn(500);
		return false;
	});
	
	current_slide = 0;
	total_slides = $('#slides li').length - 1;
	
	// slide navigation
	$('.arrow-next').click(function(){
		
		current_slide++;
		if ( current_slide > total_slides )
		{
			current_slide = 0;
			$('#slides li').fadeOut(500);
			$('#slides li:eq('+ current_slide +')').fadeIn(750);
			return false;	
		}
		else
		{
			$('#slides li').fadeOut(500);
			$('#slides li:eq('+ current_slide +')').fadeIn(750);
			return false;	
		}
		
	});
	
	$('.arrow-previous').click(function(){
		
		current_slide--;
		
		if ( current_slide < 0 )
		{
			current_slide = total_slides;
			$('#slides li').fadeOut(500);
			$('#slides li:eq('+ current_slide +')').fadeIn(750);
			return false;	
		}
		else
		{
			$('#slides li').fadeOut(500);
			$('#slides li:eq('+ current_slide +')').fadeIn(750);
			return false;	
		}
		
	});
	
	$('#slides').addLoader();
	
	$('#close-modal').each(
		function()
		{
			$(this).click(function(){
				$('#modal-overlay').fadeOut(500);
				$('#modal-content').fadeOut(500);
				return false;
			});
		}
	);
	
	escapeToClose();
	
}

function escapeToClose(){
	// hit esc to close modal
	$(document).keyup(function(event){
		if (event.keyCode == 27) {
			$('#modal-overlay').fadeOut(500);
			$('#modal-content').fadeOut(500);
		}
	});
}


function mergerSlides()
{
	$('#slides li:eq(0)').css({opacity: 0}).show().animate(
	{ opacity: 1 },
	{
		queue: false,
		duration: 750,
		easing: 'easeInSine'
	});	
}


/*

function rotateSlides()
{
	current_slide++;
	
	if ( current_slide == total_slides )
	{
		current_slide = 0;
		$('#slides li').fadeOut(500);
		$('#slides li.photo-1').fadeIn(750);
		return false;
	}
	else
	{
		$('#slides li').fadeOut(500);
		$('#slides li:eq('+ current_slide +')').fadeIn(750);
		return false;
	}	
}

function automateSlides()
{
	current_slide = 0;
	total_slides = $('#location-navigation li').length;
	rotate_slides = setInterval("rotateSlides()", 5000);
}

*/
