jQuery.preloadImages = function() {
	$('.btn_over').each(function() {
		jQuery("<img>").attr("src", replaceFilename($(this).attr('src'), ".", "_over."));
	});
}

$(document).ready(function() {
	$('.btn_over').mouseover(function(){
		$(this).attr('src', replaceFilename($(this).attr('src'), ".", "_over."));
	}).mouseout(function(){
		$(this).attr('src', replaceFilename($(this).attr('src'), "_over.", "."));
	});
	$('#txtSearchText').focus(function() {
		$(this).val("");
	});
	$('#txtSearchText').blur(function() {
		if ($(this).val()=="") {
			$(this).val("Search by Keyword");
		}
	});
	$('mainmenu ul.sub').each(function() {
		$(this).css("top",$(this).parent().offset().top+$(this).parent().height());
		$(this).css("left",$(this).parent().offset().left);

		var currSub = $(this);

		$(this).parent().hover(function(){
			currSub.show();
		}, function() {
			currSub.hide();
		});
	});

/*
	$("object, embed").each(function() {
		this.outerHTML = this.outerHTML;
	});
*/
	$.preloadImages();
})

function replaceFilename(url, fromstr, tostr){
	var filestart = url.lastIndexOf("/");
	var newUrl = 
		url.substring(0, filestart)
		+ url.substring(filestart)
		.replace(fromstr, tostr);
	return newUrl
}

function resizeImage(which, maxWidth, maxHeight) {
	var elem = which;
	if (elem == undefined || elem == null) return false;
	if (elem.width > elem.height) {
		if (elem.width > maxWidth) elem.width = maxWidth;
	} else {
		if (elem.height > maxHeight) elem.height = maxHeight;
	}
}

function Menu() {
	this.contentId = 0;
	this.text = "";
	this.alt = "";
	this.href = "";
	this.target = "";
	this.childs = new Array();
}

Menu.prototype = {
	addChild : function(m) {
		this.childs[this.childs.length] = m;
	}
}

function generateMenu(rootMenu) {
	for (var i=0; i<rootMenu.childs.length; i++) {
		var m = rootMenu.childs[i];
		document.writeln('<ul>');
		if (m.isCurrentSection) {
			document.writeln('<li><img src="'+m.img.replace(".","_on.")+'" alt="'+m.alt+'" title="'+m.alt+'" ></li>');
		} else {
			document.writeln('<li><a href="'+m.href+'"><img src="'+m.img+'" class="btn_over" border="0" alt="'+m.alt+'" title="'+m.alt+'"></a></li>');
		}
		if (m.childs.length>0) {
			generateMenu(m);
		}
		document.writeln('</ul>');
	}
}

function getdate() {
	var date = new Date();
	var dateString;
	var timeString;

	dateString = date.getDate()+" ";
	switch (date.getMonth()) {
		case 0: dateString+="January";break;
		case 1: dateString+="February";break;
		case 2: dateString+="March";break;
		case 3: dateString+="April";break;
		case 4: dateString+="May";break;
		case 5: dateString+="June";break;
		case 6: dateString+="July";break;
		case 7: dateString+="August";break;
		case 8: dateString+="September";break;
		case 9: dateString+="October";break;
		case 10: dateString+="November";break;
		case 11: dateString+="December";break;
	}
	dateString += ", "+date.getFullYear();

	if (document.getElementById('dateString')) {
		document.getElementById('dateString').innerText = dateString;
	}

	if (date.getHours()<=12) {
		timeString = date.getHours()+":";
	} else {
		timeString = (date.getHours()-12)+":";
	}
	if (date.getMinutes()<10) {
		timeString+="0"+date.getMinutes();
	} else {
		timeString+=date.getMinutes();
	}
	if (date.getHours()<10) {
		timeString+="am";
	} else {
		timeString+="pm";
	}

	if (document.getElementById('timeString')) {
		document.getElementById('timeString').innerText = timeString;
	}
}

function generateFlashTitle(){
	var title = "";
	var html = "";
	if (zmsBreadcrumbParentList.length>1) {
		var contentID = zmsBreadcrumbParentList[1];
		var dataFileID = Math.floor(contentID / 100);
		if (zmsBreadcrumbData[dataFileID]) {
			var node = zmsBreadcrumbData[dataFileID][contentID];
			title = node.name;
		}
	}
	title = title.replace(/\"/g,"&quot;");
	html = '<object align="middle" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" height="140" id="inside_en" width="235">';
	html += '<param name="FlashVars" value="section='+title+'" />';
	html += '<param name="Movie" value="/filemanager/template/en/images/title.swf" />';
	html += '<param name="Src" value="/filemanager/template/en/images/title.swf" />';
	html += '<param name="Quality" value="High" />';
	html += '<param name="AllowScriptAccess" value="sameDomain" />';
	html += '<param name="BGColor" value="#FFFFFF" />';
	html += '</object>';

	document.write(html);
}
