//头部菜单弹出
function open(){
	ddmenuitem = $(this).find('.d-container').css('display', 'block');
	ddmenulink = $(this).find('a:eq(0)').addClass('over');
}

function close(){
	ddmenuitem.css('display', 'none');
	ddmenulink.removeClass('over');
}

$(document).ready(function(){
	$('.main-nav > li').bind('mouseover', open);
	$('.main-nav > li').bind('mouseout', close);
	
	$('.user-drop').bind('mouseover', open);
	$('.user-drop').bind('mouseout', close);
	
	//当鼠标hover到细则图片上面的时候，就可以变换图片（产品图片和spot的图片【后】）
	$('.prospotplate').hover(function(){
		//当鼠标移至上面的时候，当前的图片变成spot的图片
		$(this).find('.spot_image').css('display', 'block');
		//将下面的文字变成对应spot的文字
		$(this).find('.shown_text').css('display', 'none');
		$(this).find('.spot_text').css('display', 'block');
	},function(){
		//移开时变成之前的图片（产品的主图片的缩略图）
		$(this).find('.spot_image').css('display', 'none');
		//文字还原
		$(this).find('.spot_text').css('display', 'none');
		$(this).find('.shown_text').css('display', 'block');
	});	
	
	
	//**************************************************************以下为评论部分使用隐藏载入的评论部分
	$('#moveable_discussion_form').hide();
	
	$('#post_new_bottom').click(function(){
		//点击后按钮部分隐藏
		$('#post_new_bottom').hide();
		$('#moveable_discussion_form').show();
	});
	
	//点击取消按钮
	$('.post-cancel').click(function(){
		$('#post_new_bottom').show();
		$('#moveable_discussion_form').hide();
	});
	
	//有内容后就改变按钮样式，可以提交评论内容
	$('#comment_text_edit').keyup(function(){
		$('.form-btn-disabled .post-comment').removeAttr('disabled');
		$('.post-action span').removeClass();
		$('.post-action span').addClass('form-btn');
	});
	
	//点击发送按钮将评论内容及附加参数ajax到comment
	$('.post-comment').click(function(){
		var comment_action = $('#moveable_discussion_form input[name="comment[commentable_type]"]').val();
		var comment_id = $('#moveable_discussion_form input[name="comment[commentable_id]"]').val();
		var comment_userid = $('#moveable_discussion_form input[name="comment[user_id]"]').val();
		var comment_content = $('#comment_text_edit').val();
		//alert(comment_content);
		$.post('/ajax/comment.php', {comment_action:comment_action, comment_id:comment_id, comment_userid:comment_userid, comment_content:comment_content}, function(result){
			if(result == 'success'){
				location.reload();
			}
		});
	})
});


//starinfo.tpl用明星简介弹出全部详细简介功能
$(document).ready(function(){
	$('#whole_description').hide();
	$('#short_description a').click(function(){
		$('#short_description').hide();
		$('#whole_description').show('normal');
	});
});




//点击spot——tag按钮弹出窗口
$(document).ready(function() {
  $('.add-spot-tag span').click(function() {
	//$('.spot_tag').empty();
    $('.spot_tag').load('ajax/spot_tag.html');
    
    //全部tag变为虚线，并且不会再次变化为没有虚线
    $('.tag_marker_box img').attr('src', '/images/icons/spot_tag_active.png');
    
    //并且无论怎样移动鼠标，或者取消tag_box的显示，都是以虚线的方式显示，不会变成没有虚线的样子
	$('.photo-container img').hover(function(){
		$('.tag_marker_box img').attr('src', '/images/icons/spot_tag_active.png');
	},function(){
		$('.tag_marker_box img').attr('src', '/images/icons/spot_tag_active.png');
	});
  });
});
//点击取消按钮关闭spot_tag弹出窗口
function hideSpotTag(){
	$('.spot_tag').empty();
	//return false;
};


//当 auto_complete的内容加载完毕时，当ul里面的内容加载完成后执行的方法
function spotAutoResult(){	
	//当鼠标悬浮在li上面时将class的属性设定为select
	$('.auto_complete ul li').hover(function(){
		$(this).addClass('selected');
	},function(){
		$(this).removeClass();
	});
};





//点击newspot链接打开的newspot对话框
function newSpot(leftSpotId, leftSpotCid, leftSpotName, leftSpotCname){
	newAll();
	if(leftSpotId == null || leftSpotCid == null || leftSpotName == null || leftSpotCname == null){
		$('.tool-inner').load('ajax/newspot.php');
		curr=1;
	}else{
		$('.tool-inner').load('ajax/newspotleft.php', {leftSpotId:leftSpotId, leftSpotCid:leftSpotCid, leftSpotName:leftSpotName, leftSpotCname:leftSpotCname});
		curr=2;
	}
}

//点击newprofile链接打开newprofile顺序对话框
function newProfile(){
	newAll();
	
	$('.tool-inner').load('ajax/newprofile.html');
	
	//$('.step').hide();
	curr=1;
}

//实现背景灰色并且插入有效div
function newAll(){
	//实现在界面中间打开
	var top = $(window).height()/2;
	var left = $(window).width()/2;
	var scrollTop = $(document).scrollTop();
	var scrollLeft = $(document).scrollLeft();
	
	var showTop = top + scrollTop - 200;
	var showLeft = left + scrollLeft - 150;
	//alert(showTop);
	
	//实现全界面灰色半透明背景
	$('body').append('<div id="smokeout" style="background: none repeat scroll 0% 0% black; position: absolute; top: 0px; left: 0px; z-index: 10000; height: 2404px; width: 1583px; opacity: 0.7;"></div>')
		.append('<div id="tool-container" class="tool-container" style="position: absolute; z-index: 10002; top: '+showTop+'px; left: '+showLeft+'px;"></div>');
	
	$('#tool-container').append('<form id="dialog_form"></form>');
	$('#dialog_form').append('<div id="spot-tool-outer" class="tool-outer"></div>');
	$('#spot-tool-outer').append('<div class="tool-inner" style="height:auto;overflow:visible;"></div>');
}

//newprofile点击进入下一步
function nextStep(){
	if(curr != null){
		$('#tip'+curr.toString()).hide();
		curr=curr+1;
		$('#tip'+curr.toString()).show();
	}else{
		//$('#tip1').show();
		//curr=1;
	}
}
//newprofile点击后退一步
function backStep(){
	if(curr != null){
		$('#tip'+curr.toString()).hide();
		curr=curr-1;
		$('#tip'+curr.toString()).show();
	}
}
//newprofile 点击取消
function cancelProfile(){
	$('#tool-container').remove();
	$('#smokeout').remove();
}




//spot页面相关
//spot页面左上方hover变成白色边框，离开后变成灰色边框
$(document).ready(function(){
	$('.t75').hover(function(){
		$(this).css('background-position', '0 -84px');
	},function(){
		$(this).css('background-position', '0 0px');
	})
})


//添加spot的相片或weblink传入当前spot的id
function addSpotMedia(spotId, leftSpot, rightSpot){
	newAll();
	$('.tool-inner').load("ajax/addspotmedia.php", {spotId:spotId, leftSpot:leftSpot, rightSpot:rightSpot});
}
//添加spot相片
function addSpotPhoto(spotId, leftSpot, rightSpot){
	cancelProfile();
	newAll();
	//alert(leftSpot);
	$('.tool-inner').load('ajax/addspotphoto.php', {spotId:spotId, leftSpot:leftSpot, rightSpot:rightSpot});
}





//ajax上传
function ajaxFileUpload(){
	$.ajaxFileUpload({
		url:'ajax/upload_picture.php',
		fileElementId:'upload_file_display',
	});
};


