//non specific custom functions

// For preloading images

var cache = [];
  // Arguments are image paths relative to the current page.
  var preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
  
//Quick AJAX
  
function getContent(p,c, callback){
	page = p.split('?');
	$.ajax({
		type: "GET",
		url: page[0],
		data: page[1],
		cache: false,
		success: function(html){
			c.append(html);
		},
		complete: function(){
			if(typeof callback != 'undefined'){
				callback(c);	
			}
		}
	});
}

//dim and display an image, with a gallery if possible, do not call from an image
function showImage(fname,path,w,h,thisOne){
	thisOne.append('<div class="loadingOverlay"></div>');
	$('body').append(
				$('<div></div>')
					.attr({id:'imageOverlay'})
					.append(
						$('<div></div>')
							.attr({id:'imageBg'}),
						$('<img>')
							.attr({id:'overlayedImage',border:'0',src:'image.php/'+ fname +
															'?width='+ ($(window).width() > w ? w : $(window).width())+
															'&height='+ ($(window).height() > h ? h : $(window).height())+
															'&image='+ path})
															.css({marginTop:'-'+(($(window).height() > h ? h : $(window).height())/2)+'px'})
					)
		);
	$('#imageOverlay').hide();
	
	$('#overlayedImage').bind('load',function(){
		$('#imageOverlay').fadeIn(function(){
			thisOne.children('.loadingOverlay').remove();	
		});
	});
	$('#imageOverlay').click(function(){
		$(this).fadeOut($(this).unbind().remove());	
	});
}
