//common
function getRootPath(){
	var strFullPath=window.document.location.href;
	var strPath=window.document.location.pathname;
	var pos=strFullPath.indexOf(strPath);
	var prePath=strFullPath.substring(0,pos);
	var postPath=strPath.substring(0,strPath.substr(1).indexOf('/')+1);
	return(prePath+postPath);
}

function getBasePath(){
	var strFullPath=window.document.location.href;
	var strPath=window.document.location.pathname;
	var pos=strFullPath.indexOf(strPath);
	var prePath=strFullPath.substring(0,pos);
	return prePath;
}

//play mp3 sound begin
function getFlashObject(movieName)
{
	if (window.document[movieName])
	{
		return window.document[movieName];
	}
	if (navigator.appName.indexOf("Microsoft Internet")==-1)
	{
		if (document.embeds && document.embeds[movieName])
			return document.embeds[movieName];
	}
	else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
	{
		return document.getElementById(movieName);
	}
}

function asplay(c){
	var asound = getFlashObject("asound");
	if(asound){
		asound.SetVariable("f",c);
		asound.GotoFrame(1);
	}
}

function asstop(){
	var asound = getFlashObject("asound");
	if(asound){
		asound.GotoFrame(3);
	}
}

function playSound(s){
	s = getRootPath() + '/sound/' + s + '.mp3'
	asplay(s);
}
//play mp3 sound begin

$(function(){
	$('#form_search_char').submit(function(e){
		window.location = getRootPath() + '/' + $('#MyDicSimplifiedChar').val();
		return false;
	});
	
	//将链接转换成为可发音的链接
	$('.sound').click(function(e){
		asplay(getBasePath() + $(this).attr('href'));
		e.preventDefault();
	});
	
	//==字典显示界面的浮动框
	$('.charDefinition .sound').hover(function(e){
		$(this).next('.detailWrap').show();
	});
	
	var needHide;
	$('.charDefinition .sound').bind('mouseleave',function(e){
		needHide = true;
		var detailWrap = $(this).next('.detailWrap');
		setTimeout(function(){
			if(needHide)detailWrap.hide();
		},300);
	});
	
	$('.charDefinition .detailWrap').hover(function(){
		needHide = false;
	});
	
	$('.charDefinition .detailWrap').bind('mouseleave',function(e){
			$(this).hide();
	});
	//==
	
	//留言板表单验证
	if($('#feedback'))
	{
		$('#FeedbackIndexForm').submit(function(){
			$(this).find('input').removeClass('inputError');
			if($.trim($(this).find('#FeedbackName').val()) == '')
			{
				alert( $('#FeedbackNameMessage').val());
				$(this).find('#FeedbackName').addClass('inputError').focus();
				return false;
			}
			if($.trim($(this).find('#FeedbackContent').val()) == '')
			{
				alert($('#FeedbackContentMessage').val());
				$(this).find('#FeedbackContent').addClass('inputError').focus();
				return false;
			}
			
		});
	}
});

//预载图片的jQuery插件
(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)
