$(document).ready(function(){

	positionMenu('#menu');
	positionMenu('#submenu');
	//inputWithSample($('#newsletter_email'), 'Your e-mail address');

	$('.block.features ul li').click(function(event){
		var url = $(this).find('a').attr('href');
		if (url) {
			event.preventDefault();
			window.location = url;
		}
	});

	$('#customer-service').qtip({
		content: $('#customer-service-popup'),
		show: 'mouseover',
		hide: {
			when: 'mouseout',
			delay: 1000,
			fixed: true
		},
		position: {
			adjust: {
				x: 7,
				y: 7
			},
			corner: {
				target: 'bottomLeft',
				tooltip: 'topLeft'
			}
		},
		style: { 
			'color': '#ffffff',
			'font-size': '1em',
			'font-weight': 'bold',
			'line-height': 1.4,
			'padding-top': '.8em',
			'padding-right': '3em',
			'padding-bottom': '.8em',
			'padding-left': '1.3em',
			'background': '#8dd51c',
			border: {
				width: 0
			},
			tip: {
				corner: 'topLeft',
				color: '#8dd51c',
				size: {
					x: 6, // Be careful that the x and y values refer to coordinates on screen, not height or width.
					y: 6 // Depending on which corner your tooltip is at, x and y could mean either height or width!
				}
			}
		}
	});

	$('.features .question').qtip({
		content: false,
		show: 'mouseover',
		hide: {
			when: 'mouseout',
			delay: 1000,
			fixed: true
		},
		position: {
			adjust: {
				x: 7,
				y: 7
			},
			corner: {
				target: 'bottomLeft',
				tooltip: 'topLeft'
			}
		},
		style: { 
			'color': '#ffffff',
			'font-size': '1em',
			'font-weight': 'bold',
			'line-height': 1.4,
			'padding-top': '.6em',
			'padding-right': '1em',
			'padding-bottom': '.6em',
			'padding-left': '1em',
			'background': '#202629',
			border: {
				width: 0
			},
			tip: {
				corner: 'topLeft',
				color: '#202629',
				size: {
					x: 6, // Be careful that the x and y values refer to coordinates on screen, not height or width.
					y: 6 // Depending on which corner your tooltip is at, x and y could mean either height or width!
				}
			}
		}
	});

	$('.anythingSlider').anythingSlider({
		easing: "swing",                // Anything other than "linear" or "swing" requires the easing plugin
		autoPlay: true,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not
		startStopped: false,            // If autoPlay is on, this can force it to start stopped
		delay: 10000,                    // How long between slide transitions in AutoPlay mode
		animationTime: 600,             // How long the slide transition takes
		hashTags: true,                 // Should links change the hashtag in the URL?
		buildNavigation: false,          // If true, builds and list of anchor links to link to each slide
		pauseOnHover: true,             // If true, and autoPlay is enabled, the show will pause on hover
		startText: "Start",             // Start text
		stopText: "Stop",               // Stop text
		navigationFormatter: null       // Details at the top of the file on this use (advanced use)
	});

	$('#button-try-demo').click(function(event){
		event.preventDefault();
		$(this).toggleClass('arrow-right');
		$(this).toggleClass('arrow-down');
		$('#form-try-demo').slideToggle();
	});
	//$('#button-sign-up').click(function(event){
	//	event.preventDefault();
	//	$(this).toggleClass('arrow-right');
	//	$(this).toggleClass('arrow-down');
	//	$('#form-sign-up').slideToggle();
	//});
	$('#button-more-customers').click(function(event){
		event.preventDefault();
		$('#more-customers').slideToggle();
	});

});

$(window).resize(function(){
	positionMenu('#menu');
	positionMenu('#submenu');
});





function positionMenu(menu) {
	$(menu).css('width', 'auto');
	$(menu).css('float', 'left');
	w = $(menu).innerWidth();
	b = $(document).width();
	if (b > 960) {
		$(menu).css('margin-left', b/2-w/2);
	}
}
function inputWithSample(field, sample_text) {
    field.parents('form').submit(function(){
        if (field.hasClass('sample')) {
            field.val('');
        }
    });
    function setSample(field) {
        if (field.val() === "") {
            field.addClass('sample');
            field.val(sample_text);
        }
    }
    setSample(field);
    field.keyup(function(){
        if (field.val() !== sample_text) {
            field.removeClass('sample');
        }
    });
    field.click(function(){
        if (field.hasClass('sample') && field.val() == sample_text) {
            field.removeClass('sample');
            field.val('');
        }
    });
    field.blur(function(){
        setSample(field);
    });            
}