try {
  document.execCommand("BackgroundImageCache", false, true);
} catch(e) {}

jQuery.easing['BounceEaseOut'] = function(p, t, b, c, d) {
	if ((t/=d) < (1/2.75)) {
		return c*(7.5625*t*t) + b;
	} else if (t < (2/2.75)) {
		return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
	} else if (t < (2.5/2.75)) {
		return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
	} else {
		return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
	}
};

(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)


$(document).ready(function(){

    
	jQuery.ifixpng('/images/pixel.gif');
	jQuery('img, .bgPng, .pngFix').ifixpng();
	
	// Bind login popup handlers
	$("#login-popup-open").live('click',function(){
		$("#login-popup").show(200);		
	});
	

	
	$("#login-popup-close").live('click',function(){
		$("#login-popup").hide(200);
	});
	
	// Bind login popup handlers
	$("#login-pay-popup-open").live('click',function(){
		$("#login-pay-popup").show(200);		
	});
	

	
	$("#login-pay-popup-close").live('click',function(){
		$("#login-pay-popup").hide(200);
	});
	
    // Bind login popup handlers
	$(".email-click").live('click',function(){
		$("#email-popup").show(200);		
	});	
	
	
	$("#email-popup-close").live('click',function(){
		$("#email-popup").hide(200);
	});	
	
    // Bind login popup handlers
	$("#payment-click").live('click',function(){
		$("#payment-popup").show(200);		
	});	
	
	
	$("#payment-popup-close").live('click',function(){
		$("#payment-popup").hide(200);
	});		
	
	// Home - Newsletter signup form, clear input on focus
	$("#home-newsletter-signup input.field").focus(function(){
		if($(this).val() === 'Enter your e-mail address here...') {
			$(this).val('');
		}
	});
	
	$("#home-newsletter-signup input.field").blur(function(){
		if($(this).val() === '') {
			$(this).val('Enter your e-mail address here...');
		}
	});
	
	if (jQuery.browser.msie && (parseInt(jQuery.browser.version) <= 7)) {
		$("#home-services-list li .home-services-list-overlay").css('display','none');
	}
	
	// Home carousel
	$("#home-services-list li").hover(function(){
		// IE 6-7 Version
		if (jQuery.browser.msie && (parseInt(jQuery.browser.version) <= 7)) {
			$("#home-services-list li .home-services-list-overlay").css('display','none');
			$("#home-services-list li h2").css('color','#00AAE5');
			$(".home-services-list-overlay",this).css('display','block').css('opacity','1');
			$("h2",this).css('color','#ffffff');
		// Full version
		} else {
									   
			$("#home-services-list li .home-services-list-overlay").stop().animate({'opacity': '0'},300,function(){
				//$(this).parent().parent().removeClass('active');
				$(this).css('display','none');
			});
			$("#home-services-list li h2").stop().animate({'color': '#00AAE5'},300);
			$("#home-services-list li").stop().animate({'opacity': '0.5'},300,function(){
				//$(this).parent().parent().removeClass('active');
			});
			$(".home-services-list-overlay",this).stop().css('display','block').animate({'opacity': '1'},300,function(){
				//$(this).parent().parent().addClass('active');
			});
			$("a h2",this).stop().animate({'color': '#ffffff'},300);
			$(this).stop().animate({'opacity': '1'},300,function(){
				//$(this).parent().parent().removeClass('active');
			});
			if($(".home-services-list-overlay",this).css('opacity') != 1) {
				$(".home-services-list-arrow",this).stop().animate({'right': '3px'},200,function(){
					$(this).animate({'right': '0px'},200);																	   
				});
			}
		
		}
	},function(){
		if (jQuery.browser.msie && (parseInt(jQuery.browser.version) <= 7)) {
			$("#home-services-list li .home-services-list-overlay").css('display','none');
			$("#home-services-list li h2").css('color','#00AAE5');
		} else {
			$("#home-services-list li .home-services-list-overlay").stop().animate({'opacity': '0'},300,function(){
				//$(this).parent().parent().removeClass('active');
				$(this).css('display','none');
			});
			$("#home-services-list li").stop().animate({'opacity': '1'},300,function(){
				//$(this).parent().parent().removeClass('active');
			});
			$("#home-services-list li h2").stop().animate({'color': '#00AAE5'},300);
		}
	});
	
	
	
	function mycarousel_initCallback(carousel) {
	
		jQuery('#home-services-paging-next').bind('click', function() {
			carousel.next();
			$(this).stop().animate({'right': '-13px'},100,function(){
				$(this).animate({'right': '-9px'},100);	
			});												   
		});
	
		jQuery('#home-services-paging-prev').bind('click', function() {
			carousel.prev();
			$(this).stop().animate({'left': '-13px'},100,function(){
				$(this).animate({'left': '-9px'},100);	
			});	
			return false;
		});
	};

	
	$('#home-services-list').jcarousel({
		easing: 'BounceEaseOut',
		animation: 1000,
		wrap: 'both',
		scroll: 1,
		initCallback: mycarousel_initCallback,
        // This tells jCarousel NOT to autobuild prev/next buttons
        buttonNextHTML: null,
        buttonPrevHTML: null

	});

	$("#home-services-paging-prev").mouseover(function(){
		$(this).stop().animate({'left': '-9px'},100);												   
	}).mouseout(function(){
		$(this).stop().animate({'left': '-5px'},100);	
	});
	
	$("#home-services-paging-next").mouseover(function(){
		$(this).stop().animate({'right': '-9px'},100);												   
	}).mouseout(function(){
		$(this).stop().animate({'right': '-5px'},100);	
	});
	
	$("#column-mid-clients-folders > div h2").toggle(function(){
		$("#column-mid-clients-folders > div").removeClass('active');
		$(this).addClass('active');
		$("ul", "#column-mid-clients-folders").stop().slideUp(500);
		$("ul",$(this).parent()).stop().slideDown(500);
	},function(){
		$("#column-mid-clients-folders > div").removeClass('active');
		$("ul", $(this).parent()).stop().slideUp(500);
	});
	
	if($("#our-people-list").length) {
		jQuery.preLoadImages("/images/people/allen-over.gif", "/images/people/dinu-over.gif", "/images/people/brendan-over.gif");	
	}
	
	// Contact form email field validation
	$("#contact-form").bind('submit',function(){
		var email = $("#contact-email").val();
		var emailPattern = /^((\w+\+*\-*)+\.?)+@((\w+\+*\-*)+\.?)*[\w-]+\.[a-z]{2,6}$/;
		if(email == '') {
			$(".contact-error").css('display','block');
			return false;	
		} else if(!emailPattern.test(email)) {
			$(".contact-error").css('display','block');
			return false;
		}
		
	});										  

});
