$(document).ready(function() {
	
	//Font resizer
	if ($.cookie('fontSize') != null) {
		var fontSize = $.cookie('fontSize');
		$('html').css('font-size', fontSize);	
		//alert('Font Size:'+fontSize);
		$('html').animate( { fontSize: fontSize }, 1 );
	} 
	
	var originalFontSize = $('html').css('font-size');	
	
	$("#resetFont").click(function(){
		$('html').animate( { fontSize: originalFontSize }, 500 )
		//alert(originalFontSize);
		$.cookie('fontSize', null);
	});
	//Increase Font Size
	$("#increaseFont").click(function(){
		var currentFontSize = $('html').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		var newFontSize = currentFontSizeNum*1.2;
		if (newFontSize < 25) {
			$('html').animate( { fontSize: newFontSize }, 500 )
			$.cookie('fontSize', newFontSize);
		}
		return false;
	});
	//Decrease Font Size
	$("#decreaseFont").click(function(){
		var currentFontSize = $('html').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		var newFontSize = currentFontSizeNum*0.8;
		if (newFontSize > 10) {
			$('html').animate( { fontSize: newFontSize }, 500 )
			$.cookie('fontSize', newFontSize);
		}
		return false;
	}); 

	//Newsletter form
	$("#subForm").validate({
		 rules: { 
	      "cm-name": { 
			  required: true,
			  checkForDefaultVale: true 
	      },
		  "cm-bkrddh-bkrddh": {
			  required: true,
			  email: true
		  }
	    }, 
		messages: { 
 	      "cm-name": "Please enter a your full name",
		  "cm-bkrddh-bkrddh": "Please enter your email address"
 	    },
		submitHandler: function(form) { sumbitForm(form.id); }
	});

	
	//Home slideshow
	$(".slideshowItems").cycle({ fx: 'scrollLeft', timeout: 6000, cleartype: 1, speed: 700, before:  onBefore, after: onAfter });
	function onBefore() { 
		$('.text-holder').animate({ 
			bottom: "-500px"
      	}, 600 );
		
	} 
	function onAfter() { 
		$('.text-holder').animate({ 
			bottom: "33px"
      	}, 600 );		
	} 
	
	//Home page accordion
	$('#sidebar ul.news-list li').eq(1).css('margin-bottom','6px');
	$("#sidebar").tabs("#sidebar ul.news-list", {tabs: 'h2', effect: 'slide', initialIndex: 0});
	
	//Employee Relations accordion
	$("#accordion").tabs("#content .info-list div.tabContent", {tabs: 'h4', effect: 'slide', initialIndex: 0});

	
	($('div.aside ul').length) ? '' : $('.inner #content').css({ 'width':'600px'});
	($('#rightChunks').length) ? '' : $('.inner #content').css({ 'padding-right':'100px'});
	
	
	$('a#print').click(function() {
		window.print();
		return false;						 
	});
	
	$(".scrollable").scrollable({
		circular: false,
		next: '.next',
		prev: '.prev'
	});

	$('.slide').hover(function() {
		$(this).find('span').not('span.active').show();
	}, function() {
		$(this).find('span').not('span.active').hide();
	});
	
	
	if ($('.personInfo').length) {		
		var currentUrl = window.location.href;
		var currentUrlArray = new Array();
		currentUrlArray = currentUrl.split('/');
		var currentParentPage = currentUrlArray[5];
		$('span.'+currentParentPage+'').show().addClass('active');
	}
	
	$('.groupList').each(function() {
		target = $(this).find('a.more3');
		if (!target.length) {
			$(this).find('a.more2').hide();
		}
	});
	
});

$(window).bind("load", function() {	

});

/*------- Validation additonal methods--------------------------------------------------*/
$.validator.addMethod( "checkForDefaultVale", function(value, element) { 
	data = (element.value == "Name") ? false : true; 
	return data;
});

/*------- Newsletter form action --------------------------------------------------------*/
function sumbitForm(formId) {
	data = $('#'+formId).serialize();
	formAction = $('#'+formId).attr("action");
	url = 'assets/snippets/campaignMonitor/proxy.php';
	finalData = data + "&action=" + formAction;
	$.ajax({
		type: "POST",    
		url: url,
		data: finalData,
		success: function(msg){
			$('#newsletterForm').html("<span class='info'>Thank you for subscribing to the Attain Consulting newsletter.<br />You'll receive the first edition by email soon.</span>");
			
			// Fire off Google Analytics fake pageview
			/*
			var pageTracker = _gat._getTracker("UA-7041570-21");
			pageTracker._trackPageview("/newsletter_signup");
			*/

		}
	});
	return false;
}

$.easing.custom = function (x, t, b, c, d) {
	var s = 0.70158; 
	if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
	return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
}
$.easing.bouncy = function (x, t, b, c, d) {
    var s = 1.70158;
    if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
    return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
}
$.tools.tooltip.addEffect("bouncy",
	// opening animation
	function(done) {
		this.getTip().animate({top: '+=15'}, 500, 'bouncy', done).show();
	},
	// closing animation
	function(done) {
		this.getTip().animate({top: '-=15'}, 500, 'bouncy', function()  {
			$(this).hide();
			done.call();
		});
	}
);
function getQueryVariable(variable) {
	var query = window.location.search.substring(1);
	var vars = query.split('&');
	for (var i = 0 ;i < vars.length; i++) {
		var pair = vars[i].split('=');
		if (pair[0] == variable) {
			return pair[1];
		}
	}
}
jQuery.expr[':'].Contains = function(a,i,m){
    return jQuery(a).text().toUpperCase().indexOf(m[3].toUpperCase())>=0;
};
function ucwords(str) {
    // http://kevin.vanzonneveld.net
    return (str + '').replace(/^(.)|\s(.)/g, function ($1) {
        return $1.toUpperCase();
    });
}
 
