//document ready
$(function(){

	$('.box-research select').selectbox();
	
	// Cycling integers
	(function melodyCounter() {
		var counter = $('.counter');
		var ul = counter.find('ul');
		var lis = ul.find('li');
		
		lis.each(function() {
			var li = $(this);
			$(this).data('order', $(this).index());
			$(this).data('start', parseInt($(this).text()));
			$(this).html('<span>0<br />1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />0</span>');
			$(this).find('span').css('top', '-' + li.data('start') * li.height() + 'px');
		});
		
		function increment(li) {
			var span = li.find('span');
			var spanTop = Math.abs(parseInt(span.css('top')));
			
			span.animate({ top: '-' + (spanTop + li.height()) + 'px'}, 350, function() {
				if (spanTop == span.height() - li.height() * 2) {
					span.css('top', 0);
				}
			});
			
			if (spanTop == span.height() - li.height() * 2) {
				increment(li.prev());
			} else {
				// Setting the increment random timer
				setTimeout(function() {
						increment(lis.last());
				}, Math.floor(Math.random()*7000+5000));
			}
		}
		
		setTimeout(function() {
			increment(lis.last());
		}, Math.floor(Math.random()*2000+3000));
	})();

	//form validation
	(function validateForm() {
			var email = document.getElementById('email').value;
			var name = document.getElementById('name').value;
			if ((email == "") || (name == "")) {
				document.getElementById('error_label').innerHTML  = "Required field missing.";
				return false;
			}
			var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
			if(reg.test(email) == false) {
				document.getElementById('error_label').innerHTML  = "Invalid email address.";
				return false;
			}
			document.getElementById('error_label').innerHTML  = "";
			document.getElementById('formsubmit').disabled = true;
			return true;
		})
		

	//add even class
	$('.table-example tr:even').addClass('even');

	//more text
	$('.product .more').click(function(){
		$(this).parents('.entry-box').find('.excerpt').hide();
		$(this).parents('.entry-box').find('.full-text').show();
		return false;
	})
	
	// less text
	$('.product .less').click(function(){
		$(this).parents('.entry-box').find('.excerpt').show();
		$(this).parents('.entry-box').find('.full-text').hide();
		return false;
	})
})

// slider
$(window).load(function(){
	if( $('.slider').length ){
		$('.slider ul').jcarousel({
			auto: 0,
			visible: 1,
			scroll: 1,
			animation: 750
		})
	}
})
	
