jQuery(document).ready(function($){
	$("#intro").css({"height":0,"overflow":"hidden"});
	$("#nv1, #nv2, #nv3, #nv4, #nv5, #nv6, #nv7").unbind("hover").hover(
		function() {
			$(".flyout",this).show();
			$("a:first",this).addClass('over');				
		},
		function() {
			$(".flyout",this).hide();
			$("a:first",this).removeClass('over');		
		}
	);

	$('#siblings a').filter(function() {
	   return filterPath(this.pathname) == filterPath(location.pathname);
	}).addClass('selected');

	/* users control */
	$("a.actions").click(function(){
		$(".menu").removeClass("show").addClass("hide");
		$(this).next().removeClass("hide").addClass("show");
		return false;
	})
	$("a.close").click(function(){
		$(this).parent().removeClass("show").addClass("hide");
		return false;
	});
	$(".editable .edit").click(function(){
		showPopup($(this).attr("href"), 'editor', 850, 640, 0, 0, 0);
		return false;
	});

	$("a").linkTracker();
	pngFixer("div#graphic-panel");
});
var today = new Date();
var expires = new Date(today.getTime() + (365 * 86400000));

function writeQueryFlashCode() {
	var so = new SWFObject("/management/KiaActivityPlanner.swf", "query", "910px", "700px", "8");
	so.addParam("wmode","transparent");
	so.write("query");
}
function pngFixer(ele) {
	//Iterate over the current set of matched elements 
	var ie55 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 5.5") != -1);
	var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);
	$(ele).each(function() {
		if (ie55 || ie6) {
			// fix css background pngs
			var bgIMG = jQuery(this).css('background-image');
			if (bgIMG.indexOf(".png") != -1) {
				var iebg = bgIMG.split('url("')[1].split('")')[0];
				jQuery(this).css('background-image', 'none');
				jQuery(this).css('z-index', '3');
				jQuery(this).get(0).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + iebg + "',sizingMethod='scale')";
			}
		}
	});
}
function showPopupSmall(url, name) {
	showPopup(url, name, 300, 240, 1, 1, 1, 'default');
}
function pickDate(formControlName, theValue) {
	prefix = "";
	if ((formControlName != "insertionDate") && (formControlName != "copyDeadline")) {
		prefix = "ctl01_";
	}
	theFormInputBox = window.opener.document.getElementById(prefix + formControlName);
	theFormInputBox.value = theValue;
	window.close();
}
function newReplace(t_str, t_x, t_y) {
	var t_ret = "",
	t_str = String(t_str), 
	t_xI;
	while((t_xI = t_str.indexOf(t_x)) != -1) {
		t_ret += t_str.substring(0, t_xI) + t_y;
		t_str = t_str.substring(t_xI + t_x.length);
	}
	return t_ret+t_str;
}
function changeStyle(element, strClass) {
	element.className = strClass;
}
function doRowMouseOver(rowIdentifier) {
	changeStyle(rowIdentifier, "rowMouseOver");
}
function doRowMouseOut(rowIdentifier) {
	changeStyle(rowIdentifier, "rowMouseOut");
}
function filterPath(pathString) {
   return pathString.replace(/^\//,'').replace(/\/(index\.\w{3,4})?$/,'');
}
function showPopup(url, name, width, height, scroll, resizable, statusbar, screenpos) {
	var Xwin = width;
	var Ywin = height;
	var Xsize = screen.availWidth;
	var Ysize = screen.availHeight;
	var Xpos = 0;
	var Ypos = 0;
	switch(screenpos) {
		case "topleft":
			Xpos = 0;
			Ypos = 0;
			break;
		case "topright":
			Xpos = Xsize - width;
			Ypos = 0;
			break;
		case "bottomleft":
			Xpos = 0;
			Ypos = Ysize - height;
			break;
		case "bottomright":
			Xpos = Xsize - width;
			Ypos = Ysize - height;
			break;
		default:
			Xpos = (Xsize - width) / 2;
			Ypos = (Ysize - height) / 2;
			break;
	}
	var popwin;
	var opts = "status=" + statusbar + ",resizable=" + resizable + ",scrollbars=" + scroll + ",height=" + Ywin + ",width=" + Xwin + ",left=" + Xpos + ",top=" + Ypos;
	popwin = window.open(url, name, opts);
	popwin.focus();
}
function showConfirm() {
	if (confirm("Are you sure?")) return true;
	else return false;
}
function getCookie(name) {
	var start = document.cookie.indexOf(name+"=");
	var len = start+name.length+1;
	if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
	if (start == -1) return null;
	var end = document.cookie.indexOf(";",len);
	if (end == -1) end = document.cookie.length;
	return unescape(document.cookie.substring(len,end));
}
function setCookie(name, value, expires, path, domain, secure) {
	path = "/";
	document.cookie = name + "=" +escape(value) +
	((expires) ? ";expires=" + expires.toGMTString() : "") +
	((path) ? ";path=" + path : "") + 
	((domain) ? ";domain=" + domain : "") +
	((secure) ? ";secure" : "");
}
function pickRandomNumber(num) {
	return Math.round(num*Math.random());
}
function arrayShuffle(u_array, n) {
	var i, j, k;
	var temp;
	for (i = 0; i < n; i++)
	for (j = 0; j < u_array.length; j++) {
		k = Math.floor(Math.random() * u_array.length);
		temp = u_array[j];
		u_array[j] = u_array[k];
		u_array[k] = temp;
	}
}