// JavaScript Document

function pageLoad() {

$(".background_photos").cdzPreloadImages(
	function(total){//starting load
		$(".bg_photo").hide();
		$(".bottom_menu").hide();
	}, function(loaded, total){//in progress
		var pctLoaded = (loaded/total)*100;
		$("#progressbar").progressbar({
			value: pctLoaded
		});
		//alert("Preload Progress : " + loaded + " / " + total)
	}, function(){//completed load
		
		var timages = ['home1.jpg','home2.jpg','home3.jpg'];
		$('<img src="/Portals/0/Skins/infraplan/images/bg_images_trans/' + timages[Math.floor(Math.random() * timages.length)] + '">').appendTo('#img2');
		$("#home .background_photos #img2").fadeIn();
		$(".bottom_menu").fadeIn();
		$("#progressbar").fadeOut();
		
		// make trans section active once loaded
		$(".bottom_link_overview .trans").animate({ height: "363px"},500,function(){
		$(".case_study_bg").animate({ height: "40px"},500,
			function(){
				$(".case_study .trans").animate({ height: "60px"},{queue:false},500);
				});
			})
		$("#home span.trans").animate({ height: "75px"},{queue:false},200);
		$("#home .bottom_links .trans_active").height(75);
	}
	
);

	
};


$(document).ready(function(){	
	

	var hurbanimages = ['home1.jpg', 'home2.jpg', 'home3.jpg', 'home4.jpg'];
	var htransimages = ['home1.jpg','home2.jpg','home3.jpg'];
	var henviroimages = ['home1.jpg','home2.jpg','home3.jpg','home4.jpg'];
	var htrafficimages = ['home1.jpg','home2.jpg','home3.jpg','home4.jpg'];
	
	
	$(".open_body").hide();
	
	$(".open_heading").click(function(){
		$(this).next(".open_body").slideToggle(500);
		$(this).toggleClass("active");
	});
		
	$(".top_menu #HouseMenuNavCurrentLink").parent("li").parent("ul").parent("li").parent("ul").siblings("a").addClass("active");
	
	$(".open_heading").hover(function(){
		$(this).addClass("hover");
	},function(){
		$(this).removeClass("hover");
	});
	
	$(".services li").children("a").parent("li").addClass("pdf");
							   
	$(".search #dnn_dnnSearch_txtSearch").attr({ value: 'Site search...' }).focus(function(){
		if($(this).val()=="Site search..."){
		   $(this).val("");
		}
	}).blur(function(){
		if($(this).val()==""){
		   $(this).val("Site search...");
		}
	});		   
					   
	$("#inside .col2").children("ul").children("li").children("a").removeAttr("href");
	
	$(".col2 ul > li a").click(function(){
		$(this).siblings("ul").slideToggle();
	});
	
	$(".col2").children("ul").children("li").children("ul").children("#HouseMenuNavCurrentItem").parent("ul").show();
	
	var col2h = $(".content").height();
	$(".col2").css({"min-height":col2h}); 

						   
	$(".bottom_link_overview .popup").height(0);
	
	$(".case_study .study").height(0);
	
	$(".case_study_bg").height(0);

	$(".bottom_links a.urban").hover(function(){
		$(this).siblings("span.urban").animate({ height: "75px"},{queue:false},200);
	},function(){
		$(this).siblings("span.urban").animate({ height: "5px"},{queue:false},200);
	}); 
	
	$(".bottom_links a.urban").click(function(){
		if ( $(".bottom_link_overview .urban").height() > 362 ){			
			$(".bottom_link_overview .urban").animate({ height: "0px"},500,function(){
				$(".case_study_bg").animate({ height: "0px"},500);
			}).siblings(".popup").animate({ height: "0px"},{duration:500});			
			$(".bottom_links .active").animate({ height: "0px"},{queue:false},200);
			$(".case_study .urban").animate({ height: "0px"},{queue:false},500);
			$("#img0").fadeIn(1000).siblings(".bg_photo").fadeOut(1000);
		}else{
			$(".bottom_links .urban_active").height(75).siblings("span.active").animate({ height: "0px"},{queue:false},200);
			$(".case_study .urban").siblings(".study").animate({ height: "0px"},{queue:false},500); //close other studies
			
			$('<img src="/Portals/0/Skins/infraplan/images/bg_images_urban/' + hurbanimages[Math.floor(Math.random() * hurbanimages.length)] + '">').appendTo('#img1');
			$("#img1").fadeIn(1000).siblings(".bg_photo").fadeOut(1000);
			if ($(".case_study_bg").height() > 39){//already open
				$(".bottom_link_overview .urban").animate({ height: "363px"},500,function(){
					$(".case_study .urban").animate({ height: "60px"},{queue:false},500);
				}).siblings(".popup").animate({ height: "0px"},{duration:500});
				
			}else{//open for first time
				$(".bottom_link_overview .urban").animate({ height: "363px"},500,function(){
					$(".case_study_bg").animate({ height: "40px"},500,function(){
						$(".case_study .urban").animate({ height: "60px"},{queue:false},500);
					});
				}).siblings(".popup").animate({ height: "0px"},{duration:500});	
			};
		}
	});
	
	
	
	$(".bottom_links a.trans").hover(function(){
		$(this).siblings("span.trans").animate({ height: "75px"},{queue:false},200);
	},function(){
		$(this).siblings("span.trans").animate({ height: "5px"},{queue:false},200);
	}); 
	
	$(".bottom_links a.trans").click(function(){
		if ( $(".bottom_link_overview .trans").height() > 362 ){			
			$(".bottom_link_overview .trans").animate({ height: "0px"},500,function(){
				$(".case_study_bg").animate({ height: "0px"},500);
			}).siblings(".popup").animate({ height: "0px"},{duration:500});			
			$(".bottom_links .active").animate({ height: "0px"},{queue:false},200);
			$(".case_study .trans").animate({ height: "0px"},{queue:false},500);
			$("#img0").fadeIn(1000).siblings(".bg_photo").fadeOut(1000);
		}else{
			$(".bottom_links .trans_active").height(75).siblings("span.active").animate({ height: "0px"},{queue:false},200);
			$(".case_study .trans").siblings(".study").animate({ height: "0px"},{queue:false},500); //close other studies
			
			$('<img src="/Portals/0/Skins/infraplan/images/bg_images_trans/' + htransimages[Math.floor(Math.random() * htransimages.length)] + '">').appendTo('#img2');
			$("#img2").fadeIn(1000).siblings(".bg_photo").fadeOut(1000);
			if ($(".case_study_bg").height() > 39){//already open
				$(".bottom_link_overview .trans").animate({ height: "363px"},500,function(){
					$(".case_study .trans").animate({ height: "60px"},{queue:false},500);
				}).siblings(".popup").animate({ height: "0px"},{duration:500});
				
			}else{//open for first time
				$(".bottom_link_overview .trans").animate({ height: "363px"},500,function(){
					$(".case_study_bg").animate({ height: "40px"},500,function(){
						$(".case_study .trans").animate({ height: "60px"},{queue:false},500);
					});
				}).siblings(".popup").animate({ height: "0px"},{duration:500});	
			};
		}
	});
	
	
	$(".bottom_links a.enviro").hover(function(){
		$(this).siblings("span.enviro").animate({ height: "75px"},{queue:false},200);
	},function(){
		$(this).siblings("span.enviro").animate({ height: "5px"},{queue:false},200);
	}); 
	
	$(".bottom_links a.enviro").click(function(){
		if ( $(".bottom_link_overview .enviro").height() > 362 ){			
			$(".bottom_link_overview .enviro").animate({ height: "0px"},500,function(){
				$(".case_study_bg").animate({ height: "0px"},500);
			}).siblings(".popup").animate({ height: "0px"},{duration:500});			
			$(".bottom_links .active").animate({ height: "0px"},{queue:false},200);
			$(".case_study .enviro").animate({ height: "0px"},{queue:false},500);
			$("#img0").fadeIn(1000).siblings(".bg_photo").fadeOut(1000);
		}else{
			$(".bottom_links .enviro_active").height(75).siblings("span.active").animate({ height: "0px"},{queue:false},200);
			$(".case_study .enviro").siblings(".study").animate({ height: "0px"},{queue:false},500); //close other studies
			
			$('<img src="/Portals/0/Skins/infraplan/images/bg_images_enviro/' + henviroimages[Math.floor(Math.random() * henviroimages.length)] + '">').appendTo('#img3');
			$("#img3").fadeIn(1000).siblings(".bg_photo").fadeOut(1000);
			if ($(".case_study_bg").height() > 39){//already open
				$(".bottom_link_overview .enviro").animate({ height: "363px"},500,function(){
					$(".case_study .enviro").animate({ height: "60px"},{queue:false},500);
				}).siblings(".popup").animate({ height: "0px"},{duration:500});
				
			}else{//open for first time
				$(".bottom_link_overview .enviro").animate({ height: "363px"},500,function(){
					$(".case_study_bg").animate({ height: "40px"},500,function(){
						$(".case_study .enviro").animate({ height: "60px"},{queue:false},500);
					});
				}).siblings(".popup").animate({ height: "0px"},{duration:500});	
			};
		}
	});
	
	
	
	$(".bottom_links a.traffic").hover(function(){
		$(this).siblings("span.traffic").animate({ height: "75px"},{queue:false},200);
	},function(){
		$(this).siblings("span.traffic").animate({ height: "5px"},{queue:false},200);
	}); 
	
	$(".bottom_links a.traffic").click(function(){
		if ( $(".bottom_link_overview .traffic").height() > 362 ){			
			$(".bottom_link_overview .traffic").animate({ height: "0px"},500,function(){
				$(".case_study_bg").animate({ height: "0px"},500);
			}).siblings(".popup").animate({ height: "0px"},{duration:500});			
			$(".bottom_links .active").animate({ height: "0px"},{queue:false},200);
			$(".case_study .traffic").animate({ height: "0px"},{queue:false},500);
			$("#img0").fadeIn(1000).siblings(".bg_photo").fadeOut(1000);
		}else{
			$(".bottom_links .traffic_active").height(75).siblings("span.active").animate({ height: "0px"},{queue:false},200);
			$(".case_study .traffic").siblings(".study").animate({ height: "0px"},{queue:false},500); //close other studies
			
			$('<img src="/Portals/0/Skins/infraplan/images/bg_images_traffic/' + htrafficimages[Math.floor(Math.random() * htrafficimages.length)] + '">').appendTo('#img4');
			$("#img4").fadeIn(1000).siblings(".bg_photo").fadeOut(1000);
			if ($(".case_study_bg").height() > 39){//already open
				$(".bottom_link_overview .traffic").animate({ height: "363px"},500,function(){
					$(".case_study .traffic").animate({ height: "60px"},{queue:false},500);
				}).siblings(".popup").animate({ height: "0px"},{duration:500});
				
			}else{//open for first time
				$(".bottom_link_overview .traffic").animate({ height: "363px"},500,function(){
					$(".case_study_bg").animate({ height: "40px"},500,function(){
						$(".case_study .traffic").animate({ height: "60px"},{queue:false},500);
					});
				}).siblings(".popup").animate({ height: "0px"},{duration:500});	
			};
		}
	});
	
	
	
	
	
	
	$(".top_menu ul#HouseMenuNav > li").children("ul").hide();
	
	$(".top_menu ul#HouseMenuNav > li").hover(function(){
		$(this).children("ul").show();
	},function(){
		$(this).children("ul").hide();
	}); 
	

	$(".case_study .urban").children(".case_study_links").children("ul").children("li:first").addClass("active");
	$(".case_study .trans").children(".case_study_links").children("ul").children("li:first").addClass("active");
	$(".case_study .enviro").children(".case_study_links").children("ul").children("li:first").addClass("active");
	$(".case_study .traffic").children(".case_study_links").children("ul").children("li:first").addClass("active");
	
	var playSlideshow =  setInterval( "slideSwitch()", 5000 );
		
	$(".urban .case_study_links ul").hover(function() {
		clearInterval(playSlideshow);
	},
	function() {
		playSlideshow =  setInterval( "slideSwitch()", 5000 );
	});
	
	
	
	
	var playSlideshow2 =  setInterval( "slideSwitch2()", 5000 );
		
	$(".trans .case_study_links ul").hover(function() {
		clearInterval(playSlideshow2);
	},
	function() {
		playSlideshow2 =  setInterval( "slideSwitch2()", 5000 );
	});
	
	
	
	
	
	var playSlideshow3 =  setInterval( "slideSwitch3()", 5000 );
		
	$(".enviro .case_study_links ul").hover(function() {
		clearInterval(playSlideshow3);
	},
	function() {
		playSlideshow3 =  setInterval( "slideSwitch3()", 5000 );
	});
	
	
	
	
	
	var playSlideshow4 =  setInterval( "slideSwitch4()", 5000 );
		
	$(".traffic .case_study_links ul").hover(function() {
		clearInterval(playSlideshow4);
	},
	function() {
		playSlideshow4 =  setInterval( "slideSwitch4()", 5000 );
	});

	
});


function slideSwitch() {
    var $active = $('.urban .case_study_links ul li.active');

    if ( $active.length == 0 ) $active = $('.urban .case_study_links ul li:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('.urban .case_study_links ul li:first');

    $active.addClass('last-active').animate({top: -49}, 1000);

    $next.css({top: 49})
        .addClass('active')
        .animate({top: 9}, 1000, function() {
            $active.css({top: 49}).removeClass('active last-active');
        });
}

function slideSwitch2() {
    var $active = $('.trans .case_study_links ul li.active');

    if ( $active.length == 0 ) $active = $('.trans .case_study_links ul li:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('.trans .case_study_links ul li:first');

    $active.addClass('last-active').animate({top: -49}, 1000);

    $next.css({top: 49})
        .addClass('active')
        .animate({top: 9}, 1000, function() {
            $active.css({top: 49}).removeClass('active last-active');
        });
}



function slideSwitch3() {
    var $active = $('.enviro .case_study_links ul li.active');

    if ( $active.length == 0 ) $active = $('.enviro .case_study_links ul li:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('.enviro .case_study_links ul li:first');

    $active.addClass('last-active').animate({top: -49}, 1000);

    $next.css({top: 49})
        .addClass('active')
        .animate({top: 9}, 1000, function() {
            $active.css({top: 49}).removeClass('active last-active');
        });
}



function slideSwitch4() {
    var $active = $('.traffic .case_study_links ul li.active');

    if ( $active.length == 0 ) $active = $('.traffic .case_study_links ul li:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('.traffic .case_study_links ul li:first');

    $active.addClass('last-active').animate({top: -49}, 1000);

    $next.css({top: 49})
        .addClass('active')
        .animate({top: 9}, 1000, function() {
            $active.css({top: 49}).removeClass('active last-active');
        });
}




