function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}

function imageFade(url){
	
	internetExplorerVersion = getInternetExplorerVersion();
	
	if(internetExplorerVersion < 6 && internetExplorerVersion != -1){
		return true;
	}
	
	$("#imageLoop").fadeIn(500);
	
	idImageOld = parseInt($("#imageLoop").children().attr("id"));
	idImage = (idImageOld + 1) % 2;//there is 2 id img where put the images; id = 0 new image where apply the transition -> id = old image to delete and viceversa
	
	var img = (jQuery.browser.safari) ? document.createElement('img'): new Image();
	
	$(img).load(function () {//image loaded	
		
		var imageLoaded = this;

		$("#imageLoop > #"+ idImageOld).fadeOut(500,function(){ //fade out old image
			$("#imageLoop").empty();//remove all children -> multiclick problem
			$("#imageLoop").append("<div id=\"" + idImage + "\"></div>");
			$("#imageLoop > #"+ idImage).css({position: "absolute", zIndex: "20"}).empty().append(imageLoaded).css({display:"none"}).fadeIn(500); //fade in new image
			
			$("a.imagePreview").css({zIndex: "21"});

		});

	}).error(function () {
		alert("Image could not be loaded");
	}).attr({ src: url});
	
	return false;
}

function divFade(div){
	
	internetExplorerVersion = getInternetExplorerVersion();
	
	if(internetExplorerVersion < 6 && internetExplorerVersion != -1){
		return true;
	}
	
	$("#imageLoop").fadeIn(500);
	
	idImageOld = parseInt($("#imageLoop").children().attr("id"));
	idImage = (idImageOld + 1) % 2;//there is 2 id img where put the images; id = 0 new image where apply the transition -> id = old image to delete and viceversa

	$("#imageLoop > #"+ idImageOld).fadeOut(500,function(){ //fade out old image
		$("#imageLoop").empty();//remove all children -> multiclick problem
		$("#imageLoop").append("<div id=\"" + idImage + "\"></div>");
		$("#imageLoop > #"+ idImage).css({position: "absolute", zIndex: "20"}).empty().append(div);
		initialize();
	});
		
	return false;
}
