BrowserDetect.init();

if (BrowserDetect.browser == "Chrome") {
	document.write("<link type='text/css' rel='stylesheet' href='css/chrome.css' />");
}
if ((BrowserDetect.browser == "Firefox" && BrowserDetect.version == "2")) {
	document.write("<link type='text/css' rel='stylesheet' href='css/ff2.css' />");
}

$(document).ready(function(){	
	
	$('ul#navigation').superfish();
	$('ul.sub-menu').css('opacity',0.85);
	
	// page url taken from the last '/ '
	var path = location.pathname.substring(location.pathname.lastIndexOf("/") + 1);
		
	if (path == ""){
		$('ul#navigation li a[href$="index.html"]').addClass('active');	
	} else{
		// add active class to any link that matches the path, including sub navigation
		$('ul li a[href$="' + path + '"]').addClass('active');	
	}
	if (path.match("projects")){
		$('ul#navigation li a[href$="projects-rd-e-crete.html"]').addClass('active');	
	}
	
	
	
	// if a dropdown link is the currLink, add active class to parent header
	if ($('ul#navigation li ul li a').hasClass('active')){
		var dropdown = $('ul#navigation li ul li a.active');
		var parent = $(dropdown).parents('li.header').children('a');		
		$(parent).addClass('active');				
	}
	
	
	// apply Cufon after jQuery modification
	Cufon.replace('#navigation > li > a',{hover:true});
	Cufon.replace('#content-right h1');
	
	// slideshow
	if ($('body').hasClass('home')) {
		$('#slideshow ul').cycle({
			speed: 1000,
			timeout: 4000
		});
	}
	
	// projects gallery
	if ($('body').hasClass('projects')) {
		
		$("#gallery-navigation").treeview({
			animated: "normal",
			collapsed: true,
			unique: true,
			persist: "location"	// opens active section by default
		});
		
		$('#gallery').cycle({ 
		    fx:     'fade', 
		    speed:  'normal', 
		    timeout: 0, 
		    next:   '#next', 
		    prev:   '#prev' 
		});
	}
	
	
	// faqs
	// Get height of all answer divs before hide() occurs. Store height in heightArray.
	heightArray = new Array(); 
	$('div.faq-answer').each(function(i){ 
		theHeight = $(this).height(); 
		heightArray[i] = theHeight;
	}); 
	
	$('div.faq-answer').hide();

	$('li.faq-question').click(function() {
		
		// re-apply div height just before animation to fix jumpy animation bug
		$(this).children('div.faq-answer').css({height: heightArray[$("li.faq-question").index(this)]});	
		$(this).children('div.faq-answer').slideToggle('slow');
		return false;
	});
	
	// png fix
	$('body').supersleight();
	
});



