var content_moving = false;
var open_div ;

function mousewheel_scroll_gallery(event) {
	
	if($('moving_general')){
		var delta = 0;
		
		if (!event) event = window.event; // For IE
		if (event.wheelDelta) {
				// IE & Opera
				delta = event.wheelDelta / 120;
				// In Opera 9, delta differs in sign as compared to IE.
				if (window.opera) delta = -delta;
		} else if (event.detail) {
				// Mozilla case: In Mozilla, sign of delta is different than in IE. Also, delta is multiple of 3.
				delta = -event.detail/3;
		}

		direction = (delta < 0 ? -1 : 1);
		move_media_gallery('moving_general', 'showing_general', 0, direction);
	}
}

function $u(id, url, extraPars, formId) {
	var pars = '';
	if(formId) pars = Form.serialize(formId);
	if(extraPars) pars = pars+'&'+extraPars;
	
	var myAjax = new Ajax.Updater( 
		id, 
		url+'.php', 
		{ method: 'post',
		  evalScripts: true,
		  requestHeaders: ['Expires', 'Thu, 17 May 2001 10:17:17 GMT',
		  				   'Cache-Control', 'no-cache, must-revalidate',
		  				   'Pragma', 'no-cache'],
		  parameters: pars,
		  onFailure: reportError } 
	);
}

function reportError() {
	alert('Ajax error');
}

function u(id, page, vars) {
	new Ajax.Updater(
		id, 
		page+'.php',
		{
			method: 'post',
			parameters: vars,
			requestHeaders: ['Expires', 'Thu, 17 May 2001 10:17:17 GMT', 'Cache-Control', 'no-cache, must-revalidate', 'Pragma', 'no-cache'],
			evalScripts: true
		});
}

function hide_div_show_active(div_to_hide, div_class, not_to_hide){

	var div_array= $(div_to_hide).getElementsByClassName(div_class);
		
	if(open_div != not_to_hide){
		for (a = 0; a < div_array.length; a++) {
			if(div_array[a].id == "friend_"+not_to_hide){ open_div = not_to_hide; continue ;} 
			
			// div_array[a].style.display = 'none';
			Effect.BlindUp(div_array[a], { duration: 0.5 });
		}
		Effect.toggle('omschr'+not_to_hide, 'blind');
	}
	else {
		Effect.toggle('omschr'+not_to_hide, 'blind');
		open_div = '';
		
		for (a = 0; a < div_array.length; a++) {
			
			if(div_array[a].id == "friend_"+not_to_hide){ continue ;} 
			//div_array[a].style.display = '';
			Effect.BlindDown(div_array[a], { duration: 0.5 });
		}
	}
}

function show_all_div(aantal_div, div_toshow_prefix, div_class ){
	
	if(open_div != ''){
		Effect.toggle("omschr"+open_div, "blind");
		open_div = '';
	}
	for (a = 1; a <= aantal_div ; a++){
		//alert(a);
		var div_array= $(div_toshow_prefix+a).getElementsByClassName(div_class);
		for (b = 0; b < div_array.length; b++) {
			div_array[b].style.display = '';
		//Effect.BlindUp(div_array[a], { duration: 0.5 });
		}
	}
}

function scrollup(moving_div){

	var top_pos = parseInt($(moving_div).style.top);
	Effect.MoveBy(moving_div , -1 * top_pos , 0, { duration: 0.5 } );
}

function move_media_gallery(moving_div, showing_div, direction_left_right, direction_up_down ) {
	// moving div propertys 
	//alert(parseInt($('moving_general').offsetWidth));
	//alert(parseInt($('moving_general').offsetHeight));
	
	var height_div = parseInt($('moving_general').offsetHeight);
	var width_div = parseInt($('moving_general').offsetWidth);
		
	// if gallery is moving stop else set time out for moving gallery
	if (content_moving) return;
    content_moving = true;
    setTimeout('content_moving = false;', 600);
	 
	// get left , top pos 
	var left_pos = parseInt($(moving_div).style.left);
	var top_pos = parseInt($(moving_div).style.top);
	
	// bereken te bewegen afstand 
	var distance = parseInt($(showing_div).style.width);
	var distance_up = parseInt($(showing_div).style.height);

	// dont move outside of range left right
	if (direction_left_right != 0){
		if (direction_left_right == 1 && left_pos >= 0){ return }
		else if (direction_left_right == -1 && left_pos <= -1 * width_div + distance){ return }

		Effect.MoveBy(moving_div, 0, distance * direction_left_right, { duration: 0.5} );
	}
	                
	// dont move outside of range up  down
	if(direction_up_down != 0){
		if (direction_up_down == 1 && top_pos >= 0){ return; }
		if (direction_up_down == -1 && top_pos <= -1 * height_div + distance_up){ return; }
	
		Effect.MoveBy(moving_div , distance_up * direction_up_down, 0, { duration: 0.5 } );
	}
}