google.load("jquery", "1.5");
google.load("jqueryui", "1.8");

google.setOnLoadCallback(function()
{
	var path = new Array();
	var sp = new Array();
	var segment0 = $("#segment0").val();
	var segment1 = $("#segment1").val();

	$('.vehicle-select').change(function() {


		if($(this).hasClass('first'))
		{
			$('select.second option').attr('selected','');
			$('select.second option:first').attr('selected','selected');
			$('select.third option:first').attr('selected','selected');
		}
		if($(this).hasClass('second'))
		{
			$('select.third option').attr('selected','');
			$('select.third option:first').attr('selected','selected');
		}

		$('.vehicle-select').each(function(i)
		{
			var text = $(this).find('option:selected').text();
			var value = $(this).val();

			if(value != '')
			{
				text = text.replace(/ /g, '-');
				text = text.replace(/\//g, '-');
				path.push(text);
				sp.push(value);
			}
		});

		document.location.href = '/catalogus/bladeren/' + path.join('/') + '/?sp=' + segment0 + '_' + segment1 + '_' + sp.join('_');
	});


	$('#licencesearchform').submit(function() {
		$(this).attr('action', $(this).attr('action') + $('#licenceplate').val() + '/');
		return true;
	});

	$("#searchlicence").click(function() {
		$('#licencesearchform').submit();
	});

	$('#artsearchform').submit(function() {
		query = $('#query').val().replace(/ /g, '');
		query = query.replace(/\//g, '');

		$(this).attr('action', $(this).attr('action') + query + '/');
		return true;
	});

	$("#query").click(function() {
		if($(this).val() == $(this).attr('rel'))
		{
			$(this).val('');
		}
	});


	$("#licenceplate").click(function() {
		if($(this).val() == $(this).attr('rel'))
		{
			$(this).val('');
		}
	});


	$('.cancel').click(function() {
		$('#addproductform').fadeOut();
	});

	$('.addfloatinarticle').click(function() {
		$('.artnumber').val($(this).attr('rel'));
		$('#addproductform').fadeIn();
	});

	$('.confirm').click(function(e) {
		e.preventDefault();

		if($(this).attr('rel') != '')
		{
			if(confirm($(this).attr('rel')) == true)
			{			
				document.location.href = $(this).attr('href');
			}
		}
		else
		{
			if(confirm('Zeker weten?') == true)
			{			
				document.location.href = $(this).attr('href');
			}
		}
		
		return false;
	});

	$(".info-panel ul").hover(function() {
		if($(this).find('li').length > 5)
		{
			$(this).addClass('hover');
		}

	}, function() {
		$(this).removeClass('hover');
	});

	$("#image-enlarge #title").click(function() {
		$("#image-enlarge").fadeOut();
	});;

	$('#tabs').tabs();

	$("#admin-actions").draggable({
		containment: 'body'
	});


	$("#slider").slideView();

	$("#regform").submit(function() {

		pass = true;

		if($("#agreeterms").attr('checked') == false)
		{
			alert($("#agreeterms").attr('rel'));
			pass = false;
		}

		$(".password").each(function() {
			if($(this).val() == "")
			{
				alert($(this).attr('rel'));
				pass = false;
			}
		});

		return pass;
	});

	$(".status").click(function() {
		$(this).hide();
		$(this).next('.changestatus').show();
	});
	$(".changestatus").change(function() {
		document.location.href = $(this).attr('rel') + $(this).val();
	});


	$(".articleitem").hover(function() {
		$(this).addClass('hoverart');
	},function() {
		$(this).removeClass('hoverart');
	})
	
	$(".articleitem").click(function() {
		document.location.href = $(this).attr('link');
	});
	
	$(".articleitem input[type=text]").click(function(e) {
		e.preventDefault();
		return false;
	});

	$(".thumbnailwrap").not(".nolarge").click(function(e) {
		e.preventDefault();
		$("#image-enlarge img").attr('src', $(this).find('.thumbnail').attr('rel'));
		$("#image-enlarge").fadeIn();
		return false;
	});

	$('.imageItem').find('img').each(function(i) {
		if($(this).attr('href'))
		{
			if($(this).attr('target') != '')
			{
				$(this).wrap('<a href="' + $(this).attr('href') + '" target="' + $(this).attr('target') + '" />')
			}
			else
			{
				$(this).wrap('<a href="' + $(this).attr('href') + '" />')
			}
		}

	});
	
	function slide()
	{
		if($(".stripTransmitter .current").parents('li').next('li').html())
		{
			$(".stripTransmitter .current").parents('li').next('li').find('a').click();
		}
		else
		{
			$(".stripTransmitter li:first a").click();
		}

		setTimeout(function() {
			slide();
		}, 5000);
	}

	$(".datepicker").datepicker({
		dateFormat: 'dd-mm-yy'
	});


	slide();


});
