$.fn.extend({
	pngFix: function() {
		$(this).append('<!--[if lte IE 6]><script type="text/javascript">var ie6=true;</script><![endif]-->');
		if (typeof(ie6)!="undefined") {
			$("INPUT[src$=.png], IMG[src$=.png]", this).each(function() {
				$(this).get(0).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+$(this).attr('src')+"', sizingMethod='image');";
	   			$(this).attr("src", $.folder+"javascript/blank.gif");
			});
		}
	}
});
$(function () {
	$.folder = $.getFolder();
	$(document).pngFix();
	$("#topImg DIV DIV").fadeTo(3000, 1, function () {
		$(this).get(0).style.filter = "";
		$(this).parent().css("backgroundColor", "transparent").fadeTo(2000, 0, function () {
			if ($("#imgWrap").is("*")) {
				var height = 0;
				$("#imgWrap IMG")
					.each(function () {if ($(this).height() > height) height = $(this).height();})
					.each(function () {$(this).css("paddingBottom", height - $(this).height())});
				$("#imgWrap").height(height);
				window.setInterval(function () {
					var len = $("#imgWrap IMG").length;
					var current = 0;
					var bg = $("#imgWrap").css("backgroundImage");
					var found = false;
					$("#imgWrap IMG").each(function () {
						if (!found && (bg == "url("+$(this).attr("src")+")" || bg == "url(\""+$(this).attr("src")+"\")")) {
							current = $("#imgWrap IMG").index(this);
							$("#imgWrap IMG:eq("+(current+1 == len ? 0 : current+1)+")").fadeTo(500, 1, function () {
								$(this).parent().css("backgroundImage", "url("+$(this).attr("src")+")");
								$(this).css("opacity", 0).hide();
								found = true;
							});
						}
					});
					
				}, 3500);
			}
		});
	});
	// CUFON ###########################
	$("H1, H2.swf").css("visibility", "visible");
	Cufon.replace('h1', {fontFamily: "eurostile"});
	Cufon.replace('h2.swf', {fontFamily: "eurostileBoldCondensed"});
	// TABLE ROLLOVERS ###################################
	$("#content TABLE TR:has(TD > H3 > A)").each(function () {
		var href = $("TD > H3:first > A:first", this).attr("href");
		$("TD:has(> H3 > A), TD:not(:has(A))", this).click(function () {
			window.location.href = href;
		}).mouseover(function () {
			$(this).css("cursor", "pointer");
		});
		$(this).data("bg", $(this).css("backgroundColor"));
	}).hover(
		function () {$(this).stop().animate({backgroundColor: "#F0F8FF"}, 300);}, 
		function () {$(this).stop().animate({backgroundColor: $(this).data("bg")}, 300);}
	);
});
$.getFolder = function () {
	var items = $("SCRIPT");
	var re = /^(.*\/)javascript\//;
	for (var i = 0; i < items.length; i++) {
		if ((value = items[i].src.match(re)) != null) return value[1];
	}
	return "/";
};
function popUp(URL, target) {
	var newWin = window.open(URL, target, "");
	newWin.focus();
	return false;
}
// TINYMCE ######################################
function contentedFileManager(field, url, type, win) {
	var cmsUrl = tinyMCE.activeEditor.settings.file_browser_url
    if (cmsUrl.indexOf("?") < 0) cmsUrl = cmsUrl + "?type=" + type;
    else cmsUrl = cmsUrl + "&type=" + type;
	tinyMCE.activeEditor.windowManager.open({
        file : cmsUrl,
        title : 'CMS Image Browser',
        width : 550,
        height : 550,
        resizable : "yes",
        inline : "yes",
        close_previous : "no",
		scrollbars : "yes",
		popup_css : false
    }, {
        window : win,
        input : field,
		editor_id : tinyMCE.selectedInstance.editorId
    });
    return false;
}
function contentedFileSubmit(url) {
	var win = tinyMCEPopup.getWindowArg("window");
	win.document.getElementById(tinyMCEPopup.getWindowArg("input")).value = url;
	if (arguments[1] != null) {
		if (win.document.getElementById("alt")) win.document.getElementById("alt").value = arguments[1];
		else if (win.document.getElementById("title")) win.document.getElementById("title").value = arguments[1];
	}
	if (typeof(win.ImageDialog) != "undefined") {
		if (win.ImageDialog.getImageData) win.ImageDialog.getImageData();
		if (win.ImageDialog.showPreviewImage) win.ImageDialog.showPreviewImage(url);
	}
	tinyMCEPopup.close();
}