var timer;
var ready = true;
var reset = false;
var running = true;
var locked = false;
var lockedby;

var currentImage = 0;
var currentImage2 = 0;
var totalImages;
var totalImages2;



function nextImage() {
	
	$("#slideshow a.next").click();
		
	timer = setTimeout("nextImage()", 6000);

}

function nextClient() {

	if($("#clientscoller").find("ul").css("marginTop")=="-30px") {
	
		$("#clientscoller ul li:first").appendTo("#clientscoller ul");
		$("#clientscoller ul li:first").appendTo("#clientscoller ul");
		$("#clientscoller").find("ul").css({marginTop : 0}, "fast");
	}

	$("#clientscoller").find("ul").animate({
		marginTop : -30
	}, 800);
	
	setTimeout("nextClient()", 1400);

}

function nextOfficeImage() {
	totalImages = $("#officeinfo img.office").length-1;
	
	if (currentImage!=totalImages) {
		$("#officeinfo img.office").eq(currentImage+1).fadeIn("slow");
		$("#officeinfo img.office").eq(currentImage).fadeOut("slow");
		currentImage += 1;
	}
	else {
		$("#officeinfo img.office").eq(0).fadeIn("fast");
		$("#officeinfo img.office").eq(totalImages).fadeOut("slow");
		currentImage = 0;
	}
	
	setTimeout("nextOfficeImage()", 4000);
}

function nextOfficeImage2() {
	totalImages2 = $("#officeinfo2 img.office").length-1;
	
	if (currentImage2!=totalImages2) {
		$("#officeinfo2 img.office").eq(currentImage2+1).fadeIn("slow");
		$("#officeinfo2 img.office").eq(currentImage2).fadeOut("slow");
		currentImage2 += 1;
	}
	else {
		$("#officeinfo2 img.office").eq(0).fadeIn("fast");
		$("#officeinfo2 img.office").eq(totalImages2).fadeOut("slow");
		currentImage2 = 0;
	}
	
	setTimeout("nextOfficeImage2()", 4000);
}

$(document).ready(function() {

	/* IE6 fix for dropdowns  */

	if (document.all) {
		 $("#globalnav li").hover(function(){
			$(this).addClass("hover");
		},function(){
			$(this).removeClass("hover");
		});
				
       $("#mainnav li").hover(function(){
			$(this).addClass("hover");
		},function(){
			$(this).removeClass("hover");
		});
		
		$("#pagetools").hover(function(){
			$(this).addClass("hover");
		},function(){
			$(this).removeClass("hover");
		});
		
		$("div.dropdown").hover(function(){
			$(this).addClass("hover");
		},function(){
			$(this).removeClass("hover");
		});
    }
	
	/* Page tools */
	
	$("#email").click(function(){
		pageTracker._trackPageview('/_tools/email');
		location.href='mailto:?SUBJECT=Link to Website of DPR Construction (http://www.dpr.com)&BODY=Below is a link to a page from the DPR Construction web site that contains information I think you%27ll find interesting:%0D%0A%0D%0ATo view the page, visit '+escape(location.href)+'%0D%0A%0D%0A-------------------------------------%0D%0AABOUT DPR CONSTRUCTION -  http://www.dpr.com%0D%0ADPR Construction is a forward-thinking national general contractor and construction manager specializing in technically complex and sustainable projects for the advanced technology, biopharmaceutical, healthcare and corporate office markets. Founded in 1990, DPR has grown to more than $1 billion in annual revenue, making it one of the largest general contractors in the nation and a %22great%22 story of entrepreneurial success. The privately held, employee-owned company has 10 offices across the country and has built projects for such world-class customers as Apple, Bayer, Genentech, HCA, Kaiser Permanente, Oracle, Pixar, Rockwell International, Sun Microsystems and Sutter Health.%0D%0A%0D%0AProjects completed by DPR:  http://www.dpr.com/projects';
		return false;
	});
	$("#bookmark").click(function(){
		pageTracker._trackPageview('/_tools/bookmark');
		var general = "First click OK and then hit CTRL+D to bookmark this page.";
		var opera =" First click OK and then hit CTRL+T to bookmark this page.";
	
		if($.browser.opera)
			alert(opera);
		else
			alert(general);
			
		return false;
	});
	$("#print").click(function(){
		pageTracker._trackPageview('/_tools/print');
		print();
		return false;
	});
	
	/* Prepare external links and video pop ups */
	
	$("a").each(function(i){
		if($(this).attr("rel")=="external")
			$(this).attr("target","_blank");
		else if ($(this).attr("rel")=="video")
			$(this).click(function(){
		
				popup = window.open($(this).attr("href"),'_blank','width=790,height=408,resizable=no,scrollbars=0,menubar=0,toolbar=0,location=0,directories=0,status=0');
				popup.focus();
				
				return false;
			});
	});

	
	/* Scroller */
	
	$('div.scroller').jScrollPane();
	
	/* Highlights */
	
	$("#highlights span.total").html($("#highlights div.content").length);
	
		
	$("#highlights a.next").click(function(){
		
		if ($("#highlights span.current").html() != $("#highlights span.total").html()) {
			$("#highlights div.content").eq($("#highlights span.current").html()).fadeIn("fast");
			$("#highlights div.content").eq($("#highlights span.current").html()-1).fadeOut("fast");
			$("#highlights span.current").html(parseInt($("#highlights span.current").html())+1);
		}
		else {
			$("#highlights span.current").html("1");
			$("#highlights div.content").eq(0).fadeIn("fast");
			$("#highlights div.content").eq($("#highlights div.content").length-1).fadeOut("fast");
		}
		
		return false;
	});
	
	$("#highlights a.previous").click(function(){
		
		if ($("#highlights span.current").html() != "1") {
			$("#highlights div.content").eq($("#highlights span.current").html()-2).fadeIn("fast");
			$("#highlights div.content").eq($("#highlights span.current").html()-1).fadeOut("fast");
			$("#highlights span.current").html(parseInt($("#highlights span.current").html())-1);
		}
		else {
			$("#highlights span.current").html($("#highlights div.content").length);
			$("#highlights div.content").eq($("#highlights div.content").length-1).fadeIn("fast");
			$("#highlights div.content").eq(0).fadeOut("fast");
		}
		
		return false;
	});
	
	/* Featured Projects */
	
	$("#featuredproj span.total").html($("#featuredproj div.content").length);
	
	$("#featuredproj div.content").hide();
	
	$("#featuredproj div.content").eq(0).show();
		
	$("#featuredproj a.next").click(function(){
		
		if ($("#featuredproj span.current").html() != $("#featuredproj span.total").html()) {
			$("#featuredproj div.content").eq($("#featuredproj span.current").html()).fadeIn("fast");
			$("#featuredproj div.content").eq($("#featuredproj span.current").html()-1).fadeOut("fast");
			$("#featuredproj span.current").html(parseInt($("#featuredproj span.current").html())+1);
		}
		else {
			$("#featuredproj span.current").html("1");
			$("#featuredproj div.content").eq(0).fadeIn("fast");
			$("#featuredproj div.content").eq($("#featuredproj div.content").length-1).fadeOut("fast");
		}
		
		return false;
	});
	
	$("#featuredproj a.previous").click(function(){
		
		if ($("#featuredproj span.current").html() != "1") {
			$("#featuredproj div.content").eq($("#featuredproj span.current").html()-2).fadeIn("fast");
			$("#featuredproj div.content").eq($("#featuredproj span.current").html()-1).fadeOut("fast");
			$("#featuredproj span.current").html(parseInt($("#featuredproj span.current").html())-1);
		}
		else {
			$("#featuredproj span.current").html($("#featuredproj div.content").length);
			$("#featuredproj div.content").eq($("#featuredproj div.content").length-1).fadeIn("fast");
			$("#featuredproj div.content").eq(0).fadeOut("fast");
		}
		
		return false;
	});

	
	/* Contextual dropdowns  */


	$("#contextual ul").addClass("invis");
	
	$("#contextual h4.expand").toggle(function(){
		$(this).addClass("selected");
		$(this).parent().find("ul").slideDown("fast");
	},function(){
		$(this).removeClass("selected");
		$(this).parent().find("ul").slideUp("fast");
	});
	
	$("#contextual h4.show").click();
	

	/* Linkareas  */
	
	$(".linkarea").addClass("active");
	

	
	$(".linkarea").hover(function(){
		$(this).css({ cursor: 'pointer' });
	},function(){
	});
	
	$("dl.linkarea").hover(function(){
		$(this).css({ border: '1px solid #aaa' });
	},function(){
		$(this).css({ border: '1px solid #fff' });
	});

	$("dl.advancedtech .linkarea").hover(function(){
		$(this).css({ border: '0' });
		$(this).css({ backgroundColor: '#e1e3e6' });
	},function(){
		$(this).css({ border: '0' });
		$(this).css({ backgroundColor: '#edeff1' });
	});
	
	$("dl.advancedtech .linkarea").hover(function(){
		$(this).css({ border: '0' });
		$(this).css({ backgroundColor: '#e1e3e6' });
	},function(){
		$(this).css({ border: '0' });
		$(this).css({ backgroundColor: '#edeff1' });
	});
	
	$("div.projectlisting.linkarea").hover(function(){
		$(this).css({ backgroundColor: '#e1e3e6' });
	},function(){
		$(this).css({ backgroundColor: '#edeff1' });
	});
	
	$("p.linkarea").hover(function(){
		$(this).css({ backgroundColor: '#e1e3e6' });
	},function(){
		$(this).css({ backgroundColor: '#edeff1' });
	});
	
	$(".linkarea a").click(function(){

		if ($(this).attr("rel")=="external") {
			var newWindow = window.open($(this).attr("href"), '_blank');
			newWindow.focus();
				
			return false;
		}
		else if ($(this).attr("rel")=="video") {
			return false;
		}
	});	

	$(".linkarea").click(function(){		
		if ($(this).find("a").attr("rel")=="external" || $(this).find("a").attr("rel")=="video") {
			$(this).find("a").eq(0).trigger("click");
		}
		else 
			document.location = $(this).find("a").eq(0).attr("href");

	});
	

	
	
		/* Contact Us map  */
	
		$("#buildingmap").addClass("active");
		
		if($.browser.msie) { 
			$("#buildingmap div.popup").hover(function(){
				$(this).find("div").show();
			},function(){
				$(this).find("div").hide();
			});
		}
		else {
			$("#buildingmap div.popup").hover(function(){
				$(this).find("div").fadeIn("fast");
			},function(){
				$(this).find("div").fadeOut("fast");
			});
		}
		
		/* Management Team  */

		
		$("dl.mteam dd a").click(function(){

			
			//	$(this).css({ zIndex: 200 });
				
				$($(this).attr("href")).css({ display: 'none' });
				$($(this).attr("href")).css({ visibility: 'visible' });
				
				if($.browser.msie)
					$($(this).attr("href")).show();
				else
					$($(this).attr("href")).fadeIn("fast");
					
			return false;
		});
		
		
		$("dl.mteam p.close a").click(function() {
			$(this).parent().parent().hide();
		});
		
		
		/* Office Google Maps */
		
		$("#mapthumb a").click(function(){
			if($.browser.msie)
				$("#mappopup").show();
			else
				$("#mappopup").fadeIn("fast");
				
			load();
			return false;
		});
		
		$("#mapthumb2 a").click(function(){
			if($.browser.msie)
				$("#mappopup2").show();
			else
				$("#mappopup2").fadeIn("fast");
				
			load2();
			return false;
		});
		
		$("#mappopup p.close").click(function() {
			$("#mappopup").hide();		

			GUnload();
		});
		
		$("#mappopup2 p.close").click(function() {
			$("#mappopup2").hide();		

			GUnload();
		});
		
		
		/* Office slideshow */
	
		setTimeout("nextOfficeImage()", 4000);
		setTimeout("nextOfficeImage2()", 4000);
		
		/* Slideshow  */
	
		$("#slideshow").find("ul").width($("#slideshow").find("li").length*162);
		
		$("#slideshow li.linkarea").hover(function(){
			$(this).css({ border: '1px solid #aaa' });
		},function(){
			$(this).css({ border: '1px solid #fff' });
		});
		
		setTimeout("nextImage()", 6000);
		
		$("#slideshow a.next").click(function(){
			if($("#slideshow ul").css("marginLeft") != "0px") {
				$("#slideshow ul").css({ marginLeft: 0 });
				$("#slideshow ul li:first").appendTo("#slideshow ul");
			}
		
			$("#slideshow").find("ul").animate({
			 marginLeft : -161
			}, "fast");
			return false;
		});
		
		$("#slideshow a.prev").click(function(){
			if($("#slideshow ul").css("marginLeft") == "0px") {
				$("#slideshow ul").css({ marginLeft: -161 });
				$("#slideshow ul li:last").prependTo("#slideshow ul");
			}
			$("#slideshow").find("ul").animate({
			 marginLeft : 0
			}, "fast");
			return false;
		});
		
		$("#slideshow a.pause").click(function() {
			if (running) {
				running = false;
				clearTimeout(timer);
				$(this).addClass("stopped");
			}
			else {
				running = true;
				$(this).removeClass("stopped");
				nextImage();
			}
			return false;
		});

		
		/* Projects module  */
	
		$("div.imgcontainer img.thumb").fadeTo("fast", 0.25);
		
		$("#featuredprojects ul a").hover(function(){
			if (ready && !locked) {
				$("div."+$(this).attr("class")+" img.thumb").fadeTo(200, 1.0);
			}
		},function(){
			if (!locked)
				$("div.imgcontainer img.thumb").fadeTo(100, 0.25);
		});
		
		$("#featuredprojects ul a").click(function(){
			if (ready) {
				if (locked) {
					$("div.imgcontainer img.thumb").fadeTo("fast", 0.25);
					
					$("#featuredprojects ul li").removeClass("selected");
					
					
					if ($(this).attr("class") == lockedby) {
						locked = false;
					}
					else {
						$("div."+$(this).attr("class")+" img.thumb").fadeTo("fast", 1.0);
						lockedby = $(this).attr("class");
						$(this).parent().addClass("selected");
					}
				}
				else {
					locked = true;
					lockedby = $(this).attr("class");
					
					$(this).parent().addClass("selected");
				}
			}
		});
	
		
		$("div.project").hover(function(){
			if (ready) {
				if (!locked)
					$(this).find("img.thumb").fadeTo("fast", 1.0);
					
					$(this).find("p.tooltip").show();
				$(this).css({ zIndex: 2 });
			}
		},function(){
			if (ready) {
				if (!locked)
					$(this).find("img.thumb").fadeTo("fast", 0.25);
					

				$(this).find("p.tooltip").hide();
				
				$(this).css({ zIndex: 1 });
			}
		});
		
		$("div.project").click(function() {
			if (ready) {
				ready = false;
				
				$(this).find("p.tooltip").hide();
				
				$("div.project").css({ position: 'static' });
				
				if($.browser.msie)
					$(this).find("div.popup").show();
				else
					$(this).find("div.popup").fadeIn("fast");
			}
			
			if (reset) {
				ready = true;
				reset = false;
			}
			
		});
		
		
		$("div.imgcontainer p.close").click(function() {
			$(this).parent().parent().hide();
			$("div.project").css({ position: 'relative' });
			reset = true;
		});
		
		
	/* Projecs Overview */
	
	$("#projectinfo span.total").html($("#projectinfo img.project").length);
	
	$("#projectinfo p.controls").fadeIn("fast");
	
	$("#projectinfo img.project").hide();
	
	$("#projectinfo img.project").eq(0).show();
		
	$("#projectinfo a.next").click(function(){
		
		if ($("#projectinfo span.current").html() != $("#projectinfo span.total").html()) {
			$("#projectinfo img.project").eq($("#projectinfo span.current").html()).fadeIn("fast");
			$("#projectinfo img.project").eq($("#projectinfo span.current").html()-1).fadeOut("fast");
			$("#projectinfo span.current").html(parseInt($("#projectinfo span.current").html())+1);
		}
		else {
			$("#projectinfo span.current").html("1");
			$("#projectinfo img.project").eq(0).fadeIn("fast");
			$("#projectinfo img.project").eq($("#projectinfo img.project").length-1).fadeOut("fast");
		}
		
		return false;
	});
	
	$("#projectinfo a.previous").click(function(){
		
		if ($("#projectinfo span.current").html() != "1") {
			$("#projectinfo img.project").eq($("#projectinfo span.current").html()-2).fadeIn("fast");
			$("#projectinfo img.project").eq($("#projectinfo span.current").html()-1).fadeOut("fast");
			$("#projectinfo span.current").html(parseInt($("#projectinfo span.current").html())-1);
		}
		else {
			$("#projectinfo span.current").html($("#projectinfo img.project").length);
			$("#projectinfo img.project").eq($("#projectinfo img.project").length-1).fadeIn("fast");
			$("#projectinfo img.project").eq(0).fadeOut("fast");
		}
		
		return false;
	});
	
	
	/* Careers Client Scroller */
	
	setTimeout("nextClient()", 1400);
	


	
});