 $(document).ready(function() {	
			
		
	$("form#form1").submit(function() {
      if ($('#check_1:checked').val() == null && $('#check_2:checked').val() == null && $('#check_3:checked').val() == null && $('#check_4:checked').val() == null && $('#check_5:checked').val() == null && $('#check_6:checked').val() == null && $('#check_7:checked').val() == null && $('#check_8:checked').val() == null) {
		  
			$("#dialog").dialog({
				bgiframe: true,
				height: 140,
				modal: true
			});
		  
		  return false;
      }
        return true;
    });
		
		
	$("form#form2").submit(function() {
	  if ($('.ui-helper-close').html() == null) {
		  
		 	$("#dialog").dialog({
				bgiframe: true,
				height: 140,
				modal: true
			});	  
		  
		  return false;
      }
        return true;
    });
		
	
	
		
	
	
	$("a.popup").fancybox({
		'frameWidth':		550,
		'frameHeight':		345,
		'padding':			0,
		'zoomSpeedIn':		300, 
		'hideOnContentClick':		false, 
		'overlayShow':		false, 			
		'zoomSpeedOut':		300
	});
	
	$(".dragster222").mouseup(function(){					
			
	  	var $item = $(this);
		var $item_ID = $item.attr('id');
		var $item_position = $item.position();
		var $item_position_top = $item_position.top - 11;
		var $item_position_left = $item_position.left;
		
		
		var $item_tijd = ($item_position_top / 32) + 9;
		$item_tijd = Math.round($item_tijd*10)/10;
		
		$var_links_name = "links_"+$item_ID;
		
		// sla de waardes op in de hidden fields
		//$("#links_"+$item_ID).val();
		$("#ID_"+$item_ID).val($item_ID);
		$("#links_"+$item_ID).val($item_position_left);
		$("#top_"+$item_ID).val($item_tijd);
									
      $("#result").html("gedropped: "+$("#top_"+$item_ID).val());
	  
    })
	
	
	if ($.browser.msie) {
	  $(".radio_basis").click(function() {
		this.blur();
		this.focus();
	  });
	  $(".radio_voortgezet").click(function() {
		this.blur();
		this.focus();
	  });
	  $(".radio_bedrijven").click(function() {
		this.blur();
		this.focus();
	  });
	}
	
	
	
	// Radio buttons scherm 1
	$(".radio_basis").change(function(){	
		  $(".selectdoos").attr('checked', false);
	  	  $(".kiesinteresses").hide();	
	  	  $(".basis").show("fast");	  	  
	  	  $("#containerKeuzes").fadeTo("fast", 1);
    })
	
	$(".radio_voortgezet").change(function(){	
		  $(".selectdoos").attr('checked', false);	
	  	  $(".kiesinteresses").hide();
	  	  $(".voortgezet").show("fast"); 
	  	  $("#containerKeuzes").fadeTo("fast", 1);
    })
	
	$(".radio_bedrijven").change(function(){	
		  $(".selectdoos").attr('checked', false);
	  	  $(".kiesinteresses").hide();
	  	  $(".bedrijven").show("fast"); 
	  	  $("#containerKeuzes").fadeTo("fast", 1);
    })
	
	$(function() {
			
			// there's the gallery and the trash
			var $gallery = $('#gallery'), $trash = $('#trash');
			
			// let the gallery items be draggable
			$('li',$gallery).draggable({
				snap: '#trash',
				containment: '#arrangementenKader',
				cancel: 'a.ui-icon',// clicking an icon won't initiate dragging
				revert: 'invalid', // when not dropped, the item will revert back to its initial position
				opacity: 0.7,
				helper: 'clone',
				cursor: 'move'
			});

			// let the trash be droppable, accepting the gallery items
			$trash.droppable({
				accept: '#gallery > li, #trash li',
				drop: function(ev, ui) {
					
					var $item = ui.draggable;
					var $optellen = 0;
					var $item_ID = $item.attr('id');
					var $activeWaarde = $item.find('#selected_'+$item_ID).val()
					
					if($activeWaarde == 'inactief'){
						$optellen = 114;
					}
					
					
					deleteImage(ui.draggable, ui.position.top+$optellen, ui.position.left);
				}
			});

			// let the gallery be droppable as well, accepting items from the trash
			$gallery.droppable({
				accept: '#trash li',
				drop: function(ev, ui) {
					recycleImage(ui.draggable);
				}
			});

			
			$('li').droppable({
				accept: '#gallery > li, #trash li',
				tolerance: 'touch',
				drop: function(ev, ui) {
					//alert("Dag indeling mag geen overlappende arrangementen bevatten");					
				}
			});

			// image deletion function
			var recycle_icon = '<a href="link/to/recycle/script/when/we/have/js/off" title="Recycle this image" class="ui-icon ui-icon-close">Recycle image</a>';
			function deleteImage($item, $positieBoven, $positieLinks) {
								
				var $list = $('ul',$trash).length ? $('ul',$trash) : $('<ul class="gallery ui-helper-close"/>').appendTo($trash);
				$item.find('a.ui-icon-close').remove();
				$item.prepend(recycle_icon).appendTo($list);
				
				var $item_ID = $item.attr('id');
				var $item_tijd = ($positieBoven / 33) + 5.2;
				$item_tijd = Math.round($item_tijd*10)/10;
				
				$item.find('#selected_'+$item_ID).val('actief');
				$item.find('#tijd_'+$item_ID).val($item_tijd);
								
				var cssObj = {
					'float' : 'none',
					'position' : 'absolute',
					'left' : '30px',
					'top' : $positieBoven+'px'
				}
				$item.css(cssObj);
								
			}

			// image recycle function
			function recycleImage($item) {
				$item.fadeOut(function() {
					
					var $item_ID = $item.attr('id');
					$item.find('#selected_'+$item_ID).val('inactief');
					
					var cssObj = {
						'float' : 'left',
						'position' : 'relative',
						'left' : '0px',
						'top' : '0px'
					}
					$item.css(cssObj);
					
					$item.find('a.ui-icon-close').remove();
					
					//$item.prependTo($gallery).fadeIn();
					$item.appendTo($gallery).fadeIn();
				});
			}

			// resolve the icons behavior with event delegation
			$('ul.gallery > li').click(function(ev) {
				var $item = $(this);
				var $target = $(ev.target);

				if ($target.is('a.ui-icon-trash')) {
					deleteImage($item);
				} else if ($target.is('a.ui-icon-zoomin')) {
					viewLargerImage($target);
				} else if ($target.is('a.ui-icon-close')) {
					recycleImage($item);
				}

				return false;
			});
		});
	
	
	
	
	// png fix
	$('.doorzichtig').pngFix();
	
	// flash bestanden
	$('#logo').flash(
        { src: '../swf/logo_gp.swf',		
          wmode: 'transparent', 
          width: 200,
          height: 178 },
        { version: 8 }
    );	
	$('#titel').flash(
        { src: '../swf/top_gp.swf',		
          wmode: 'transparent', 
          width: 630,
          height: 60 },
        { version: 8 }
    );
	
	 
	 
 });
 
	$(function(){
		$('input').customInput();
	});

