function getPageSizeWithScroll(){
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
	}
	arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
	//alert( 'The height is ' + yWithScroll + ' and the width is ' + xWithScroll );
	return arrayPageSizeWithScroll;
}

function getScrollTop(){
	if(typeof pageYOffset!= 'undefined'){
		//most browsers
		return pageYOffset;
	}
	else{
		var B= document.body; //IE 'quirks'
		var D= document.documentElement; //IE with doctype
		D= (D.clientHeight)? D: B;
		return D.scrollTop;
	}
}

function getElementHeight(elem) {
	return elem.offsetHeight;
}

function getElementWidth(elem) {
	return elem.offsetWidth;
}






/*var item_arr = new Array({name: "Faux Comic Book Cover",
										image_arr: new Array("images/fullsize/cover.jpg"),
										description: "<p>This one was done as a Christmas present in 2008. It&rsquo;s a parody of the Marvel Team-Up comic book series, with my brother-in-law&rsquo;s face on the villain Doctor Doom.</p>"},
									
									{name: "Dirk Maximus Site Banner",
										image_arr: new Array("images/fullsize/dirk_banner.jpg")},
									
									{name: "Catwoman Wallpaper",
										image_arr: new Array("images/fullsize/catwoman.jpg")},
									
									{name: "Dr. No Poster",
										image_arr: new Array("images/fullsize/honeychile.jpg")},
									
									{name: "Voltron Poster",
										image_arr: new Array("images/fullsize/voltron.jpg")},
									
									{name: "HackMaster",
										url: "http://www.kenzerco.com/hackmaster",
										image_arr: new Array("images/fullsize/hackmaster.jpg"),
										description: '<p>When I decided to start up freelance work, I happened across a request for a site design on the forums of <a href="http://kenzerco.com">Kenzer &amp; Company</a>. It was more or less a freebie for them, and in addition to taking advantage of an opportunity to work with a client whose work I admired and was familiar with, I used it as a way to get my feet wet with designing again. I&rsquo;m not really sure what happened to this on their end, as I finished not only the design, but the entire site development, which included integrating content provided by them into my pages. With luck, this will end up live sometime in the future!</p>'},
									
									{name: "Sauerkraut 20K 2008 Shirt",
										image_arr: new Array("images/fullsize/sauerkraut_2k8.jpg"),
										description: "<p>After a number of years volunteering to help hand out water at the Sauerkraut Festival 20k race held annually in Phelps NY, I was asked to start designing the t-shirts that are given out to runners and volunteers. I created the cabbage graphic one year, and have tried to incorporate it each year since as a logo of sorts for the race.</p>"},
									
									{name: "Old Portfolio",
										url: 'http://dirkmaximus.com/portfolio_old',
										image_arr: new Array("images/fullsize/spy_portfolio2.jpg",
																		"images/fullsize/spy_portfolio3.jpg",
																		"images/fullsize/spy_portfolio4.jpg",
																		"images/fullsize/spy_portfolio5.jpg",
																		"images/fullsize/spy_portfolio6.jpg"),
										description: '<p>This is my old Flash portfolio site, created in my final year of college. Its content is now outdated and my interest in Flash has since shifted from sites to games, but I think this design still merits a mention. The scrolling parallax animation from scene to scene was successful in catching attention, and this site got me into few interviews with solid companies in the months after I graduated.</p>'},
									
									{name: "Wedding Invitation",
										image_arr: new Array("images/fullsize/wedding_invite_chris.jpg"),
										description: "<p>The paper cut-out look for this invitation helped give the invitation a craft-y feel that I felt was appropriate for a wedding invitation.</p>"},
									
									{name: "RIT Dept. of Communication Poster",
										image_arr: new Array("images/fullsize/rit_doc_admit_one.jpg")},
									
									{name: "Colgate Donation Doubler Game",
										url: "http://www.colgateclonation.com/donation_doubler/index.php",
										image_arr: new Array("images/fullsize/donation_doubler1.jpg",
																		"images/fullsize/donation_doubler2.jpg",
																		"images/fullsize/donation_doubler3.jpg",
																		"images/fullsize/donation_doubler4.jpg",
																		"images/fullsize/donation_doubler5.jpg",
																		"images/fullsize/donation_doubler6.jpg",
																		"images/fullsize/donation_doubler7.jpg")},
									
									{name: "Motorola Scanvisor",
										url: "http://motorola.com/scanvisor",
										image_arr: new Array("images/fullsize/scanvisor1.jpg",
																		"images/fullsize/scanvisor2.jpg",
																		"images/fullsize/scanvisor3.jpg",
																		"images/fullsize/scanvisor4.jpg",
																		"images/fullsize/scanvisor5.jpg"),
										description: "<p>This site is used to view available Motorola scanners and filter out those that do not have the desired features. The dynamic content, which includes capabilities for multiple languages, is stored in XML files rather than a database to allow the site to be distributed via CD as well as viewed online. I eventually also created a system to allow the data to be stored in Excel files which the client could edit and then convert to the necessary XML files automatically.</p>"},
									
									{name: "Motorola Solution Advisor",
										url: "http://www.firstcommunicate.com/motorola/supply_chain/s49704/",
										image_arr: new Array("images/fullsize/solution_advisor1.jpg",
																		"images/fullsize/solution_advisor2.jpg",
																		"images/fullsize/solution_advisor3.jpg",
																		"images/fullsize/solution_advisor4.jpg",
																		"images/fullsize/solution_advisor5.jpg",
																		"images/fullsize/solution_advisor6.jpg")},
									
									{name: "GE Energy Savings Calculator",
										url: "http://hostimages.com/GE/56443_new/",
										image_arr: new Array("images/fullsize/ge_energy1.jpg",
																		"images/fullsize/ge_energy2.jpg")},
									
									{name: "Caesars Pocono Resorts",
										url: "http://covepoconoresorts.com",
										image_arr: new Array("images/fullsize/caesars1.jpg",
																		"images/fullsize/caesars2.jpg",
																		"images/fullsize/caesars3.jpg",
																		"images/fullsize/caesars4.jpg")},
																		
									{name: "HackMaster Illustration",
										url: "http://www.kenzerco.com/hackmaster",
										image_arr: new Array("images/fullsize/hackmaster_illustration.jpg"),
										description: '<p>This illustration was created for use in my HackMaster site design for Kenzer &amp; Company. I wanted to make sure that the new basic rulebook was on the front page, so rather than reuse the illustration from the cover of that book in the site banner, I decided to take a stab at some fantasy player characters. Creating a custom image for the front page also allowed me to have something that would fade to the background color of the site on all sides naturally and by design.</p>'},
										
									{name: "The Old Farmhouse",
										image_arr: new Array("images/fullsize/farmhouse.jpg")},
										
									{name: "Motorola Network Security Services Assessment",
										url: "http://www.hostimages.com/motorola/security_services/s51477/",
										image_arr: new Array("images/fullsize/security_assessment1.jpg",
																		"images/fullsize/security_assessment2.jpg",
																		"images/fullsize/security_assessment3.jpg",
																		"images/fullsize/security_assessment4.jpg",
																		"images/fullsize/security_assessment6.jpg",
																		"images/fullsize/security_assessment7.jpg",
																		"images/fullsize/security_assessment8.jpg")},
																		
									{name: "Delduchetto &amp; Potter",
										url: "http://www.dpmedlaw.com",
										image_arr: new Array("images/fullsize/dp1.jpg",
																		"images/fullsize/dp2.jpg",
																		"images/fullsize/dp3.jpg")},
																		
									{name: "Transitions Live Your Vision Challenge",
										url: "http://hostimages.com/transitions/t56304/",
										image_arr: new Array("images/fullsize/transitions1.jpg",
																		"images/fullsize/transitions2.jpg",
																		"images/fullsize/transitions4.jpg",
																		"images/fullsize/transitions5.jpg",
																		"images/fullsize/transitions6.jpg",
																		"images/fullsize/transitions7.jpg")},
																		
									{name: "MC17 Retail Mobile Computer",
										url: "http://hostimages.com/motorola/mcd/m6113/",
										image_arr: new Array("images/fullsize/mc17_1.jpg",
																		"images/fullsize/mc17_2.jpg",
																		"images/fullsize/mc17_3.jpg",
																		"images/fullsize/mc17_4.jpg",
																		"images/fullsize/mc17_5.jpg")},
																		
									{name: "Project Home Again",
										url: "http://www.projecthomeagain.com/",
										image_arr: new Array("images/fullsize/homeagain1.jpg",
																		"images/fullsize/homeagain2.jpg",
																		"images/fullsize/homeagain3.jpg",
																		"images/fullsize/homeagain4.jpg")},
																		
									{name: "Reporter Magazine Illustrations",
										image_arr: new Array("images/fullsize/reporter_1.jpg",
																		"images/fullsize/reporter_2.jpg",
																		"images/fullsize/reporter_3.jpg")},
																		
									{name: "RIT Student Government and Hillel Holocaust Week Promotional Design",
										image_arr: new Array("images/fullsize/sg_hillel_1.jpg",
																		"images/fullsize/sg_hillel_2.jpg",
																		"images/fullsize/sg_hillel_3.jpg")});*/












function load_into_popup_image(path) {
	/*$image_width = $("img#popup_image").width();
	$image_height = $("img#popup_image").height();
	
	if($image_width != null && $image_height != null) {
		$('div#popup_image_container').css('width', $image_width + 'px');
		$('div#popup_image_container').css('height', $image_height + 'px');
	}*/
	
	$("img#popup_image").unbind('load');
	$('div#popup_image_container').html('<img src="' + path + '" alt="" id="popup_image" />');
	//$('img#popup_image').attr('src', path);
	
	$("img#popup_image").load(function(evt){
		//alert("load");
		popup_content_size();
	});

	/*if($("img#popup_image")[0].complete){
		alert("complete");
		popup_content_size();
	}else{
		$("img#popup_image").load(function(evt){
			alert("load");
			popup_content_size();
		});
	}*/
}











function open_popup(title, copy, link, image_path_arr) {
	//get the size of the page
	var size_arr = getPageSizeWithScroll();
	
	//set the popup
	var popup = document.getElementById('item_popup');
	popup.style.height = size_arr[1] + 'px';
	
	//set the black transparent background
	var background = document.getElementById('background');
	background.style.height = size_arr[1] + 'px';
	
	//set up the loading animation
	var scroll_top = getScrollTop();
	var loading_circle = document.getElementById('loading_circle');
	loading_circle.style.top = scroll_top + 250 + 'px';
	loading_circle.style.display = "block";
	
	//set the content location
	var content = document.getElementById('popup_content');
	content.style.top = scroll_top + 50 + 'px';
	
	//display the popup
	popup.style.display = 'block';
	
	//load the first image for this item
	//var start_image = item_arr[num].image_arr[0];
	var start_image = image_path_arr[0];
	load_into_popup_image(start_image);
	
	//load the image nav if there is more than one image
	var img_nav_ul = document.getElementById('img_nav');
	if(image_path_arr.length > 1) {
		img_nav_ul.style.display = "block";
		
		var html_str = '<li id="prev"><a href="" onclick="prev_image();return false;">&lt;</a></li>';
		for(var i = 0; i < image_path_arr.length; i++) {
			if(i == 0) {
				html_str += '<li class="selected"><a href="'+ image_path_arr[i] + '" onclick="new_image(' + i + ', this);return false;">' + (i + 1) + '</a></li>';
			}else{
				html_str += '<li><a href="'+ image_path_arr[i] + '" onclick="new_image(' + i + ', this);return false;">' + (i + 1) + '</a></li>';
			}
			
			if(image_path_arr.length > 15 && i > image_path_arr.length / 2) {
				html_str += '<div class="clear"></div>';
			}
		}
		html_str += '<li id="next"><a href="" onclick="next_image();return false;">&gt;</a></li>';
		html_str += '<div class="clear"></div>';
		
		img_nav_ul.innerHTML = html_str;
	}else {
		img_nav_ul.style.display = "none";
		img_nav_ul.innerHTML = "";
	}
	
	//create the title and site link if available
	var text_content_div = document.getElementById("text_content");
	html_str = '<h1>' + title;
	
	if(link != undefined) {
		html_str += ' - <a href="' + link + '" target="_blank">View the site</a>';
	}
	
	html_str  += '</h1>';
	
	//create the description if available
	if(copy != undefined) {
		html_str += copy;
	}
	
	text_content_div.innerHTML = html_str;
}

function new_image(num, path) {
	//var popup_image = document.getElementById("popup_image");
	
	load_into_popup_image(path);
	
	var img_nav_ul = document.getElementById('img_nav');
	
	var li_arr = img_nav_ul.getElementsByTagName("li");
	var nav_arr = new Array();
	for(var i = 0; i < li_arr.length; i++) {
		var li = li_arr[i];
		
		if(li.getAttribute("id") != "prev" && li.getAttribute("id") != "next") {
			nav_arr.push(li);
		}
	}
	
	for(var i = 0; i < nav_arr.length; i++) {
		var li = nav_arr[i];
		
		if(i != num) {
			li.className = "";
		}else {
			li.className = "selected";
		}
	}
	
	$('#image_loading_circle').css('display', 'block');
}

function prev_image() {
	var num;
	var path;
	
	var img_nav_ul = document.getElementById('img_nav');
	var li_arr = img_nav_ul.getElementsByTagName("li");
	var nav_arr = new Array();
	for(var i = 0; i < li_arr.length; i++) {
		var li = li_arr[i];
		
		if(li.getAttribute("id") != "prev" && li.getAttribute("id") != "next") {
			nav_arr.push(li);
		}
	}
	
	for(var i = 1; i < nav_arr.length; i++) {
		var li = nav_arr[i];
		
		if(li.className == "selected") {
			num = i - 1;
			var new_li = nav_arr[num];
			path = new_li.getElementsByTagName("a")[0];
		}
	}
	
	if(typeof(num) != "number") {
		return;
	}
	
	$('#image_loading_circle').css('display', 'block');
	
	//var popup_image = document.getElementById("popup_image");
	load_into_popup_image(path);
	
	for(var i = 0; i < nav_arr.length; i++) {
		var li = nav_arr[i];
		if(i != num) {
			li.className = "";
		}else {
			li.className = "selected";
		}
	}
}

function next_image() {
	var num;
	var path;
	
	var img_nav_ul = document.getElementById('img_nav');
	var li_arr = img_nav_ul.getElementsByTagName("li");
	var nav_arr = new Array();
	for(var i = 0; i < li_arr.length; i++) {
		var li = li_arr[i];
		
		if(li.getAttribute("id") != "prev" && li.getAttribute("id") != "next") {
			nav_arr.push(li);
		}
	}
	
	for(var i = 0; i < nav_arr.length - 1; i++) {
		var li = nav_arr[i];
		
		if(li.className == "selected") {
			num = i + 1;
			var new_li = nav_arr[num];
			path = new_li.getElementsByTagName("a")[0];
		}
	}
	
	if(typeof(num) != "number") {
		return;
	}
	
	$('#image_loading_circle').css('display', 'block');
	
	//var popup_image = document.getElementById("popup_image");
	load_into_popup_image(path);
	
	for(var i = 0; i < nav_arr.length; i++) {
		var li = nav_arr[i];
		if(i != num) {
			li.className = "";
		}else {
			li.className = "selected";
		}
	}
}















function close_popup() {
	
	
	//reset the image
	$('div#popup_image_container').html('');
	$('div#popup_image_container').css('width', 'auto');
	$('div#popup_image_container').css('height', 'auto');
	
	//hide the content
	var content = document.getElementById('popup_content');
	content.style.display = "none";
	
	//hide the popup
	var popup = document.getElementById('item_popup');
	popup.style.display = 'none';
}

function popup_content_size() {
	//hide the loading animations
	$('#image_loading_circle').css('display', 'none');
	$('#loading_circle').css('display', 'none');
	
	//show the content
	var content = document.getElementById('popup_content');
	var popup_image = document.getElementById("popup_image");
	content.style.display = "block";
	content.style.width = getElementWidth(popup_image) + 'px';
	
	//set size
	$image_width = $("img#popup_image").width();
	$image_height = $("img#popup_image").height();
	
	if($image_width != null && $image_height != null) {
		$('div#popup_image_container').css('width', $image_width + 'px');
		$('div#popup_image_container').css('height', $image_height + 'px');
	}
	
	//make the background grow if needed based on the content size
	var scroll_top = getScrollTop();
	var content_height = getElementHeight(content);
	
	var background = document.getElementById('background');
	var background_height = background.style.height;
	background_height = background_height.replace('px', '');
	
	var popup = document.getElementById('item_popup');
	
	if(scroll_top + 50 + content_height > background_height) {
		popup.style.height = scroll_top + 50 + content_height + 'px';
		background.style.height = scroll_top + 50 + content_height + 'px';
	}
}
