$(function() {
	$("#image-slider").bxSlider({
		pager: false,
		speed: 600,
		easing: 'easeInOutQuad',
		onBeforeSlide: function(currentSlideNumber, totalSlideQty, currentSlideHtmlObject){
			$('.info', currentSlideHtmlObject).hide();
		},
		onAfterSlide: function(currentSlideNumber, totalSlideQty, currentSlideHtmlObject){
			$('.info', currentSlideHtmlObject).fadeIn(500, 'easeInOutQuad');
		}
	});

	var gridContainer = $('#featured-client-grid');
	$('li:not(.client-info ul li)', gridContainer)
		.css('height', '181px')
		.prepend('<span />');

	$("span", gridContainer).bind({
		mouseenter: function() {
			$(this).parent().find('.client-info').stop(true, true).fadeIn(200);
			$(this).parent().find('.client-info ul', gridContainer).center();
		},
		mouseleave: function() {
			$(this).parent().find('.client-info').stop(true, true).fadeOut(100);
		},
		click: function() {
			if(!$(this).parent().find('a[href^=http]').attr('href'))
	 			 window.location = $(this).parent().find('a').attr('href');
			else
				window.open($(this).parent().find('a').attr('href'));
			return false;
		}
	});

	$("li p a[href^=http]", gridContainer).click(function(e) {
		window.open(this.href);
			return false;
	});

	$("#expand-btn").click(function(e) {
		var btn = $(e.target);
		var featureContainer = $('#featured-column');
		if(featureContainer.css('height') == '789px') {
			$('body').scrollTo(0, 500, 'easeInOutQuad');
			featureContainer
				.stop(true, true)
				.animate({ height: '415px' }, 500, 'easeInOutQuad', function(){
					btn.removeClass('less');
				}
			);
		}
		else {
			var newY = (($('.home-carousel').height() + $('#header').height()) + 50) + 'px';
			$('body').scrollTo(newY, 500, 'easeInOutQuad');
			featureContainer
				.stop(true, true)
				.animate({ height: '789px' }, 500, 'easeInOutQuad', function(){
					btn.addClass('less');
				}
			);
		}
		return false;
	});

});

jQuery.fn.center = function(params) {
	var options = {
		vertical: true,
		horizontal: true
	}
	op = jQuery.extend(options, params);

   return this.each(function(){

		//initializing variables
		var $self = jQuery(this);
		//get the dimensions using dimensions plugin
		var width = $self.width();
		var height = $self.height();
		//get the paddings
		var paddingTop = parseInt($self.css("padding-top"));
		var paddingBottom = parseInt($self.css("padding-bottom"));
		//get the borders
		var borderTop = parseInt($self.css("border-top-width"));
		var borderBottom = parseInt($self.css("border-bottom-width"));
		//get the media of padding and borders
		var mediaBorder = (borderTop+borderBottom)/2;
		var mediaPadding = (paddingTop+paddingBottom)/2;
		//get the type of positioning
		var positionType = $self.parent().css("position");
		// get the half minus of width and height
		var halfWidth = (width/2)*(-1);
		var halfHeight = ((height/2)*(-1))-mediaPadding-mediaBorder;
		// initializing the css properties
		var cssProp = {
			position: 'absolute'
		};

		if(op.vertical) {
			cssProp.height = height;
			cssProp.top = '50%';
			cssProp.marginTop = halfHeight;
		}
		if(op.horizontal) {
			cssProp.width = width;
			cssProp.left = '50%';
			cssProp.marginLeft = halfWidth;
		}
		//check the current position
		if(positionType == 'static') {
			$self.parent().css("position","relative");
		}
		//aplying the css
		$self.css(cssProp);
   });
};
