jQuery(function( $ ){
	/**
	 * Most jQuery.localScroll's settings, actually belong to jQuery.ScrollTo, check it's demo for an example of each option.
	 * @see http://flesler.demos.com/jquery/scrollTo/
	 * You can use EVERY single setting of jQuery.ScrollTo, in the settings hash you send to jQuery.LocalScroll.
	 */


	$.localScroll.defaults.axis = 'xy';

	// Scroll initially if there's a hash (#something) in the url
	$.localScroll.hash({
		target: '#maincontent', // Could be a selector or a jQuery object too.
		queue:true,
		duration:1000
	});

	/**
	 * NOTE: I use $.localScroll instead of $('#navigation').localScroll() so I
	 * also affect the >> and << links. I want every link in the page to scroll.
	 */
	$.localScroll({
		target: '#maincontent', // could be a selector or a jQuery object too.
		queue:true,
		duration:1000,
		hash: true,
      		onBefore:function( e, anchor, $target ){
			// The 'this' is the settings object, can be modified
		},
		onAfter:function( anchor, settings ){
			// The 'this' contains the scrolled element (#content)
		}
	});
});

// Center Vertically and Horizontally via JS //
(function ($) {
$.fn.vAlign = function() {
	return this.each(function(i){
	var h = $(this).height();
	var oh = $(this).outerHeight();
	var mt = (h + (oh - h)) / 2;
	//$(this).css("margin-top", "-" + mt + "px");
	//$(this).css("top", "50%");
	//$(this).css("position", "absolute");
	});
};
})(jQuery);

(function ($) {
$.fn.hAlign = function() {
	return this.each(function(i){
	var w = $(this).width();
	var ow = $(this).outerWidth();
	var ml = (w + (ow - w)) / 2;
	$(this).css("margin-left", "-" + ml + "px");
	$(this).css("left", "50%");
	$(this).css("position", "absolute");
	});
};
})(jQuery);

$(document).ready(function() {
$("#container").vAlign();
	$("#container").hAlign();


});

$(document).ready(function(){
	$(".btn-slide-web").click(function(){
		$("#contact").hide()
		//if($("#container").height() == 1200){
		//$("#container").height(633)
		//}
		//else {
		//$("#container").height(1200)
		//}
		$("#webanalysis").slideToggle("slow");
		return false;
	});
});

$(document).ready(function(){
	$(".btn-slide-contact").click(function(){
		$("#webanalysis").hide()
		//if($("#container").height() == 1200){
		//$("#container").height(633)
		//}
		//else {
		//$("#container").height(1200)
		//}
		$("#contact").slideToggle("slow");
		return false;
	});


});

/* Web Analysis Form */
$(document).ready(function() {
	// prepare Options Object
	var options = {
	url: '/webform/xhr',
	dataType:  'json',
	success:   processJsonWeb,
	beforeSubmit: beforeFormWeb
	};
    $('#web_form').ajaxForm(options);
});

function beforeFormWeb() {
	$('#bt').attr("disabled","disabled");
	$('.error').removeClass();
	$('#wemsg').fadeOut('slow');
	return true;
}

function processJsonWeb(data) {

	if (data) {
		e_msg = "Your submission has been received, thank you.";

		if (eval(data.bad)) {
			e_msg = "Your submission contains missing or invalid data. Please check the highlighted fields.";
			errors = eval(data.errs);
			$.each(errors,function(fieldname,errmsg)
			{
				id = "#id_" + fieldname;
				$(id).addClass("error")
				});
			$('#bt').attr("disabled","");
		}
		$('#wemsg').text( e_msg ).fadeIn("fast");
	} else {
		$('#wemsg').text("Ajax error : no data received. ").fadeIn("slow");
	}
}

/* Content Form */
$(document).ready(function() {
	// prepare Options Object
	var options = {
	url: '/contactform/xhr',
	dataType:  'json',
	success:   processJson,
	beforeSubmit: beforeForm
	};
    $('#contact_form').ajaxForm(options);
});

function beforeForm() {
	$('#bt_contact').attr("disabled","disabled");
	$('.error').removeClass();
	$('#cemsg').fadeOut('slow');
	return true;
}

function processJson(data) {

	if (data) {
		ce_msg = "Your submission has been received, thank you.";

		if (eval(data.bad)) {
			ce_msg = "Your submission contains missing or invalid data. Please check the highlighted fields.";
			errors = eval(data.errs);
			$.each(errors,function(fieldname,errmsg)
			{
				id = "#id_" + fieldname;
				$(id).addClass("error")
				});
			$('#bt_contact').attr("disabled","");
		}
		$('#cemsg').text( ce_msg ).fadeIn("slow");
	} else {
		$('#cemsg').text("Ajax error : no data received. ").fadeIn("slow");
	}
}

$(document).ready(function(){
$('.clients').columnize({
        width : 860,
		buildOnce : true,
		overflow : {
            id : ".thin",
            doneFunc : function(){
                $('.thin').columnize({ width:172 });
            }
		}
})
});
