Function.prototype.later = function(ms,s) {
	
	var sf = this,
	f = function() {
		var a = f.arguments,
		lf = function() { sf.apply(s,a); }
		setTimeout(lf,ms);
	}
	return f;
}

jQuery(document).ready(function($){
	
	var themePath = '../wp-content/themes/bosalon/';
	
	$('#topMenu img.anime').rollover();
	$('#sidebar img.anime').rollover();
	
	$('.pagetop').click(function(e) {
		$.scrollTo($('#top'), { speed:500, axis:'y' } );
	});
	
	$('#nailgalleryStage').each(function() {
		
		var file = 'nailgallery.xml',
		stage = $(this);
		
		// load gallery xml file.
		$.ajax({
			url: themePath + file,
			type: 'GET',
			dataType: 'xml',
			error: function(){
				alert('Error loading XML document(' + file + ')');
			},
			success: function(xml){
				
				var s = '<table>',
				column = 3,
				c = 0;
				
				$(xml).find('image').each(function(){
					var self = $(this),
					url = self.attr('url'),
					bigurl = self.attr('bigurl'),
					title = self.attr('title'),
					comment = self.attr('comment');
					
					if (c % column == 0) s += '<tr>';
					
					s += '<td><a class="fancybox" rel="group" title="'
						+ title + '" href="' + themePath + 'images/nailgallery/'
						+ bigurl + '"><img class="shadow" src="' + themePath
						+ '/images/nailgallery/' + url + '" alt=""/></a>'
						+ '<p><b>' + title + '</b><br/>' + comment + '</p></td>';
					
					if (c % column == column - 1) s += '</tr>';
					c++;
				});
				
				s += '</table>';
				stage.append($(s));
				
				$('a.fancybox').fancybox();
			}
		});
	});
});
