//   ---------------------------------------------------------------------------
//   Copyright (C) Hahoo Network Technology Co.,Ltd
//	URL:http://www.hahoo.cn or http://www.hahoo.com.cn
//   ---------------------------------------------------------------------------


$(function(){
	//reset form
	$.fn.formreset = function () {
	  $(this).each (function() { this.reset(); });
	}

	$.fn.scrollToTop=function(){
		
		$(this).hide().removeAttr("href");
		
		if($(window).scrollTop()!="0"){
			$(this).fadeIn("slow")
		}
		var scrollDiv=$(this);
		$(scrollDiv).text("");
		var mode = document.documentMode || 0;
		var ie6 = $.browser.msie && /MSIE 6.0/.test(navigator.userAgent) && !mode;
		var d = document.documentElement, b = document.body;
		if(!ie6){
			$(scrollDiv).css({"position":"fixed","bottom":"48%","right":"2%"});
		}else{
			$(scrollDiv).css({"position":"absolute","top":"50%","right":"2%"});
		}
		
		$(window).scroll(function(){
								  
			if($(window).scrollTop()=="0"){
				$(scrollDiv).fadeOut("slow")
			}else{
				$(scrollDiv).fadeIn("slow")
			}
			if(ie6){
				$(scrollDiv).css({top:(b.scrollTop || d.scrollTop)+300});
			}
		});
		
		$(this).click(function(){
			$("html, body").animate({scrollTop:0},"slow");
		});
	
	}
			
});

$(function(){

	$("#toTop").scrollToTop();

	$('.boxgrid.captionfull').hover(function(){
		$(".cover", this).stop().animate({top:'60px'},{queue:false,duration:300});
	}, function() {
		$(".cover", this).stop().animate({top:'140px'},{queue:false,duration:300});
	});

	$(".ajax").colorbox();

	/*$('ul#portfolio').innerfade({
		speed: 1000,
		timeout: 5000,
		type: 'sequence',
		containerheight: '424px'
	});*/

	try {
	document.execCommand("BackgroundImageCache", false, true);
	} catch(err) {}

	
	$("#feedbackForm").submit(function(){
		
		if($.trim($("input[name='name']").val())==""){alert("请输入联系人!");$("input[name='name']").focus();return false;}
		if($.trim($("input[name='phone']").val())==""){alert("请输入联系电话!");$("input[name='phone']").focus();return false;}
		if($.trim($("input[name='vcode']").val())==""){alert("请输入验证码!");$("input[name='vcode']").focus();return false;}


		$(".submit").attr("disabled","disabled");
		$("#loading").html('<img src="images/loading.gif" align="absmiddle" /> 正在提交...</div>');
		var dataString = 'name=' + escape(FixJqText($("input[name='name']").val()));
		dataString += '&phone=' + escape(FixJqText($("input[name='phone']").val()));
		dataString += '&email=' + escape(FixJqText($("input[name='email']").val()));
		dataString += '&vcode=' + escape(FixJqText($("input[name='vcode']").val()));
		dataString += '&content=' + escape(FixJqText($("[name='content']").val()));

		var obj=$(this);
		$.ajax({
			type:"POST",
			url:"ajax/feedback.asp",
			data:dataString,
			error:function(){alert("遇到错误,请刷新页面重新尝试!");$("#loading").html('');},
			success:function(data){
				if(data!=="ok"){
					alert(data);
					$('#verifycode').click();
					$("#loading").html('');
					$(".submit").removeAttr("disabled");
				}else{
					obj.formreset();
					$("#loading").html('');
					alert("发送成功，我们会尽快与您联系!");
					$(".submit").removeAttr("disabled");
				}
			}
		});

		
		return false;

	});


});

$(document).ready(function(){
	$(".scroll").click(function(event){
		//prevent the default action for the click event
		event.preventDefault();
		
		//get the full url - like mysitecom/index.htm#home
		var full_url = this.href;
		
		//split the url by # and get the anchor target name - home in mysitecom/index.htm#home
		var parts = full_url.split("#");
		var trgt = parts[1];
		
		//get the top offset of the target anchor
		var target_offset = $("#"+trgt).offset();
		var target_top = target_offset.top;
		
		//goto that anchor by setting the body scroll top to anchor top
		$('html, body').animate({scrollTop:target_top+30}, 500);
	});
});

function FixJqText(str) {
    //str=encodeURIComponent(str);//先编码
    var tempstr = str.replace(/\+/g, "＋");
    //tempstr = tempstr.replace(/\&/g, "&amp;");
    return tempstr;
}
