$(document).ready(function() {
	
	// MESSAGE
	$('div#msg').ajaxStart(function() { 
		$(this).html("<p>Loading...</p>");
	});
	$('div#msg').ajaxStop(function() { 
		$(this).empty();
	});
	
	// FADE
	$("div#container").css("display", "none").fadeIn("slow");
	$("a").click(function() {
		var target = $(this).attr("target");
		if(target=="_blank") {
			return true;
		} else {
			var href = $(this).attr("href");
			$("div#container").fadeOut("slow",function() {
				$("div#msg").html('<p><a href="#" onclick="$(\'div#container\').fadeIn(\'slow\');$(this).empty();return false;">Refresh</a></p>');
				$("div#msg").css({ "position": "absolute", "top": "50%", "left": "50%" });
				document.location = href;
			});
			return false;
		}
	});
	
	// GALLERIES
	$('div#gallery-thumbs img').click(function() {
		/*$('div#top-left').ajaxStart(function() { 
			$(this).css("background", "url(/images/loading.gif) no-repeat 184px 134px");
		});*/
		$('div#top-left').load("/ajax/gallery_show_picture/?directory="+$(this).attr('rel')+"&picture="+$(this).attr('alt'));
	});
	
	// IMAGE MAP
	$("a img.view").click(function() {
		$('div#'+$(this).parent().attr("rel")).load("/ajax/view_show_picture/?picture="+$(this).attr('alt'));
		return false;
	});
	
	// SUBMENU
	if ( $.browser.msie ) {
		$("ul#submenu li a").each(function() {
			if ( Helper.findImageFormat($(this).children("img").attr("src")) == "png" ) { //$(this).children("img").attr("src").indexOf(".png") != -1 ) {
				$(this).html(Helper.displayPngImage($(this).attr("rel")));
			}			
		});
	}
	$('ul#submenu li a').hover(
		function() {
			if ( $.browser.msie && $(this).children("img").attr("src") == undefined ) {
				if( $(this).attr("rel").indexOf("-bold") == -1 ) {					
					$(this).children("div.transparent-png-container").children("div.transparent-png").css({ filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader (src=\'"+Constants.imgRoot+"/links/"+$(this).attr("rel")+"-bold.png\', sizingMethod=\'scale\')" });
				}
			} else  {
				if ( $(this).attr("rel").indexOf("-bold") == -1 ) {
					var format = Helper.findImageFormat($(this).children("img").attr("src"));
					$(this).children("img").attr({ src: Constants.imgRoot+"/links/"+$(this).attr("rel")+"-bold."+format });
				}
			}			
		},
		function() {
			if ( $.browser.msie && $(this).children("img").attr("src") == undefined ) {
				if( $(this).attr("rel").indexOf("-bold") == -1 ) {					
					$(this).children("div.transparent-png-container").children("div.transparent-png").css({ filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader (src=\'"+Constants.imgRoot+"/links/"+$(this).attr("rel")+".png\', sizingMethod=\'scale\')" });
				}
			} else  {
				if ( $(this).attr("rel").indexOf("-bold") == -1 ) {
					var format = Helper.findImageFormat($(this).children("img").attr("src"));
					$(this).children("img").attr({ src: Constants.imgRoot+"/links/"+$(this).attr("rel")+"."+format });
				}
			}
		}
	);
});

Helper = {
	findImageFormat : function(img) {
		var format;		
		if(img.indexOf(".png")>0)
			format = "png";
		else if(img.indexOf(".jpg")>0)
			format = "jpg";
		else
			format = "gif";
		return format;
	},
	displayPngImage : function(img) {
		return '<div class="transparent-png-container" style="width:13px"><img src="/images/links/spacer.gif" alt="'+image+'" /><div class="transparent-png" style="height:200px;width:13px;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader (src=\'/images/links/'+image+'.png\', sizingMethod=\'scale\')"></div></div>'
	}	
};