/* 
	used for home,buy,sell  index page .
	based on Jquery. By Evance
	2008.10.23
*/
$().ready(function() {
	//clear default tips words value in homeSearch.
	$("#headerGlobalMenu form").submit(function() {
		var simpleSearchValue = $("#searchWord").val();		
		if(simpleSearchValue == mainSrchTips) {
			$("#searchWord").val("");
		}
	});

	// recommendItemTab switcher
	$("#recommendItemTab li").each(function(index) {
		$(this).hover(function() {
			$("#recommendItemTab li").removeClass("thisOn");
			$(this).addClass("thisOn");
			$("#recommendItemBanner .itemWrapper").addClass("noDisplay");
			$("#recommendItemBanner .itemWrapper").eq(index).removeClass("noDisplay");
		},function() {
		})
	});

	//home magazine onfocus and onblur event.
	var myEmailValue = $("#myEmail").val();
	$("#myEmail").blur(function() {
		if($(this).val() == "") {
			$(this).val(myEmailValue);
			$(this).attr("class","inputBefore");
		}
	}).focus(function() {
		if($(this).val() == myEmailValue) {
			$(this).val("");
			$(this).attr("class","inputAfter")
		}
	});

	//home magazine  checkemail onsubmit
	$("#magazine_d").submit(function() {
		if (/^\w+[[\.-]?\w*]*@\w+([\.-]\w+)*(\.\w{2,3})+$/.test($("#myEmail").val())){
			$(this).submit();
		}else{
			alert($(".maga_email_error").text());
			return false;
		}
	});

	//home subscribe onfocus and onblur event.
	var myEmailValue2 = $("#myEmail2").val();
	$("#myEmail2").blur(function() {
		if($(this).val() == "") {
			$(this).val(myEmailValue2);
			$(this).attr("class","inputBefore");
		}
	}).focus(function() {
		if($(this).val() == myEmailValue2) {
			$(this).val("");
			$(this).attr("class","inputAfter")
		}
	});
	//home subscribe checkemail onsubmit
	$("#senduseremail").submit(function() {
		if (/^\w+[[\.-]?\w*]*@\w+([\.-]\w+)*(\.\w{2,3})+$/.test($("#myEmail2").val())){
			$(this).submit();
		}else{
			alert($(".sub_email_error").text());
			return false;
		}
	});

	//home ajax login
	$("#homeLoginForm input:image").click(function() {
		var params = $("#homeLoginForm").serialize() +'&timeStamp=' + new Date().getTime();		
		$("#loginRegistDiv").load($(".dictBaseUrl").text() + '/include/widget/userPanel.htm?' + params, {});
		return false;
	});

	//uesd for that if thumbnail loads error, replace thumbnail with original image.
	$(".homeThumbnail").error(function() {
			var tempImgSrc = $(this).attr("src"),  //get the thumbnail image url .
			oriImgSrc = tempImgSrc.substr(0,(tempImgSrc.length)-9); // get the original image url
			if(oriImgSrc) {
				$(this).attr("src",oriImgSrc) //set image url to original image url
			}
			else {
			}
	});
	
	// change simpleSearchForm's action url when change selectSearchType added by wb_dapeng.li 2009-04-10
	$("#simpleSearchForm .selectSearchType").change(function(){		
		if($("#simpleSearchForm .selectSearchType").val() == "bbs") {			
			$("#simpleSearchForm").attr("action", $("#headerGlobalMenu .clubSearchUrl").text());
		} else {
			$("#simpleSearchForm").attr("action", $("#headerGlobalMenu .indexSearchUrl").text());
		}
	});
	
});