$('document').ready(function() {
	
	
	/**** VARIABLE DECLARATIONS ****/
	/****************************************************************************************/
	
	var contentActive = false;
	var ssFvActive = false;
	var fvAllowed = false;
	var ssPauseLoc;
	var activeContent;
	var spacerHeight;
	var txtActive;
	var scrollPosition;
	var portFullSizeActive = false;
	var pageHeight = $(document).height();
	
	
	//Define content area height when active
	var cHeight = new Array(2350,675,2050,1367,700);
	
	//Define pixel position for different active content
	var pixelPosition = new Array('20%','35%','49%','63%','77%');
	
	//Create Object for slideshow css variables
	var cssHolder = {};	
	var ssPosition;
	var fvContent;
	
	//Slideshow data, EVEN NUMBERS PLEASE
	var ssArray = new Array();
	//Elements in array ( MEDIA TYPE {1=jpg, 2=vid, 3=swf}, THUMBNAIL NAME, FULL VIEW FILE (flv location), WIDTH, HEIGHT)
	ssArray.push(new Array(2,'images/ss/showcase_1.jpg','video/showcase_1.flv',640,480));
	ssArray.push(new Array(2,'images/ss/showcase_2.jpg','video/showcase_2.flv',800,600));
	ssArray.push(new Array(3,'images/ss/showcase_3.jpg','swf/SSPlayer.swf',900,650));
	ssArray.push(new Array(3,'images/ss/showcase_4.png','nerc/player.swf',1000,650));
	
	//Portfolio Section data
	var portArray = new Array();
	//Elements in array ( MEDIA TYPE {1=jpg, 2=vid, 3=swf, 4=web}, FULL VIEW FILE, DESCRIPTION TEXT, HYPERLINK URL)
	portArray.push(new Array(3,'swf/interactive_1.swf','Game developed to utilize questions the students had studied during lesson videos.  Adding a game makes review activities fun and something the viewer enjoys doing.'));
	portArray.push(new Array(3,'swf/interactive_2.swf','Students had been studying Pompei, and in this particular activity they learn more about the parts of a Volcano.'));
	portArray.push(new Array(3,'swf/interactive_3.swf','Simple page flip interaction that allows the student to be a bit more actively engaged with some audio content.'));
	portArray.push(new Array(3,'swf/interactive_4.swf','HR piece done to train drivers on the dangers of distracted driving and inform them of company policy regarding the issue.'));
	portArray.push(new Array(3,'swf/interactive_5.swf','Review game that asks questions prior to the game.  In this example the better the student does on their questions the more time they earn to complete their sub mission.'));
	portArray.push(new Array(3,'swf/interactive_6.swf','Simple branching interaction that integrates video responses to student selections.',655,510));
	portArray.push(new Array(2,'video/vid_1.flv','This video demonstrates how green screen is utilized to produce a more engaging and vivid final product.'));
	portArray.push(new Array(2,'video/vid_2.flv','Also produced via a green screen background, this example illustrates a business marketing application.'));
	portArray.push(new Array(2,'video/vid_3.flv','This video demonstrates various overlay effects and was used as a bumper video for a timeline based interaction.'));
	portArray.push(new Array(2,'video/vid_4.flv','Educational video, used in a history course to showcase various gargoyle styles.  Utilizes custom animation and motion graphics.'));
	portArray.push(new Array(2,'video/vid_5.flv','Show reel demonstrating custom 3d modeling and animations produced for educational courses.'));
	portArray.push(new Array(2,'video/vid_6.flv','Animated character utilized to help better engage younger target audience.'));
	portArray.push(new Array(1,'images/portfolio/articulate/art_1_full.jpg','Extending upon Articulates capabilities with a custom video playback component that pulls video files from a Content Delivery Network and Flash content for various interactive slides.'));
	portArray.push(new Array(1,'images/portfolio/articulate/art_2_full.jpg','Developing content to meet all budgets.  Simple but attractive design staying within the capabilities of Articulate with minimal custom Flash to meet clients budget.'));
	portArray.push(new Array(1,'images/portfolio/articulate/art_3_full.jpg','A nation wide real estate continuing education project.  Client needed a solution to make sure students met state required seat time within a course.  HMI developed custom code to extend Articulate to fufill this need.'));
	
	portArray.push(new Array(1,'images/portfolio/print/print_1_full.jpg','Identity system for a landscaping and excavation company.'));
	portArray.push(new Array(1,'images/portfolio/print/print_2_full.jpg','Church capital campaign materials.'));
	portArray.push(new Array(1,'images/portfolio/print/print_6_full.jpg','Identity system for an organic hair products company.'));
	
	
	portArray.push(new Array(4,'images/portfolio/web/web_1_full.jpg','Flash website developed for client, utilizing smooth transitions and pleasant effects to create the right kind of atmosphere for their customers.','http://bluerockgourds.com'));
	portArray.push(new Array(4,'images/portfolio/web/web_2_full.jpg','','http://phillipsgraphicfinishing.com/'));
	portArray.push(new Array(4,'images/portfolio/web/web_3_full.jpg','','http://www.pandmbg.com/'));
	
	
	//detect browser type and version
	var browser = hmiFunctions.browserDetect();
	
	//detect if flash
	var flashVersionObject = swfobject.getFlashPlayerVersion();
	var flashV = flashVersionObject.major;
	
	
	/**** PAGE SETUP ****/
	/****************************************************************************************/
	
	
	$('html, body').animate({scrollTop:0}, 500);
	
	if (pageHeight > 700) {
		$("#pagewrap").height(pageHeight * 1.1);
	}
	else {
		$("#pagewrap").height(800);
	}
	spacerUpdate();
	updateAdj();
	footerUpdate();
	ssInit();
	
	$(window).resize(function() {
	  if(!contentActive) {
	  	windowHeight = $(window).height();
	  	$("#pagewrap").height(windowHeight * 1.1);
	  	
	  	//spacerUpdate();
	  	updateAdj();
	  	footerUpdate();
	  }
	});
	
	function updateAdj() {
		var wh = $(window).height();
		if (wh < 600) {
			resizeAdj = .7;
		}
		else if (wh < 700) {
			resizeAdj = .8;
		}
		else if (wh < 900) {
			resizeAdj = .9;
		}
		else {
			resizeAdj = 1;
		}
	}
	
	/**** BUTTON PROGRAMMING ****/
	/****************************************************************************************/
	
	
	$('#logo').click(function() {
		resetNav(true,0);
	});
	
	$("#nav1").click(function() {
		if (contentActive) {resetNav(false,1); }
		else {showContent(1,cHeight[0]);}
	});
	
	$("#nav2").click(function() {
		if (contentActive) {resetNav(false,2); }
		else {showContent(2,cHeight[1]);}
	});	
	
	$("#nav3").click(function() {
		if (contentActive) {resetNav(false,3); }
		else {showContent(3,cHeight[2]);}
	});
	
	$("#nav4").click(function() {
		if (contentActive) {resetNav(false,4); }
		else {showContent(4,cHeight[3]);}
	});
	
	$("#nav5").click(function() {
		if (contentActive) {
			resetNav(false,5); }
		else {
			showContent(5,cHeight[4]);
		}
		$('.smallField').val("");
		$('.largeField').val("");
	});
	
	
	/**** SS FUNCTIONS ****/
	/****************************************************************************************/
	
	
	function ssInit() {
		
		//Add slide show housings
		$('#ssi').append('<div id=ss0 />');
		$('#ssi').append('<div id=ss1 />');
		
		//Add click listeners to slide show holders
		$('#ss0').click(function(event) {ssClicked(event);});
		$('#ss1').click(function(event) {ssClicked(event);});
			
		//Build CSS variables	
		for (i=0;i<ssArray.length;i = i + 2) {
			
			var img1 = ssArray[i][1];
			var img2 = ssArray[i + 1][1];
					
			cssHolder['css' + i] = {display : 'none', backgroundImage : 'url(' + img1 + ')', width : '335px', height : '370px', marginTop : '5px', marginLeft : '5px', overflow : 'hidden'}
			cssHolder['css' + (i + 1)] = {display : 'none', backgroundImage : 'url(' + img2 + ')', width : '635px', height : '370px', marginTop : '5px', marginLeft : '5px', overflow : 'hidden'}	
		}	
		
		//Define val variable and animate in the slide show housings
		$("#ss0").data("val",0).animate({marginLeft:'-500px'}, 1000);
		$("#ss1").data("val",1).animate({marginLeft:'-145px'}, 1000);
		setTimeout(ss1show, 1000);
	}
	
	function ss1show() {
		if (!ssFvActive) {
			if (!portFullSizeActive) {
				//Add content holders, apply css and fade in
				$('#ss0').append('<div id=ssc0 />');
				$('#ss1').append('<div id=ssc1 />');
				$('#ssc0').css(cssHolder['css' + $('#ss0').data("val")]).fadeIn(1000);
				$('#ssc1').css(cssHolder['css' + $('#ss1').data("val")]).fadeIn(1000);
				fvAllowed = true;
				setTimeout(ss2tran, 5000);
			}
			else {
				ssPauseLoc = 'ss1show';
			}
		}
	}
	
	function ss2tran() {
		if (!ssFvActive) {
			if (!portFullSizeActive) {
				//Animate size adjustment of both housings and images
				$("#ss0").animate({width:'645px'}, 1000);
				$("#ss1").animate({width:'345px',marginLeft:'155px'}, 1000);
				if ((browser[0] == 'Explorer') && (browser[1] < 9)) {
					$('#ssc0').animate({width:'635px', backgroundPositionX:'-10px'}, 1000);
					$('#ssc1').animate({width:'335px', backgroundPositionX:'-300px'}, 1000);
				}
				else {
					$('#ssc0').animate({width:'635px',backgroundPosition:'-10px 0px'}, 1000);
					$('#ssc1').animate({width:'335px',backgroundPosition:'-300px 0px'}, 1000);
				}
				setTimeout(ss2hide, 5000);
			}
			else {
				ssPauseLoc = 'ss2tran';
			}
		}
	}
	
	function ss2hide() {
		if (!ssFvActive) {
			if (!portFullSizeActive) {
				//Fade out images
				$('#ssc0').fadeOut(1000);
				$('#ssc1').fadeOut(1000);
				setTimeout(ss1tran, 1000);
			}
			else {
				ssPauseLoc = 'ss2hide';
			}
		}
	}
	
	function ss1tran() {
		if (!ssFvActive) {
			if (!portFullSizeActive) {
				fvAllowed = false;
				
				//Remove images and send housings off page
				$('#ssc0').remove();
				$('#ssc1').remove();
				$("#ss0").animate({marginLeft:'-1700px'}, 1000);
				$("#ss1").animate({marginLeft:'1500px'}, 1000);
				setTimeout(ss1tran2, 1000);
			}
			else {
				ssPauseLoc = 'ss1tran';
			}
		}
	}
	
	function ss1tran2() {
		if (!ssFvActive) {
			if (!portFullSizeActive) {
				//Reset housings and animate return
				$('#ss0').width(345).animate({marginLeft:'-500px'}, 1000);
				$('#ss1').width(645).animate({marginLeft:'-145px'}, 1000);
				
				//Update object variables for next set of slides
				$('#ss0').data('val',($('#ss0').data('val') + 2));
				$('#ss1').data('val',($('#ss1').data('val') + 2));
				if ($('#ss1').data('val') > ssArray.length) {
					$('#ss0').data('val',0);
					$('#ss1').data('val',1);
				}
				
				setTimeout(ss1show,1000);
			}
			else {
				ssPauseLoc = 'ss1tran2';
			}
		}
	}
	
	function ssClicked(event) {
		if (fvAllowed) {
			ssFvActive = true;
			ssPosition = $('#ss0').data("val");
			fvContent = $(event.target).parent().data('val');
			
			//Remove click listener and hide housings
			$('#ss0').unbind('click').animate({marginLeft:'-1700px'}, 300);
			$('#ss1').unbind('click').animate({marginLeft:'1500px'}, 300);
			
			//Define and calculate new page height
			fvPageAdjust(0);
		}
	}
	
	function showFv(fvhAdj) {			
		footerUpdate();
		
		//if fvhAdj is not zero then animate it into position	
		if (fvhAdj != 0) {
			$('#fvh').width((ssArray[fvContent][3] + 10)).height((ssArray[fvContent][4] + 10)).css({marginLeft:fvhAdj}).show().animate({marginLeft:-((ssArray[fvContent][3] + 10) / 2)},800);
		}
		else {
			//Add navigation and fullsize container
			$('#ssi').append('<div id=larrow />').append('<div id=rarrow />').append('<div id=fvh><div id=fv ></div></div>');
			$('#ssi').append('<div id=close />');
			$('#fvh').width((ssArray[fvContent][3] + 10)).height((ssArray[fvContent][4] + 10)).css({marginLeft:-((ssArray[fvContent][3] + 10) / 2)}).fadeIn(500);
		}
		
		//Handle different media types
		if (ssArray[fvContent][0] == 1) {
			$('#fv').width(ssArray[fvContent][3]).height(ssArray[fvContent][4]).css({marginLeft: -(ssArray[fvContent][3] / 2), 'background-image':'url(' + ssArray[fvContent][2] + ')'});
			$('#fv').delay(500).fadeIn(1500);
		}
		else if (ssArray[fvContent][0] == 2) {
			$('#fv').width(ssArray[fvContent][3]).height(ssArray[fvContent][4]).css({marginLeft: -(ssArray[fvContent][3] / 2)}).show();
			
			if (ssArray[fvContent][3] == 800) {
				setTimeout(function() { addVideoPlayer('swf/videoPlayer_800x600.swf',ssArray[fvContent][2]); },800);
			}
			if (ssArray[fvContent][3] == 640) {
				setTimeout(function() { addVideoPlayer('swf/videoPlayer_640x480.swf',ssArray[fvContent][2]); },800);
			}
		}
		else if (ssArray[fvContent][0] == 3) {
			$('#fv').width(ssArray[fvContent][3]).height(ssArray[fvContent][4]).css({marginLeft: -(ssArray[fvContent][3] / 2)}).show();
			//setTimeout(function() { addSwfLoader('swf/swfPreloader_800x550.swf',ssArray[fvContent][2]); },800);
			setTimeout(function() { addSwfLoader(ssArray[fvContent][2],0); },800);
		}
		
		$('#close').delay(500).animate({marginLeft:((ssArray[fvContent][3] / 2) - 55)},3000).css('cursor','pointer').click(function() {resetSS();});		
		$('#larrow').css({marginLeft:-(((ssArray[fvContent][3] + 10) / 2) + 46), 'cursor':'pointer'}).click(function() {prevFv();});
		$('#rarrow').css({marginLeft:(((ssArray[fvContent][3] + 10) / 2) + 20), 'cursor':'pointer'}).click(function() {nextFv();});
			
		setTimeout(updateArrowVisibility,2000);
	}
	
	function nextFv() {
		if (fvContent < (ssArray.length - 1)) {
			blowFvNav();
			$('#fv').fadeOut(500);
			$("#fvh").delay(500).animate({marginLeft:'-2000px'},800);
			fvContent++;
			setTimeout(function() { fvPageAdjust(1800); },1300);
		}
	}
	
	function prevFv() {
		if (fvContent > 0) {
			blowFvNav();
			$('#fv').fadeOut(500);
			$("#fvh").delay(500).animate({marginLeft:'1500px'},800);
			fvContent--;
			setTimeout(function() { fvPageAdjust(-1800); },1300);
		}
	}
	
	function fvPageAdjust(an) {
		$('#fvh').empty();
		$('#fvh').append('<div id=fv />');
		
		var newHeight;
		if (contentActive) {
			newHeight = (ssArray[fvContent][4] - 400) + cHeight[activeContent - 1];
		}
		else {
			newHeight = (ssArray[fvContent][4] - 400);
		}	
		if (newHeight <= 0) {newHeight = 0;}
		
		//change height of pagewrap and ss container, scroll to top of ss container
		$("#pagewrap").height(pageHeight + newHeight);
		footerUpdate();
		$('#ss').animate({height:(ssArray[fvContent][4] + 70)}, 500, 'linear',function(){showFv(an);});
		
		if ($(window).height() < (ssArray[fvContent][4] + 150)) {
			$('html,body').animate({scrollTop: $("#ss").offset().top - 5}, 500);
		}
	}
	
	function updateArrowVisibility() {
		if (fvContent == (ssArray.length - 1)) {
			$('#rarrow').unbind('click').hide();
		}
		else {
			$('#rarrow').fadeIn(500);
		}
		if (fvContent == 0) {
			$('#larrow').unbind('click').hide();
		}
		else {
			$('#larrow').fadeIn(500);
		}
	}
	
	function blowFvNav() {
		removeVideo();
		removeSwf()
		$(".footer").css('visibility','hidden');
		$('#close').animate({marginLeft:'1500px'},500).unbind('click');
		$('#larrow').fadeOut(500).unbind('click');
		$('#rarrow').fadeOut(500).unbind('click');
	}
	
	function resetSS() {
		//Remove fv navitation and housing
		blowFvNav();
		$('#fvh').fadeOut(300);
		$('#ss').delay(500).animate({height:400}, 500);
		
		//Update window position if needed
		if ($(window).height() < (ssArray[fvContent][4] + 150)) {
			$('html, body').animate({scrollTop:0}, 500, 'linear', function(){restartSS();});
		}
		else {
			setTimeout(restartSS,500);
		}
	}
	
	function restartSS() {
		if (ssFvActive) {
			ssFvActive = false;
			
			//SS reset of elements
			$('#larrow').stop().remove();
			$('#rarrow').stop().remove();
			$('#fvh').stop().remove();
			$('#fv').stop().remove();
			$('#close').stop().remove();
			$('#ssc0').stop().remove();
			$('#ssc1').stop().remove();
			$('#ss0').stop().remove();
			$('#ss1').stop().remove();
			
			//Reset page size
			$("#pagewrap").height($(document).height() - (ssArray[fvContent][4] - 400));
			footerUpdate();
			
			//Add slide show housings
			$('#ssi').append('<div id=ss0 />');
			$('#ssi').append('<div id=ss1 />');
			
			//Add click listeners to slide show holders
			$('#ss0').click(function(event) {ssClicked(event);})
			$('#ss1').click(function(event) {ssClicked(event);})
			
			$("#ss0").data('val',ssPosition).animate({marginLeft:'-500px'}, 1000);
			$("#ss1").data('val',(ssPosition + 1)).animate({marginLeft:'-145px'}, 1000);
			
			setTimeout(ss1show,1000);
		}
	}
	
	function addVideoPlayer(sn,p1) {
		var fileArray = ssArray[fvContent][2].split(".");
				
		swfobject.embedSWF(sn,'fv',ssArray[fvContent][3],ssArray[fvContent][4],'10.0.0','swf/expressInstall.swf',{fileVar: "../" + p1,var2: 0, var3: 0}, {menu:"false", wmode: "transparent"}, {id: "vidPlayer", name: "vidPlayer"});
		if (flashV == 0) {
			$("#fv").append('<video id="html5vid" width="' + ssArray[fvContent][3] + '" height="' + ssArray[fvContent][4] + '" controls="controls" autoplay></video>');
			$("#html5vid").append('<source src="' + fileArray[0] + '.mp4" type="video/mp4"></source>');
			$("#html5vid").append('<source src="' + fileArray[0] + '.ogv" type="video/ogg"></source>');	
			$("#html5vid").append('<p>This content requires the Free Adobe Flash Player, <a href="http://get.adobe.com/flashplayer/" target="_blank">Get Flash Here</a> or an HTML5 capable browser.</p>');
			$("#html5vid").bind('ended', function(){
		        	removeVideo();
		        	resetSS();
			});
		}
		else {
			$('#fv').remove();
		}
	}
	
	window.videoFinished = function(vt) {
		if (portFullSizeActive) {
			setTimeout(removePortVid,500);
		}
		else {
			removeVideo();
			resetSS();
		}
	}
	
	function removeVideo() {
		if (flashV != 0) {
			swfobject.removeSWF("vidPlayer");
			$('#fvh').empty();
			$('#fvh').append('<div id=fv />');
		}
		else {
			$('#html5vid').remove();
		}
	}
	
	function addSwfLoader(sn,p1) {
		trace(	ssArray[fvContent][3] + ", " + ssArray[fvContent][4]);
		swfobject.embedSWF(sn,'fv',ssArray[fvContent][3],ssArray[fvContent][4],'10.0.0','swf/expressInstall.swf',{fileVar: p1,var2: 0, var3: 0}, {menu:"false", wmode: "transparent"}, {id: "swfPlayer", name: "swfPlayer"});
		if (flashV == 0) {
			$("#fv").append('This content requires the free Adobe Flash Player. <a href="http://get.adobe.com/flashplayer/" target="_blank">Get Flash Here</a>');
		}
		else {
			$('#fv').remove();
		}
	}
	
	function removeSwf() {
		if (flashV != 0) {
			swfobject.removeSWF("swfPlayer");
			$('#fvh').empty();
			$('#fvh').append('<div id=fv />');
		}
	}
	
	function resumeSS() {
		eval(ssPauseLoc + '()');
	}
	
	/**** NAVIGATION AND PAGE SETUP FUNCITONS ****/
	/****************************************************************************************/
	
	function spacerUpdate() {
		var windowHeight = $(window).height();
		if (windowHeight > 670) {
			spacerHeight = windowHeight * .05
			$("#spacer").height(spacerHeight);
		}
		else {
			$("#spacer").height(1);
		}
	}
	
	function footerUpdate(){
		$(".footer").css("visibility","visible");
	}
	
	function slidePixel(pixelMargin) {
		$("#pixel").show().css({opacity:0});
		$("#pixel").animate({marginLeft:pixelMargin, opacity: 1}, 100);
	}
	
	function hidePixel() {
		$("#pixel").animate({marginLeft:'0%', opacity: 0}, 100);
	}
	
	function showContent(cn,ch)
	{
		trace("show cn = " + cn + ", ch = " + ch);
		contentActive = true
		activeContent = cn;
		trace("open content box " + cn);
		$('#contentBox' + cn).show();
		var htmlHeight; 
		
		
		if (!ssFvActive) {
			htmlHeight = (ch + 950);
		}
		else {
			htmlHeight = (ch + 1165);
		}
		
		//Check that window height will be tall enough so that scroll position can be correct, if not increase new html height
		if (($(window).height() + 570) > htmlHeight) {
			htmlHeight = $(window).height() + 570;
		}
		
		$("#pagewrap").height(htmlHeight);
		
		$("#pixel").show().css({opacity:0});
		$("#pixel").animate({marginLeft:pixelPosition[activeContent - 1], opacity: 1}, 500);
		$('#contentBox' + cn).animate({ height: ch}, 500 );
		$('html,body').animate({scrollTop: $("#nav").offset().top - 1}, 500);
		
		
		setTimeout(footerUpdate,500);	
	}
	
	function resetNav(t,cn2)
	{
		if (cn2 == activeContent) {
			//Content already open, no need to do anything
		}
		else {
			$(".footer").css('visibility','hidden');
			$('#contentBox' + activeContent).animate({ height: "0px"}, 400 );
			
			if (t) {
				contentActive = false;
				$("#pixel").animate({marginLeft:0, opacity: 0}, 500);
				$('html, body').animate({scrollTop:0}, 500);
				if (ssFvActive) {
					//$('html').height(pageHeight + 300);
					$("#pagewrap").animate({height:(pageHeight + 215)},400);
				}
				else {
					//$("html").height(pageHeight);
					$("#pagewrap").animate({height:pageHeight},400);
				}
				setTimeout(footerUpdate,500);	
			}
			else {
				setTimeout(function() {showContent(cn2,cHeight[cn2 - 1]);}, 600);
			}
					
			setTimeout(function() { hideContent(t); },500);
		}
	}
	
	function hideContent(t)
	{
		trace("hide cn = " + activeContent);
		spacerUpdate();
		$('#contentBox' + activeContent).hide();
		if (t) {
			activeContent = 0;
		}
	}	
	
	
	
	
	/**** PORTFOLIO SECTION FUNCTIONS ****/
	/****************************************************************************************/
	
	

	for (i=1;i<25;i++) {
		$('#portTn' + i).data('val',i).css({cursor:'pointer'}).click(function(event) { reportTn(event); });
	}
	
	
	function reportTn(event) {
		$('#pagewrap').before('<div id="viewer"></div><div id="viewerBg"></div>');
		$('#viewer').height($('#pagewrap').height());
		$('#viewerBg').height($('#pagewrap').height());
		if (browser[0] == 'Explorer') {
			$('#viewerBg').show();
		}
		else {
			$('#viewerBg').fadeIn(1000);
		}
		var id = $(event.target).data('val');
		portFullSizeActive = true;
		if (portArray[id - 1][0] == 1) {
			var newImg = new Image();
			
			//if (browser[0] == 'Explorer') {
				//$(newImg).ready(function() { placeImg(newImg,id); });
			//}
			//else {
				$(newImg).load(function() { placeImg(newImg,id); });
			//}
			newImg.src = portArray[id - 1][1];
		}
		else if (portArray[id - 1][0] == 2) {
			placeVid(id);
		}
		else if (portArray[id - 1][0] == 3) {
			placeSwf(id);
		}
		else if (portArray[id - 1][0] == 4) {
			var newImg = new Image();
			
			//if (browser[0] == 'Explorer') {
				//$(newImg).ready(function() { placeImg(newImg,id); });
			//}
			//else {
				$(newImg).load(function() { placeImg(newImg,id); });
			//}
			newImg.src = portArray[id - 1][1];
		}	
	}
	            
	function placeImg(newImg,id) {
		curHeight = newImg.height * resizeAdj;
		curWidth = newImg.width * resizeAdj;
		scrollPosition = $(window).scrollTop();
		addIeShadow(curWidth,curHeight,scrollPosition);
		$('#viewer').append("<img src=" + portArray[id - 1][1] + " alt='Full Size Image' width='" + curWidth + "' height='" + curHeight + "' id='portFullImage' class='ds4' />")
		$('#portFullImage').css({display:'none',position:'absolute',left:'50%',marginLeft:-(curWidth / 2),marginTop:(scrollPosition + (($(window).height() - curHeight) / 2)) + "px",zIndex:'22'}).delay(1000).fadeIn(500);
		       
		$('#portFullImage').before('<div id=closePort />');
		
		$('#closePort').css({marginTop:((scrollPosition + (($(window).height() - curHeight) / 2)) - 10) + "px"}).animate({marginLeft:((curWidth / 2) - 80) + 'px'},2000).click(function() { removeFullImage(id); });
		
		$('#viewer').append('<div id="rollOver" ></div>');
		$('#rollOver').width(curWidth).height(curHeight).css({marginLeft:-(curWidth / 2),marginTop:(scrollPosition + (($(window).height() - curHeight) / 2)) + "px"})
		
		
		setTimeout(function() { addRollOverTreatment(id,scrollPosition,curWidth,curHeight); },2000);
		
		if (portArray[id - 1][3] != undefined) {
			$('#portFullImage').before('<div id=visitSite />');
			$('#visitSite').css({marginTop:((scrollPosition + (($(window).height() - curHeight) / 2)) + (curHeight - 10))}).animate({marginLeft:-((curWidth / 2) + 10)},2000).click(function() { window.open(portArray[id - 1][3]); });
		}
	}
	
	function addRollOverTreatment(id,sp,cw,ch) {
		$('#portFullImage').addClass('ds4');
		addTextBlock(1,portArray[id - 1][2],sp,cw,ch);
		$('#rollOver').mouseenter(function() { addTextBlock(1,portArray[id - 1][2],sp,cw,ch); }).mouseleave(function() { removeTextBlock(); });
	}
	
	function removeFullImage(id) {
		$('#rollOver').unbind();
		removeTextBlock()
		removeIeShadow();
		$('#closePort').animate({marginLeft:'1500px'},1000);
		if (portArray[id - 1][3] != undefined) {
			$('#visitSite').animate({marginLeft:'-1500px'},1000);
		}
		$('#portFullImage').fadeOut(500);
		$('#viewerBg').fadeOut(2000);
		setTimeout(function() { removePortImageElements(id); },2100);
	}
	
	function removePortImageElements(id) {
		portFullSizeActive = false;
		resumeSS();
		$('#portFullImage').remove();
		$('#closePort').remove();
		if (portArray[id - 1][3] != undefined) {
			$('#visitSite').remove();
		}
		$('#viewer').remove();
		$('#viewerBg').remove();
	}
	
	
	function placeVid(id) {
		scrollPosition = $(window).scrollTop() - 50;
		$('#viewer').append("<div id='portVid' ></div>");
		var fileArray = portArray[id - 1][1].split(".");
		
		swfobject.embedSWF('swf/videoPlayer_640x480.swf','portVid','640','480','10.0.0','swf/expressInstall.swf',{fileVar: "../" + portArray[id - 1][1],var2: 0, var3: 0}, {menu:"false", wmode: "transparent"}, {id: "vidPlayerPort", name: "vidPlayerPort"});
		
		
		if (flashV == 0) {
			$("#portVid").append('<video id="html5vidPort" width="640" height="480" controls autoplay></video>');
			$("#html5vidPort").append('<source src="' + fileArray[0] + '.mp4" type="video/mp4"></source>');
			$("#html5vidPort").append('<source src="' + fileArray[0] + '.ogv" type="video/ogg"></source>');	
			$("#html5vidPort").append('<p>This content requires the Free Adobe Flash Player, <a href="http://get.adobe.com/flashplayer/" target="_blank">Get Flash Here</a> or an HTML5 capable browser.</p>');
			$("#html5vidPort").bind('ended', function(){
		        	setTimeout(removePortVid,500);
			});
			$('#html5vidPort').addClass('ds4').css({position:'absolute',left:'50%',marginLeft:'-320px',marginTop:(scrollPosition + (($(window).height() - 480) / 2)) + "px",zIndex:'22'});
			$('#portVid').before('<div id=closePort />')
		}
		else {
			$('#vidPlayerPort').addClass('ds4').css({position:'absolute',left:'50%',marginLeft:'-320px',marginTop:(scrollPosition + (($(window).height() - 480) / 2)) + "px",zIndex:'22'});
			$('#vidPlayerPort').before('<div id=closePort />')
		}
		addIeShadow(640,480,scrollPosition);
		
		$('#closePort').css({marginTop:(scrollPosition + (($(window).height() - 480) / 2) - 10) + "px",cursor:'pointer'}).animate({marginLeft:'255px'},2000).click(function() { removePortVid(); });
		setTimeout(function() { addTextBlock(2,portArray[id - 1][2],scrollPosition,640,480); },2000);
	}
	
	
	function removePortVid() {
		removeTextBlock();
		removeIeShadow();
		$('#closePort').animate({marginLeft:'1500px'},1000);
		if (flashV == 0) {
			$("#html5vidPort").remove();
		}
		else {
			swfobject.removeSWF("vidPlayerPort");	
		}
		$('#viewerBg').fadeOut(2000);
		setTimeout(removePortVidElements,2100);
	}
	
	function removePortVidElements() {
		portFullSizeActive = false;
		resumeSS();
		$('#portVid').remove();
		$('#closePort').remove();
		$('#viewer').remove();
		$('#viewerBg').remove();
	}
	
	
	function placeSwf(id) {
		scrollPosition = $(window).scrollTop() - 20;
		$('#viewer').append("<div id='portSwf' ></div>");
		trace(portArray[id-1][1]);
		
		if (portArray[id-1][3] != undefined) {
			swfobject.embedSWF('swf/swfPreloader_' + portArray[id-1][3] + 'x' + portArray[id-1][4] + '.swf','portSwf',portArray[id-1][3],portArray[id-1][4],'10.1.0','swf/expressInstall.swf',{fileVar: portArray[id - 1][1],var2: 0, var3: 0}, {menu: 'false', wmode: "opaque"}, {id: "swfPortPlayer", name: "swfPortPlayer"});
			swfW = portArray[id-1][3];
			swfH = portArray[id-1][4];
		}
		else {		
			swfobject.embedSWF('swf/swfPreloader_800x550.swf','portSwf','800','550','10.1.0','swf/expressInstall.swf',{fileVar: portArray[id - 1][1],var2: 0, var3: 0}, {menu: 'false', wmode: "opaque"}, {id: "swfPortPlayer", name: "swfPortPlayer"});
			
			//swfobject.embedSWF(portArray[id - 1][1],'portSwf','800','550','10.0.0','swf/expressInstall.swf',{fileVar: 0,var2: 0, var3: 0}, {menu:"false", wmode: "transparent"}, {id: "swfPortPlayer", name: "swfPortPlayer"});
			swfW = 800;
			swfH = 550;
		}
		
		if (flashV == 0) {
			$("#portSwf").append('This content requires the free Adobe Flash Player version 10.1. <a href="http://get.adobe.com/flashplayer/" target="_blank">Get Flash Here</a>');
			$('#portSwf').before('<div id=closePort />');
			$('#portSwf').addClass('ds4').css({position:'absolute', backgroundColor:'#CCC', width:'800px', height:'550px', left:'50%', marginLeft:'-400px', marginTop:(scrollPosition + (($(window).height() - 550) / 2)) + "px", zIndex:'22'});
		}
		else {
			$('#portSwf').remove();
			$('#swfPortPlayer').before('<div id=closePort />');
			$('#swfPortPlayer').addClass('ds4').css({position:'absolute',left:'50%',marginLeft:-(swfW / 2),marginTop:(scrollPosition + (($(window).height() - swfH) / 2)) + "px",zIndex:'22'});
			$('body').css({overflow:'hidden'});
		}
		
		addIeShadow(swfW,swfH,scrollPosition);
		$('#closePort').css({marginTop:(scrollPosition + (($(window).height() - swfH) / 2) - 10) + "px",cursor:'pointer'}).animate({marginLeft:(swfW / 2) - 75},2000).click(function() { removePortSwf(); });
		setTimeout(function() { addTextBlock(2,portArray[id - 1][2],scrollPosition,swfW,swfH); },2000);
	}
	
	function removePortSwf() {
		removeTextBlock();
		removeIeShadow();
		$('#closePort').animate({marginLeft:'1500px'},1000);
		if (flashV == 0) {
			$("#portSwf").remove();
		}
		else {
			swfobject.removeSWF("swfPortPlayer");	
		}
		$('#viewerBg').fadeOut(2000);
		setTimeout(removePortSwfElements,2100);
	}
	
	function removePortSwfElements() {
		portFullSizeActive = false;
		resumeSS();
		$('body').css({overflow:'visible'});
		$('#closePort').remove();
		$('#viewer').remove();
		$('#viewerBg').remove();
	}
	
	function addTextBlock(mt,txt,sp,cw,ch) {
		if (!txtActive) {
			if (txt != '') {
				if ((mt == 1) || (mt == 4))  {
					$('#rollOver').after('<span id="descTxt">' + txt + '</span>');
					$('#descTxt').after('<div id="descTxtBg"></div>');
					$('#descTxt').width(cw - 40).css({zIndex:'28',marginTop:((sp + (($(window).height() - ch) / 2)) + (ch - 90)),marginLeft:-((cw / 2) - 20)});
					$('#descTxtBg').width(cw).css({zIndex:'27',marginTop:((sp + (($(window).height() - ch) / 2)) + (ch - 100)),marginLeft:-(cw / 2)});
				}
				else if (mt == 2) {
					$('#closePort').after('<span id="descTxt">' + txt + '</span>');
					$('#descTxt').after('<div id="descTxtBg" class="ds2"></div>');
					$('#descTxt').width(cw - 40).css({zIndex:'28',marginTop:((sp + (($(window).height() - ch) / 2)) + (ch + 30)),marginLeft:-((cw / 2) - 20)});
					$('#descTxtBg').width(cw).css({zIndex:'27',marginTop:((sp + (($(window).height() - (ch - 20)) / 2)) + ch),marginLeft:-(cw / 2)});
					addIeShadow(cw,ch,sp,'Txt');
				}
				else {
				
				}
				
				txtActive = true;
			}		
		}
	}
	
	function removeTextBlock() {
		removeIeShadow('Txt');
		$('#descTxt').remove();
		$('#descTxtBg').remove();
		txtActive = false;
		
	}
	
	
	function addIeShadow(cw,ch,sp,ci) {
		if (browser[0] == 'Explorer') {
			if (ci == 'Txt') {
				$('#viewer').append('<div id="ieShadowTxt" class="ds4"></div>');
				$('#ieShadowTxt').width(cw).height(100).css({marginTop:((sp + (($(window).height() - (ch - 20)) / 2)) + ch),marginLeft:-(cw / 2)});
			}
			else {
				$('#viewer').append('<div id="ieShadow" class="ds4"></div>');
				$('#ieShadow').width(cw).height(ch).css({marginLeft:-(cw / 2),marginTop:(sp + (($(window).height() - ch) / 2))});
				
			}
		}
	}
	
	function removeIeShadow(ci) {
		if (browser[0] == 'Explorer') {
			if (ci == 'Txt') {
				$('#ieShadowTxt').fadeOut(2000).delay(2000).remove();
			}
			else {
				$('#ieShadow').fadeOut(2000).delay(2000).remove();
			}
		}
	}
	
	
	/**** FORM FUNCTIONS ****/
	/****************************************************************************************/
	
	$(function() {
	    $('.error').hide();
	    $('.error2').hide();
	    $(".button").click(function() {
	      // validate and process form here
	
	     $('.error').hide();
	  	 $('.error2').hide();
	  	 
	  	 var name = $("input#name").val();
	  	 if (name == "") {
	       $("label#name_error").show();
	       $("input#name").focus();
	       return false;
	     }
	      
	  	 var email = $("input#email").val();
	  	 var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	  	 if (email == "") {
	       $("label#email_error").show();
	       $("input#email").focus();
	       return false;
	     }
	     else if (reg.test(email) == false) {
	      $("label#email_error2").show();
	      $("input#email").focus();
	      return false;
	     }
	  	  
	  	 var phone = $("input#phone").val();
	  	 if (phone == "") {
	  	 	phone = "null";
	  	 }
	  	  
	  	 var msg = $("textarea#message").val();
	  	 if (msg == "") {
	  	   $("label#message_error").show();
	  	   $("input#message").focus();
	  	   return false;
	  	 }
	      	
		 var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone + '&msg=' + msg;
		 
		 $.ajax({
		   type: "POST",
		   url: "php/scripts.php",
		   data: dataString,
		   success: function() {
		   	 $('#contact_form').fadeOut(1000);
		   	 $('#thankyou').delay(900).fadeIn(1000); 
		   }
		 });
		 return false;
		 
	    });
	  });
	
	
	/**** GENERAL FUNCTIONS ****/
	/****************************************************************************************/
	
	function trace(msg) {
		if(window.console && window.console.firebug){	
			console.log(msg);
		}
	}
	
});


