port = new Array();
port['#transitions'] = "portNav1";
port['#alcoa'] = "portNav2";
port['#pureair'] = "portNav3";
port['#sigma'] = "portNav4";
port['#zeiss'] = "portNav5";
port['#rec'] = "portNav6";
port['#qp'] = "portNav7";
port['#iii'] = "portNav8";
port['#bonfetti'] = "portNav9";
port['#kayak'] = "portNav10";
port['#dmd'] = "portNav11";
port['#vectren'] = "portNav12";
port['#genoa'] = "portNav13";
port['#pnb'] = "portNav14";
port['#shopnsave'] = "portNav15";
port['#hershey'] = "portNav16";
port['#trilithic'] = "portNav17";
//port['#mhe'] = "portNav18";
port['#plascore'] = "portNav19";
port['#purdue'] = "portNav20";
port['#mindtrust'] = "portNav21";
port['#sweetriot'] = "portNav22";
port['#hoby'] = "portNav23";
port['#woodshield'] = "portNav24";
port['#pearson'] = "portNav25";
port['#jpenney'] = "portNav26";
port['#toiecp'] = "portNav27";
port['#diversityaccords'] = "portNav28";


$(document).ready(function()
{
	
	slide("#navWho", 10, 65, 850, .8);
	slide("#navWhat", 10, 60, 850, .8);
	slide("#navWhy", 10, 103, 850, .8);
	slide("#navWhen", 10, 77, 850, .8);
	slide("#navWhere", 10, 63, 850, .8);

	portfade("#portItem2", "#portNav1");
	portfade("#portItem3", "#portNav2");
	portfade("#portItem4", "#portNav3");
	portfade("#portItem5", "#portNav4");
	portfade("#portItem6", "#portNav5");
	portfade("#portItem7", "#portNav6");
	portfade("#portItem8", "#portNav7");
	portfade("#portItem9", "#portNav8");
	portfade("#portItem10", "#portNav9");
	portfade("#portItem11", "#portNav10");
	portfade("#portItem12", "#portNav11");
	portfade("#portItem13", "#portNav12");
	portfade("#portItem14", "#portNav13");
	portfade("#portItem15", "#portNav14");
	portfade("#portItem16", "#portNav15");
	portfade("#portItem17", "#portNav16");
	portfade("#portItem18", "#portNav17");
	//portfade("#portItem19", "#portNav18");
	portfade("#portItem20", "#portNav19");
	portfade("#portItem21", "#portNav20");
	portfade("#portItem22", "#portNav21");
	portfade("#portItem23", "#portNav22");
	portfade("#portItem24", "#portNav23");
	portfade("#portItem25", "#portNav24");
	portfade("#portItem26", "#portNav25");	
	portfade("#portItem27", "#portNav26");	
	portfade("#portItem28", "#portNav27");	
	portfade("#portItem29", "#portNav28");	

	portfade2("#portItem2", "#portMainNav1", "#portNav1");
	portfade2("#portItem3", "#portMainNav2", "#portNav2");
	portfade2("#portItem4", "#portMainNav3", "#portNav3");
	portfade2("#portItem5", "#portMainNav4", "#portNav4");
	portfade2("#portItem6", "#portMainNav5", "#portNav5");
	portfade2("#portItem7", "#portMainNav6", "#portNav6");
	portfade2("#portItem8", "#portMainNav7", "#portNav7");
	portfade2("#portItem9", "#portMainNav8", "#portNav8");
	portfade2("#portItem10", "#portMainNav9", "#portNav9");
	portfade2("#portItem11", "#portMainNav10", "#portNav10");
	portfade2("#portItem12", "#portMainNav11", "#portNav11");
	portfade2("#portItem13", "#portMainNav12", "#portNav12");
	portfade2("#portItem14", "#portMainNav13", "#portNav13");
	portfade2("#portItem15", "#portMainNav14", "#portNav14");
	portfade2("#portItem16", "#portMainNav15", "#portNav15");
	portfade2("#portItem17", "#portMainNav16", "#portNav16");
	portfade2("#portItem18", "#portMainNav17", "#portNav17");
	//portfade2("#portItem19", "#portMainNav18", "#portNav18");
	portfade2("#portItem20", "#portMainNav19", "#portNav19");
	portfade2("#portItem21", "#portMainNav20", "#portNav20");
	portfade2("#portItem22", "#portMainNav21", "#portNav21");
	portfade2("#portItem23", "#portMainNav22", "#portNav22");
	portfade2("#portItem24", "#portMainNav23", "#portNav23");
	portfade2("#portItem25", "#portMainNav24", "#portNav24");
	portfade2("#portItem26", "#portMainNav25", "#portNav25");
	portfade2("#portItem27", "#portMainNav26", "#portNav26");
	portfade2("#portItem28", "#portMainNav27", "#portNav27");
	portfade2("#portItem29", "#portMainNav28", "#portNav28");


	quickView("#transLink1", "#transPop1", "237", "160");
	quickView("#transLink2", "#transPop2", "190", "119");


	$('#'+this_page+'Arrow img').fadeIn(350);
	$('#'+this_page).css("margin-left","-225px");
	
	port = new Array();
	port['#transitions'] = "portNav1";
	port['#alcoa'] = "portNav2";
	port['#pureair'] = "portNav3";
	port['#sigma'] = "portNav4";
	port['#zeiss'] = "portNav5";
	port['#rec'] = "portNav6";
	port['#qp'] = "portNav7";
	port['#iii'] = "portNav8";
	port['#bonfetti'] = "portNav9";
	port['#kayak'] = "portNav10";
	port['#dmd'] = "portNav11";
	port['#vectren'] = "portNav12";
	port['#genoa'] = "portNav13";
	port['#pnb'] = "portNav14";
	port['#shopnsave'] = "portNav15";
	port['#hershey'] = "portNav16";
	port['#trilithic'] = "portNav17";
	//port['#mhe'] = "portNav18";
	port['#plascore'] = "portNav19";
	port['#purdue'] = "portNav20";
	port['#mindtrust'] = "portNav21";
	port['#sweetriot'] = "portNav22";
	port['#hoby'] = "portNav23";	
	port['#woodshield'] = "portNav24";
	port['#pearson'] = "portNav25";
	port['#jcpenney'] = "portNav26";
	port['#toiecp'] = "portNav27";
	port['#diversityaccords'] = "portNav28";
	
	commonHeight = 550;
	expandedHeight = 620;
	currentFocus = "";
	init();

//	subnav("#navWhoSub", 65);
//	subnav("#navWhatSub", 60);

	introExpand();

	thumbFade();

	showForm();
	
	
	jQuery.validator.addMethod("phoneUS", function(phone_number, element) {
    phone_number = phone_number.replace(/\s+/g, ""); 
	return this.optional(element) || phone_number.length > 9 &&
		phone_number.match(/^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/);
	}, "Please specify a valid phone number");
	
	$("#cfm").validate({
	  rules: {
		field: {
		  required: true,
		  phoneUS: true
		}
	  }
	});

	
});


function slide(navigation_id, pad_out, pad_in, time, multiplier)
{
	//var list_elements = navigation_id;
	//var link_elements = list_elements + " a";
	$(navigation_id+'Sub').fadeOut('fast');

	$(navigation_id+'2').hover(

		function()
		{
			if(navigation_id!='#'+this_page)
			{
				$(navigation_id).stop().animate({ marginLeft: pad_out }, 350);
				$(navigation_id+'Arrow img').fadeIn(350);
				//$(navigation_id+'Arrow img').animate({opacity: 1 }, 'fast');
			}
			$(navigation_id+'Sub').fadeIn(350);
		},
		function()
		{
			if(navigation_id!='#'+this_page)
			{
				$(navigation_id).stop().animate({ marginLeft: pad_in }, 250);
				//$(navigation_id+'Arrow img').animate({opacity: 0 }, 'fast');
				$(navigation_id+'Arrow img').fadeOut('fast');
			}
			$(navigation_id+'Sub').fadeOut('fast');
		});
}

///////////////////////////////////////////////////////////////////////////////

function portfade(port_id, port_nav)
{
	//var list_elements = navigation_id;
	//var link_elements = list_elements + " a";
	$(port_id).fadeOut('fast');
	$(port_nav).click(
		function()
		{
			if(currentFocus!=port_id)
			{
				$(currentFocus).fadeOut('350');
					$(".portItems:visible").fadeOut('350', function () {
					$(".portItems:visible").hide();
					$(".portSelected").removeClass("portSelected");
				$(port_nav).addClass("portSelected");
					$(port_id).fadeIn('350');
					currentFocus = port_id;
					
					if(port_nav=="#portNav10" || port_nav=="#portNav12" || port_nav=="#portNav21" || port_nav=="#portNav22"){
						$("#portHolder").animate({
							height: "700px"}, "fast" );
					}

					else if($("#portHolder").height() > commonHeight){
						$("#portHolder").animate({
							height: commonHeight}, "slow" );
						};
									
					if ($('#subPort').is(":hidden")) {
						$('#subPort').fadeIn('350');
						$(".prev").fadeIn('350');
						$(".next").fadeIn('350');
					};
					
					if ($("#portHolder").height() == "expandedHeight") {
						$("#portHolder").animate({
							height: commonHeight}, "slow" );
					};
					

					
				});
				
			}
		});
}

function portfade2(port_id, port_main_nav, port_nav)
{
	//var list_elements = navigation_id;
	//var link_elements = list_elements + " a";
	$(port_id).fadeOut('fast');

	$(port_main_nav).click(
		function()
		{
			if(currentFocus!=port_id)
			{
				$(currentFocus).fadeOut('350');
					$(".portItems:visible").fadeOut('350', function () {
					$(".portItems:visible").hide();
					$(".portSelected").removeClass("portSelected");
				$(port_nav).addClass("portSelected");
					$(port_id).fadeIn('350');
					$("#subPort").fadeIn('350');
					$(".prev").fadeIn('350');
					$(".next").fadeIn('350');
					currentFocus = port_id;
					
					if(port_nav=="#portNav10" || port_nav=="#portNav12" || port_nav=="#portNav21"){
						$("#portHolder").animate({
							height: "680px"}, "fast" );
					}
					
					else if($("#portHolder").height() > commonHeight){
						$("#portHolder").animate({
							height: commonHeight}, "slow" );
					};
					
					if ($("#portHolder").height() == "expandedHeight") {
						$("#portHolder").animate({
							height: commonHeight}, "slow" );
					}
						
				});
				
			}
		});
}





function quickView(quick_link, quick_pop, q_width, q_height)
{
	$(quick_link).hover(
		function()
		{
			$(quick_pop).stop().animate({
				opacity: 1
			}, 'fast');
			//$(quick_pop).fadeIn(250);
			$(quick_pop).animate({ width: q_width, height: q_height, top: -q_height }, { queue:false, duration:250});
		},
		
		function()
		{
			$(quick_pop).stop().animate({
				opacity: 0
			}, 'fast');
			//$(quick_pop).fadeOut(250);
			$(quick_pop).animate({ width: "0px", height: "0px", top: "0" }, { queue:false, duration:250});
		}
	)
}



function init()
{

	var hash = location.hash;
	$('#'+port[hash]).click();

}


function introExpand()
{
    $("#introPortButton").click(function () {
		if ($("#introExpand").is(":hidden")) {
        $("#introExpand").slideDown("slow");
		$("#portHolder").animate({
			height: "990px"}, "slow" );
		} else {
			$("#introExpand").slideUp("slow");
			$("#portHolder").animate({
			height: 820}, "slow" );
		}

										  
										  
      //$("#introExpand").slideDown("slow");
	  $(".toggleLink").toggle();
    });
}



function thumbFade()
{
	$(".thumbs, #sidebar .galleryThumb a, #portMain .portItemMain, #portMain .portItemMainEndRow, .portItemMainBlank, .portItemMainBlankEndRow").fadeTo("fast", 0.7); // This sets the opacity of the thumbs to fade down to 60% when the page loads
	$(".thumbs, #sidebar .galleryThumb a, #portMain .portItemMain, #portMain .portItemMainEndRow").hover(function(){
	$(this).css({ position:"relative", zIndex:999 });
	$(this).fadeTo("fast", 1.0); // This should set the opacity to 100% on hover
	},function(){
	$(this).fadeTo("fast", 0.7); // This should set the opacity back to 60% on mouseout
	$(this).css({ position:"relative", zIndex:1 });
	});
}


function showForm()
{
	$("#contactExpand").toggle(function(){
		//$("#contactArea").animate({ width: 455 }, { queue:true, duration:"slow"});
		$("#contactArea").animate({ height: 225 }, { duration:"slow"});
	},function(){
		$("#contactArea").animate({ height: 35 }, { queue:true, duration:"slow"});
		//$("#contactArea").animate({ width: 100 }, { duration:"slow"});
	});
}







function sendForm()
{
	if($("#cfm").valid()){
	
		$("#contactForm").fadeOut(250);
		$("#formBusy").fadeIn(250);
		var vals = new Array();
		vals.push($("#firstNameInput").val());
		vals.push($("#lastNameInput").val());
		vals.push($("#companyInput").val());
		vals.push($("#phoneInput").val());
		vals.push($("#phone-extInput").val());
		vals.push($("#emailInput").val());
		$.post("process.php", {first_name:vals[0], last_name:vals[1], company:vals[2], phone:vals[3], ext:vals[4], email:vals[5]},
			   function(data) {
					if(data.success == 0) {
						// success block //	
						$("#formBusy").fadeOut(250);
						$("#success").fadeIn(250);
						var message = "We will be in contact with you shortly "+data.name+"!";
						$("p.formMessage").append(document.createTextNode(message));
						var t=setTimeout("closeForm()",3000);
					} else {
						// failure //
						alert("dongjkl;");
						var message = "Sorry there was an error processing your request";
						$("#cfm").fadeIn(250);
					}
					// fade in box// set message
			}, 'json');
	}
}


function closeForm()
{
	$("#contactExpand").click();
}


