// JavaScript Document
var countAdd = 0;
$(function(){

	//homepage slide
	
	jQuery('.hp_slide').each(function(){
		var $hp_slide = jQuery(this);
		var $pic_box = $hp_slide.find('.pic_box');
		var $holder = $hp_slide.find('.holder');
		var $items = $holder.find('ul li');
		var len = $items.size();	
		var speed = 2000;
		var interval_time = 5000;
		var stop_flag=false;
		var $last_show_pic = null;
		var cur_item_index = 0;
		
		$items.each(function(idx){
		   var $this_item = jQuery(this);
			 var img_src = $this_item.find('a').attr('rel');
			 
			 //reg click 
			 $this_item.bind('click',function(){
				  if($last_show_pic){
						$last_show_pic.fadeOut(speed,function(){
							jQuery(this).remove();
						});
					};
					
					$last_show_pic = jQuery('<div><img src="'+img_src+'" alt="" /></div>').css({
						'position':'absolute',
						'left':0,
						'top':0,
						'display':'none'
					}).appendTo($pic_box).fadeIn(speed);
			    
					cur_item_index = idx;
							
					$items.removeClass('active');
					$this_item.addClass('active');
			 });//end reg click		  
		  });
			

			
			
		//init

			$pic_box.empty();
			$items.eq(0).trigger('click');
			$hp_slide.hover(function(){
				stop_flag = true;
			},function(){
				stop_flag = false;
			});
		window.setInterval(function(){
			if ( !stop_flag ){
				var next_item_idx = cur_item_index + 1;
				next_item_idx = ( next_item_idx >= len ) ? 0 : next_item_idx;
				$items.eq(next_item_idx).click();
			}
		},interval_time);
	
		
	});//end hp_slide
	

	//homepage mod_hp_links
	$('.mod_hp_links .cell').hover(
		function(){
			$(this).children('div:first').addClass('active');
			},
		function(){
			$(this).children('div:first').removeClass('active');
			}
	);

	

	
	
	//mod_service_list  toglle
	$('.mod_service_list .service_cell .bd .detail').hide();
	$('.mod_service_list .service_cell .hd span').click(function(){
		$(this).parent().siblings('.bd').find('.detail').toggle();
		$(this).toggleClass('on');
	});
	  
		
	//order form
	/*

	$('.mod_order_form .repeat_template .btn_reduce').hide();	
	$('.mod_order_form .holder_btn .btn_add').click(function(){		  	
		  var $copy=$('.repeat_template').clone(true);
		  var $repeat_area=$(this).parent().parent();
			
			countAdd++; // add by eric
			
			$copy.removeClass('repeat_template').find('.btn_reduce').show();
		  $repeat_area.after($copy);
			
			$copy.css('display','inherit'); // add by eric
			$copy.addClass('new_add_tmp'); // add by eric
			//jQuery('.new_add .row .project_option').attr('id', 'option_items' + countAdd); // add by eric
			jQuery('.new_add_tmp .row .project_option').addClass('options_'+countAdd); // add by eric
			$copy.removeClass('new_add_tmp'); // add by eric
	});
	
	$('.mod_order_form .holder_btn .btn_reduce').click(function(){	
	   $(this).parent().parent().remove();
		 //countAdd--; // add by eric
	})
*/	

	//order form
	jQuery('.mod_order_form').each(function(){
	   var $root = jQuery(this);
		 var $original_tpl = $root.find('.repeat_template');
		 var $repeat_area = $root.find('.repeat_area');
		 
		 
		 
		 $original_tpl.find('.btn_add').bind('click',function(){
			  var $copy_tpl = $original_tpl.clone(true);
				$copy_tpl.removeClass('repeat_template').addClass('repeat_area');
			  $repeat_area.after($copy_tpl);
			  $copy_tpl.show();
			  countAdd++; // add by eric
				$copy_tpl.find('.row .project_option').addClass('options_'+countAdd); // add by eric	
		 });
		 
		 $original_tpl.find('.holder_btn .btn_reduce').bind('click',function(){
			 jQuery(this).parent().parent().remove(); 
		 });
		 
		 $root.find('.repeat_area .holder_btn .btn_add').click(function(){			 
			  var $copy_tpl = $original_tpl.clone(true);
				$copy_tpl.removeClass('repeat_template').addClass('repeat_area');
			  $repeat_area.after($copy_tpl);
			  $copy_tpl.show();
			  countAdd++; // add by eric
				$copy_tpl.find('.row .project_option').addClass('options_'+countAdd); // add by eric	
		 });	
  });//END jQuery('.mod_order_form').each()
	
	
//START homepage sns share

function getParamsOfShareWindow(width, height) {
	return ['toolbar=0,status=0,resizable=1,width=' + width + ',height=' + height + ',left=',(screen.width-width)/2,',top=',(screen.height-height)/2].join('');
}
 
function bindShareList() {
	var link = encodeURIComponent(document.location); // 文章链接
	var title = encodeURIComponent(document.title.substring(0,76)); // 文章标题
	var source = encodeURIComponent('网站名称'); // 网站名称
	var windowName = 'share'; // 子窗口别称
	var site = 'http://www.example.com/'; // 网站链接
 
	jQuery('.icon_s_kaixin').click(function() {
		var url = 'http://www.kaixin001.com/repaste/share.php?rurl=' + link + '&rcontent=' + link + '&rtitle=' + title;
		var params = getParamsOfShareWindow(540, 342);
		window.open(url, windowName, params);
	});
 
	jQuery('.icon_s_renren').click(function() {
		var url = 'http://share.renren.com/share/buttonshare?link=' + link + '&title=' + title;
		var params = getParamsOfShareWindow(626, 436);
		window.open(url, windowName, params);
	});
 
	jQuery('#douban-share').click(function() {
		var url = 'http://www.douban.com/recommend/?url=' + link + '&title=' + title;
		var params = getParamsOfShareWindow(450, 350);
		window.open(url, windowName, params);
	});
 
	jQuery('.icon_s_weibo').click(function() {
		var url = 'http://v.t.sina.com.cn/share/share.php?url=' + link + '&title=' + title;
		var params = getParamsOfShareWindow(607, 523);
		window.open(url, windowName, params);
	});
 
	jQuery('.icon_qzone').click(function() {
		var url = 'http://v.t.qq.com/share/share.php?title=' + title + '&url=' + link + '&site=' + site;
		var params = getParamsOfShareWindow(634, 668);
		window.open(url, windowName, params);
	});
};
 
bindShareList();	
//END	homepage sns share
			
});




//validation
jQuery(function(){


	
	/* 验证 */
	jQuery(function(){
		jQuery('.js_mmjs_validation').MMJS_validation().each(function(){
			jQuery(this).submit( function(){
				if ( !jQuery(this).MMJS_validate() ){
					return false;
				}else{
					return true;
				}
			} );
		});
	});




	
});






