function wait(ms) {
	var date = new Date();
	var curDate = null;
	do { curDate = new Date(); } while(curDate-date < ms);
} 

function coookie() {
	var cookieValue = "";
	var search = "showcomm=";
	if(document.cookie.length > 0) {
		offset = document.cookie.indexOf(search);
	  if (offset != -1) {
	  	offset += search.length;
	    end = document.cookie.indexOf(";", offset);
			if (end == -1) end = document.cookie.length;
			cookieValue = unescape(document.cookie.substring(offset, end))
		}
	}
	var setc = 1;
	if (cookieValue == "1") setc = 0;
	document.cookie = "showcomm=" + escape(setc);
}                         	

// =================== //
// gallery functions
function setOffset() {
	var thumbs = document.getElementById('thumbs');
	var cur = document.getElementById('current');
	var pid = document.getElementById('p_id');
	var offset = document.getElementById('offset');
	var num = 0;
	for(var i=0;i<thumbs.childNodes.length;i++) { 
		if (thumbs.childNodes[i].tagName == 'LI') { 
			num++;
			if (thumbs.childNodes[i].id == 'thumb-'+pid.value) { 
				cur.value = num; 
				thumbs.childNodes[i].className='active';
			} else {
				thumbs.childNodes[i].className='';
			};
		}
	}
	offset.value=eval( Math.floor((eval(cur.value)-1)/7)*7 );
}

function move(dir) {
	var thumbs = document.getElementById('thumbs');	
	var cur = document.getElementById('current');
	var pid = document.getElementById('p_id');	
	var offset = document.getElementById('offset');
	var thumbsbox = $('thumbs');
	var fx = thumbsbox.effects({duration: 1000, transition: Fx.Transitions.Cubic.easeOut});	
	var prev = $('prev');
	var next = $('next');
	var num = 0;
	var line = 6;
	var width = 71+2+1;
	var left = 1;
	var right = 1;

	for(var i=0;i<thumbs.childNodes.length;i++) { if(thumbs.childNodes[i].tagName == 'LI') { num++; } }

	if ((eval(offset.value)-line)<0) { left=0; prev.addClass('no'); } else { left=1; prev.removeClass('no'); }
	if ((eval(offset.value)+line)>num-1) { right=0; next.addClass('no'); } else { right=1; next.removeClass('no'); }

	if (dir==0) {
		thumbs.style.width = ((width) * num)+'px' ;
		thumbs.style.marginLeft = -eval(offset.value)*width+'px';
	} else {
		if ((dir==-1 && left) || (dir==1 && right)) {
			offset.value=eval(offset.value)+line*dir;
		}
			fx.start({
				'margin-left': -eval(offset.value)*width
			});
	}

	if ((eval(offset.value)-line)<0) { left=0; prev.addClass('no'); } else { left=1; prev.removeClass('no'); }
	if ((eval(offset.value)+line)>num-1) { right=0; next.addClass('no'); } else { right=1; next.removeClass('no'); }

}

function show(id) {
	var box = document.getElementById('photobox');
	var img = document.getElementById('photo');
	var offset = document.getElementById('offset');
	
	var photobox = $('photobox');
	var fx = photobox.effects({duration: 777, transition: Fx.Transitions.Cubic.easeOut});
	var photoimg = $('photo');
	var photoimg = $('curid');
	var photoimg = $('pid');

	var photo_url = '/articles/inc/ajax.php?id='+id+'&mode=1';
	var photoinfo_url = '/articles/inc/ajax.php?id='+id+'&mode=2';
	var comment_url = '/articles/inc/ajax.php?id='+id+'&mode=3';
	var curid_url = '/articles/inc/ajax.php?id='+id+'&mode=4';
	var pid_url = '/articles/inc/ajax.php?id='+id+'&mode=5';
	var dummy; 

	box.style.width = img.width+'px';
	box.style.height = img.height+'px';

// photo loading
	photobox.addClass('loading'); 
	var ajax_photo = new Ajax(photo_url, { 
		update: $('photobox'),
		method: 'get',
		onComplete: function() {
			var box = document.getElementById('photobox');
			var img = document.getElementById('photo');

			if (box.style.height!=(img.height+'px')) {
				fx.start({
					'width':  img.width,
					'height': img.height
				}).chain(function(){
					photobox.removeClass('loading');
				});
			} else {
				photobox.removeClass('loading');
			}
		},
		onCancel: function() {
			box.style.width = img.width+'px';
			box.style.height = img.height+'px';
			photobox.removeClass('loading');
		}
	});
	dummy = $random(0, 100);
	ajax_photo.request(dummy);
// end photo loading

// photoinfo loading
	var ajax_photoinfo = new Ajax(photoinfo_url, { 
		update: $('photoinfo'),
		method: 'get',
		onComplete: function() {
		},
		onCancel: function() {
		}
	});
	ajax_photoinfo.request();
// end photoinfo loading

// comment loading
	var ajax_comment = new Ajax(comment_url, { 
		update: $('comments-wrap'),
		method: 'get',
		onComplete: function() {
		},
		onCancel: function() {
		}
	});
	ajax_comment.request();
// end comment loading

// current num loading
	var ajax_curid = new Ajax(curid_url, { 
		update: $('curid'),
		method: 'get',
		onComplete: function() {
		},
		onCancel: function() {
		}
	});
	ajax_curid.request();
// end current num loading

// current photo id loading
	var ajax_pid = new Ajax(pid_url, { 
		update: $('pid'),
		method: 'get',
		onComplete: function() {
			setOffset(); 
			//move();				
		},
		onCancel: function() {
		}
	});
	ajax_pid.request();
// end current photo id loading

	var thumbs = document.getElementById('thumbs');
	var cur = document.getElementById('current');
	var pid = document.getElementById('p_id');
	var offset = document.getElementById('offset');
	var num = 0;
	for(var i=0;i<thumbs.childNodes.length;i++) { 
		if (thumbs.childNodes[i].tagName == 'LI') { 
			num++;
			if (thumbs.childNodes[i].id == 'thumb-'+pid.value) { 
				cur.value = num; 
				thumbs.childNodes[i].className='active';
			} else {
				thumbs.childNodes[i].className='';
			};
		}
	}
	if (offset.value!=eval(Math.floor(eval(cur.value) / (7+1))*7));

}
// end gallery functions
// =================== //

// =================== //
// calendar functions
function calendar(date,type) {
	var calendar = $('calendar');

	var url = './inc/ajax_calendar.php?date='+date+'&type='+type;

// calendar loading
	calendar.addClass('loading'); 
	var ajax_calendar = new Ajax(url, { 
		update: $('calendar'),
		method: 'get',
		onComplete: function() {
			calendar.removeClass('loading');
		},
		onCancel: function() {
			calendar.removeClass('loading');
		}
	});
	ajax_calendar.request();
// end calendar loading
}
// end calendar functions
// =================== //
