if (self == top && !GLOBAL.ADMIN) {
	window.location = '/frame.php' + self.location.search;
}



$(function() {
	
	$(document).keydown(function(event) {
		try {
			top.frames['main'].keyHandler(event);
		}
		catch(err) {} // frame not loaded yet, ignore this keypress
	});
	
	
	// Show index of thumb
	var thumbs = $('#thumbs a');
	if (thumbs.length > 1) {
		thumbs.each(function() {
			var thumbIndex, defaultValue, timer;
			var main = top.frames['main'];
			if (main) {
				$(this).hover(function() {	
					thumbIndex   = main.document.getElementById('thumbIndex');
					defaultValue = thumbIndex.innerHTML;
					var curIndex = $(this).index() + 1;
					timer = setTimeout(function() {
						thumbIndex.innerHTML = defaultValue.replace(/^(\d+)/, '<span>' + curIndex + '</span>');
					}, 500);
					
				},
				function() {
					clearTimeout(timer);
					thumbIndex.innerHTML = defaultValue;
				});
			}
		});
	}
	
	
	if (GLOBAL.LOGIN) {
		$('#thumbs').sortable({
			axis:'y',
			distance:10,
			forcePlaceholderSize:true,
			opacity:0.7,
			placeholder:'placeholder',
			revert:100,
			scroll:true,
			tolerance:'intersect',
			update:function(event, ui) {
				//var newOrder = $(this).sortable('toArray').toString();
				var newOrder = $(this).sortable('serialize', {attribute: 'href'}).match(/(\d+)/g).toString();
				$.get(self.location.href, {itemIds:newOrder});
			}
		});
	}
	
});
