function rotate() {
	// Get the first image
	var current = ($('div#rotator ul li.show') ? $('div#rotator ul li.show')
			: $('div#rotator ul li:first'));

	// Get next image, when it reaches the end, rotate it back to the first
	// image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#rotator ul li:first')
			: current.next())
			: $('div#rotator ul li:first'));

	// Set the fade in effect for the next image, the show class has higher
	// z-index
	next.css( {
		opacity : 0.0
	}).addClass('show').animate( {
		opacity : 1.0
	}, 1000);

	// Hide the current image
	current.animate( {
		opacity : 0.0
	}, 1000).removeClass('show');
};

function theRotator() {
	// Set the opacity of all images to 0
	$('div#rotator ul li').css( {
		opacity : 0.0
	});

	// Get the first image and display it (gets set to full opacity)
	$('div#rotator ul li:first').css( {
		opacity : 1.0
	});

	// Call the rotator function to run the slideshow, 6000 = change to next
	// image after 6 seconds
	setInterval('rotate()', 6000);
}

function pakketten_meer(pos) {

	$("#hide_p" + pos).slideToggle("slow");

	$("#extra_p" + pos).fadeToggle();
	$("#links_p" + pos).fadeToggle();

	if ($("#meer_" + pos).html() == 'Lees verder') {
		$("#meer_" + pos).html('Sluiten');
	} else {
		$("#meer_" + pos).html('Lees verder');
	}
}

function doorsturen(id, soort) {
	Boxy.load(baseurl + '/doorsturen.php?id=' + id + '&soort=' + soort, {
		title : 'Doorsturen',
		modal : true
	})
}

function ajax(url, target, laden) {
	// native XMLHttpRequest object
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
		if (req.overrideMimeType) {
			req.overrideMimeType('text/html; charset=iso-8859-1');
		}
		req.onreadystatechange = function() {
			jahDone(target);
		};
		req.open("GET", url, true);
		req.send(null);
		// IE/Windows ActiveX version
	} else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
		if (req) {
			req.onreadystatechange = function() {
				jahDone(target);
			};
			req.open("GET", url, true);
			req.send();
		}
	}
}

function jahDone(target) {
	// only if req is "loaded"
	if (req.readyState == 4) {
		// only if "OK"
		if (req.status == 200) {
			results = req.responseText;
			// native XMLHttpRequest object
			//document.getElementById('progres_bar').style.display = 'none';
			document.getElementById(target).innerHTML = results;
		} else {
			//document.getElementById('progres_bar').style.display = 'none';
		}
	}
}

$(document).ready(function() {

	$("#nieuws-scroller").jCarouselLite( {
		vertical : true,
		hoverPause : true,
		visible : 3,
		auto : 4000,
		speed : 1000
	});

	$('.offerte_img').tipsy( {
		gravity : 'e',
		html : true
	});

	$('.tooltip').tipsy( {
		gravity : 'w',
		html : true,
		classname : 'pakket-tool',
		classnameinner : 'pakket-tool-inner'
	});

	$("#slider").easySlider( {
		auto : true,
		pause : 10000,
		continuous : true,
		numeric : true
	});

	jQuery.fn.fadeToggle = function(speed, easing, callback) {
		return this.animate( {
			opacity : 'toggle'
		}, speed, easing, callback);

	};

	$(".slide_li").click(function() {
		var pos = $(this).attr('id');
		var url = $(this).attr('href');

		var active = $('#sub_' + pos).attr('class');

		$('#sub_' + pos).toggleClass('.hide');

		$('#sub_' + pos).slideToggle("1000");

		setTimeout(function() {

			if (active == 'active') {
				location.href = baseurl2 + '/toebehoren';
			} else {
				location.href = url;
			}
		}, '500');

		return false;
	});

	$(".meer").click(function() {
		pos = $(this).parent().attr('id')

		$("#hide_" + pos).slideToggle("slow");
		$("#extra_" + pos).fadeToggle();
		$("#links_" + pos).fadeToggle();

		if ($(this).html() == 'Lees verder') {
			$(this).html('Sluiten');
		} else {
			$(this).html('Lees verder');
		}
	});

	$(".offerte_input").click(function() {
		val = $(this).val();
		val3 = $(this).attr('id');

		if (val == val3)
			$(this).attr("value", "");
	});

	$(".offerte_input").blur(function() {
		val2 = $(this).val()
		val3 = $(this).attr('id');

		if (val2 == '') {
			$(this).attr("value", val3);
			$(this).removeClass("offerte_input2");
		} else {
			$(this).addClass("offerte_input2");
		}
	});

	$(".offerte_input").keypress(function() {
		$(this).addClass("offerte_input2");
	});

	$("#logo_top").click(function() {
		location.href = baseurl2;
	});

	$("#logo_header").click(function() {
		location.href = baseurl2;
	});

	$(".meernieuws").click(function() {
		pos = $(this).parent().parent().attr('id')

		if ($(this).html() == 'Lees meer') {
			$(this).html('Sluiten');
		} else {
			$(this).html('Lees meer');
		}

		$("#hide_" + pos).toggle("slow");
	});

	$(document).ready(function() {
		// Load the slideshow
			theRotator();
		});
});
