$(document).ready(function() {

	/**
	 * Cufon
	 * Example: Cufon.replace('selector', {hover:true, fontFamily:'fontName'});
	 */
	//Cufon.replace('#header > ul > li > a', {hover:true, fontFamily:'eras'});
	Cufon.replace('#content h1, #content h2, #content h3, #content .services h3', {hover:true, fontFamily:'verdana'});
	Cufon.replace('#sidebar h3, #sidebar ul.why li', {hover:true, fontFamily:'verdana'});
	

	/**
	 * Home Services Slider
	 */
	var caseSlider = $('#caseSlider .slider');
	if (caseSlider.length > 0) {
		if($('#caseSlider .slider li').length > 3){
			caseSlider.jCarouselLite({  
				btnNext: '.next',
				btnPrev: '.previous',
				speed:1500,
				visible: 3,
				circular: true,
				auto: 5000
			}).css('width',847);
		} else {
			$('#caseSlider').css('overflow', 'hidden');
			$('#caseSlider').css('width', '847px');
			$('#caseSlider button.previous').css('display', 'none');
			$('#caseSlider button.next').css('display', 'none');
		}
	}
	
	/**
	 * Fancybox
	 */
	$('a.fancybox').fancybox();
	
	
	/**
	 * Header images
	 */
	if($('div.headerimgwrapper')){
		setInterval("headerSlide()", 5000);
	}
	
	
});

function headerSlide() {
	
	var total = $('div.headerimgwrapper li').length;
	if(total > 1){
		var active = $('div.headerimgwrapper li.active');
		var next = active.next().length ? active.next() : $('div.headerimgwrapper li:first');
		
		active.addClass('lastactive');
		
		next.css({opacity: 0.0}).removeClass('inactive').addClass('active').animate({opacity: 1.0}, 1000, function() {
			active.removeClass('active lastactive');
			active.addClass('inactive');
		});
	}
	
}

sfHover = function() {
	var sfEls = $('#header .navigation li');
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

