$(document).ready(function () {

	//placeholder
	if (!Modernizr.input.placeholder) {
		$('input[placeholder]').each(function (e, index) {
			var el = $(this);
			el.val(el.attr('placeholder'));

			el.bind('click', function () {
				el.val('').unbind('click');
			});
		});

	}

	//validation
	$('form').validate();

	//form
	$('#sidebar .form:not(.contact)').hide();

	$('button#btn_requestQuote').bind('click', function (event) {
		$('.form').fadeIn('slow');
		$(this).unbind('click');
		event.preventDefault();
	});

	$('.faq dl dd, .expanded-content').each(function (e, index) {
		var h = $(this).height();
		$(this).css('height', h);
	}).hide();

	$('.faq dl dt').bind('click', function (event) {
		var a = $(this).find('a');
		var v = a.html();

		if (v == 'Answer') { a.html('Close'); }
		else { a.html('Answer'); }

		a.toggleClass('close');

		$(this).next().slideToggle('slow');
	});

	$('.more').bind('click', function (event) {
		var a = $(this);
		var v = a.html();

		if (v == 'Read more') { a.html('Close'); }
		else { a.html('Read more'); }

		a.toggleClass('close');

		a.next().slideToggle('normal');
		event.preventDefault();
	});

	//login
	$('.login-block a.login').bind('click', function (event) {
		$('.login-expand').slideToggle('fast');
		event.preventDefault();
	});

	testimonialRotator();
});

function randomSort(a, b) {
	return (parseInt(Math.random() * 10) % 2);
}

var testimonials = [
	{ quote: "Never knew that it was possible to save so much time. We felt we were doing a large number of repetitive manual tasks. We were amazed when Access quantified how many and made that disappear, giving us time to do our real work! A little automation never hurt anybody.", author: "Operations Manager" },
	{ quote: "My departments love your online services. They can track where every contract is and  who viewed or made changes to it. Everything is just more organised.", author: "Real Estate Franchisee" },
	{ quote: "It is so easy to use. I love that I don’t have to be an IT expert to use Access online.", author: "Accounts Payable Officer" },
	{ quote: "I didn’t have to get any capital approvals to purchase expensive infrastructure.  They just integrated with our existing equipment and we can call them anytime for help. It’s refreshing to finally see IT made easy.", author: "IT Manager" },
	{ quote: "This is perfect for a small business like mine. I get access to my most important information from anywhere and as for those other documents - thank God they’re not in my office anymore! I love the extra space i have now.", author: "Small business owner" },
	{ quote: "Our company deals with customer information, which needs to be constantly shared across departments and even other offices. As such, security compliance is non-negotiable and Access Online makes no discounts in that area.", author: "CIO" },
	{ quote: "It’s great value. I only pay for what I use and store, yet I feel as if I have an outsourced IT department. Thanks for the support and the peace of mind.", author: "Financial Accountant" },
	{ quote: "It’s done well for our bottom line. Information is more secured and more organised, so now we know when there is a bottle neck in our communications", author: "CEO" },
	{ quote: "My company uses Access to ensure information can be leveraged as an asset and keep our business moving forward. We believe in speedy service and efficient communication. Access helps us keep maintain this position in the market.", author: "Sales Manager" },
	{ quote: "Space. Lots if it. That was the immediate benefit, the moment we moved all our boxes from our office to their facility. Now, we are box free and if we need records, we can get them in two hours.", author: "HR Manager" },
	{ quote: "All I initially wanted was somewhere to keep my boxes. Now, not only do I know where my boxes are, I know where my documents, records and data are kept and used.", author: "Office manager" },
	{ quote: "Access originally promised that our archive and retrieval cost would decrease and that their service was second to none. Happily for us, Access has come good on both counts. We find the archival and retrieval of our files easy, quick and cheaper compared to our previous service provider.", author: "Records manager" },
	{ quote: "With more than 3,000 customers, our company has complex record keeping needs and when it comes to records management, Access is our provider of choice.", author: "Records manager" },
	{ quote: " Flexible to our needs, courteous and always delivering professional customer service, they are almost an extension of our business. We have developed a close working relationship with Access over the past three years and would not hesitate to recommend the team and service they have to offer to any prospective clients.", author: "Knowledge manager" }
];

function testimonialRotator() {
	if (testimonials && testimonials.length) {
		testimonials.sort(randomSort);
		$('#quotes').each(function () {
			var $testimonials = $(this),
			pos = 2,
			screenPos = 0;
			$testimonials.empty();
			for (var i = 0; i < pos; i++) {
				var html = '<blockquote>';
				html = html + '<q>&quot;' + testimonials[i]['quote'] + '&quot;</q>';
				html = html + '<cite>' + testimonials[i]['author'] + '</cite>';
				html = html + '</blockquote>';
				$testimonials.append(html);
				Cufon.refresh();
			}
			var showItem = function () {
				var html = '<blockquote>';
				html = html + '<q>&quot;' + testimonials[pos]['quote'] + '&quot;</q>';
				html = html + '<cite>' + testimonials[pos]['author'] + '</cite>';
				html = html + '</blockquote>';
				$testimonials.children().eq(screenPos).hide().html(html).fadeIn('slow');
				Cufon.refresh();
				pos++;
				pos %= testimonials.length;
				screenPos++;
				screenPos %= 3;
			};
			setInterval(function () {
				$testimonials.children().eq(screenPos).fadeOut('normal', showItem)
			}, 5000);
		});
	}
}
