$.fn.cycle.defaults.timeout = 800;
$.fn.cycle.defaults.random = 1;

$(function() {
    setTimeout(function() {
        $('#ad-partners img').fadeIn();
        $('#ad-partners').cycle();
    });
});

$(function() {
    setTimeout(function() {
        $('#ad-clients img:first').fadeIn();
        $('#ad-clients').cycle();
    });
});

$(function() {
	$("#for-publishers").hover(function () {
		$("#for-publishers p").fadeIn("fast");
	}, 
	function () {
		$("#for-publishers p").fadeOut("fast");
	});
});

$(function() {
	$("#for-advertisers").hover(function () {
		$("#for-advertisers p").fadeIn("fast");
	}, 
	function () {
		$("#for-advertisers p").fadeOut("fast");
	});
});

$(function() {
	setTimeout(function() {
		$('#slot-one img:first').fadeIn();
		$('#slot-one').cycle({
			pause: 1,
			timeout:  5000,
			speed:  1000,
			delay:  -4000
		});
	});
});

$(function() {
	setTimeout(function() {
		$('#slot-two img:first').fadeIn();
		$('#slot-two').cycle({
			pause: 1,
			timeout:  5000,
			speed:  1000,
			delay:  -2000
		});
	});
});

$(function() {
	setTimeout(function() {
		$('#slot-three img:first').fadeIn();
		$('#slot-three').cycle({
			pause: 1,
			timeout:  5000,
			speed:  1000
		});
	});
});


var stop = false;

// Stops adding extra images after a length of time
$(document).ready(function(){
	$.timer(210000, function (timer) {
		stop = true;
		timer.stop();
	});
});

// Repeats the images before the marquee has a chance to end, which prevents the blank spots
$(document).ready(function(){
	$.timer(1000, function (timer) {
		if (!stop) {
			var customerlogos = $('#platform-customers > div > div').html();
			$("#platform-customers > div > div").append(customerlogos);
			timer.reset(50000);
		} else{
			timer.stop();
		}
	});
});

$(document).ready(function(){
	$.timer(1000, function (timer) {
		if (!stop) {
			var advertiserlogos = $('#platform-advertisers > div > div').html();
			$("#platform-advertisers > div > div").append(advertiserlogos);
			timer.reset(50000);
		} else{
			timer.stop();
		}
	});
});
	
$(function () {
$('#platform-customers p').marquee().mouseover(function () {
	$(this).trigger('stop');
	}).mouseout(function () {
		$(this).trigger('start');
	}).mousemove(function (event) {
		if ($(this).data('drag') == true) {
		event.preventDefault();
		this.scrollLeft = $(this).data('scrollX') + ($(this).data('x') - event.clientX);
	}
	}).mousedown(function (event) {
		event.preventDefault();
		$(this).data('drag', true).data('x', event.clientX).data('scrollX', this.scrollLeft);
	}).mouseup(function () {
		$(this).data('drag', false);
	});
});

$(function () {
$('#platform-advertisers p').marquee().mouseover(function () {
		$(this).trigger('stop');
	}).mouseout(function () {
		$(this).trigger('start');
	}).mousemove(function (event) {
		if ($(this).data('drag') == true) {
		event.preventDefault();
		this.scrollLeft = $(this).data('scrollX') + ($(this).data('x') - event.clientX);
	}
	}).mousedown(function (event) {
		event.preventDefault();
		$(this).data('drag', true).data('x', event.clientX).data('scrollX', this.scrollLeft);
	}).mouseup(function () {
		$(this).data('drag', false);
	});
});
