//兑换礼品列表
function exchange_list(){
	this.list = $('.gift_list01');
	this.show_btn = $('.basket');
	this.hide_btn = $('.gift_list01 .close');
}

exchange_list.prototype = {
	
	init:function(){
		var that = this;
		this.show_btn.click(function(){
			//that.show();					 
		});
		this.hide_btn.click(function(){
			//that.hide();							 
		});
	},
	
	hide:function(){
		this.list.slideUp(500);
	},
	
	show:function(){
		this.list.slideDown(500);
	}
}

//兑换产品列表
function recommend(){
	this.pic_list = $('.integral_right .li_pic');
	this.con_list = $('.integral_right .li_content');
	this.current = 0;
}

recommend.prototype = {
	
	init:function(){
		var that = this;
		this.pic_list.each(function(i){
			$(this).hover(function(){
				if(that.current!=i){
					that.show_con(i);
					if(that.current>=0){
						that.hide_con(that.current);
					}
				}
				that.current = i;
			},function(){});							
		});
	},
	
	show_con:function(i){
		$(this.con_list[i]).show(800);
	},
	
	hide_con:function(i){
		$(this.con_list[i]).hide(800);
	}
	
}



//我的收藏页面
function favorite(){
	this.tab = $('.favorite .list table');
	this.list = $(this.tab).find('td');
	this.width = 192;
	this.len = $('.favorite .list').find('table td').length-5;
	this.current = 0;
}

favorite.prototype = {
	
	init:function(){
		var that = this;
		this.get_width();
		$('.favorite .left_click').click(function(){
			that.current = that.current + 1;
			//alert(that.current);
			if(that.current > that.len)
				that.current = 0;
			that.left(that.current);
		});
		$('.favorite .right_click').click(function(){
			that.current = that.current - 1;
			if(that.current < 0)
				that.current = that.len;				
			that.left(that.current);
		});
	},
	
	get_width:function(){
		width = 192;
		this.tab.width(width*this.list.length);
	},
	
	left:function(i){
		$('.favorite .list').find('table').animate({left:(-this.width*i)+'px'},'slow');
	},
	
	right:function(i){
		$('.favorite .list').find('table').animate({left:this.width*i+'px'},'slow');
	}
}

//二级菜单
function second(){
	this.list = $('.menu li');
}

second.prototype = {
	init:function(){
		var that = this;
		this.list.each(function(i){
			$(this).hover(function(){
				that.show_div(i);
			},function(){
				that.hide_div(i);	
			});						
		});
	},
	
	show_div:function(i){
		$(this.list[i]).find('div').show();
	},
	
	hide_div:function(i){
		$(this.list[i]).find('div').hide();
	}
}

//点击弹出信息框
function pop_form(){
	this.check = $(".order_infor input:radio");
}

pop_form.prototype = {
	
	init:function(){
		var that = this;
		this.check.each(function(i){
			$(this).click(function(){
				if(i == that.check.length-1){
					that.show();
				}else{
					that.hide();
				}
			});					 
		});
	},
	
	show:function(){
		$('.order_infor .order_person').find('div').show();
	},
	
	hide:function(){
		$('.order_infor .order_person').find('div').hide();
	}
}

//提交信息页面的高度的判断
function page_height(){
	var current_height = $('.order_infor').height();
	var box_height = $('.order_infor .box').height();
	var box = 160;
	//if(box_height > box){
		$('.order_infor').height(current_height+box_height);
	//}
	//alert(current_height+"'"+box_height);
	
}

//杂志下载
function tween(){
	var list = $('.upload_list li');
	var download = $('.upload_list .download');
	list.each(function(i){
		$(list[i]).hover(function(){
			$(download[i]).animate({'left':'0px'},800);		  
		},function(){
			$(download[i]).animate({'left':'-152px'},800);
		});				   
	});
}

//svip 页面 左侧的线条高度判断
function checkHeight(){
	var right_height = $('.svip_right').height();
	var li_height = $('.svip_left li:first').height();
	var li_len = $('.svip_left li').length - 1;
	var repeat_height =li_len - 1 ;//重复的线条
	var li_last_height = $('.svip_left .space'); //最后一个li 的高度取值
	li_last_height.height(right_height - li_height*li_len - repeat_height);
}

//svip 滑动门
function sliderdoor(){
	this.element = $('.svip_left li');
	this.len = this.element.length;
	this.content = $('.svip_right .svip_content')
	this.current = 0;
	this.repeat_height =this.len - 2 ;//重复的线条
	this.li_height = $('.svip_left li:first').height();
	this.li_last = $('.svip_left .space');
}
sliderdoor.prototype = {
	init:function(){
		var that = this;
		this.init_height();
		this.element.each(function(i){
			$(this).click(function(){
				if(i != that.len-1){
					that.show_back_content(i);
					if(i != that.current){
						that.hide_back_content(that.current);
					}
					that.current = i;
				}
			},function(){});						   
		});
		
	},
	
	show_back_content:function(i){
		$(this.element[i]).removeClass('li_back');
		$(this.content[i]).show();
		this.li_last.height($('.svip_right').height()-this.li_height*(this.len-1)-this.repeat_height);
		//$('.svip').height($('.svip_right').height()+50);
	},
	
	hide_back_content:function(i){
		$(this.element[i]).addClass('li_back');	
		$(this.content[i]).hide();
		this.li_last.height($('.svip_right').height()-this.li_height*(this.len-1)-this.repeat_height);
		$('.svip').height($('.svip_right').height()+258);
	},
	
	init_height:function(){
		this.li_last.height($('.svip_right').height()-this.li_height*(this.len-1)-this.repeat_height);
		$('.svip').height($('.svip_right').height()+258);
	}
}

//左右两边的高度比较
function lr_height(){
	var left_height = $('.middle_left').height();
	var right_height = $('.middle_right').height();
	if(left_height > right_height){
		$('.middle_right').height(left_height);
	}else{
		$('.middle_right').addClass('padding');	
	}
}

//密码修改
function modify_pw(){
	this.list_li = $('.password li');
	this.current = 1;
}
modify_pw.prototype = {
	init:function(){
		var that = this;
		this.list_li.each(function(i){
			$(this).find('input').focus(function(){
				if(i != that.list_li.length-1){
					that.add_back(i);
					if(that.current != i){
						that.remove_back(that.current)	
					}
					that.current = i;
				}
			}).blur(function(){	}); 
		});
	},
	
	add_back:function(i){
		$(this.list_li[i]).addClass('li_box');
		$(this.list_li[i]).find('span').show();
		
	},
	
	remove_back:function(i){
		$(this.list_li[i]).removeClass('li_box');
		$(this.list_li[i]).find('span:not(.span_error)').hide();
	}
}

//收藏夹 全选
function selectAll(){
	this.checkbox_list = $(".favorite_list input:[name='check']");
	this.select_all = $('#select_all');
	this.delete_all = $('#delete_all');
	this.add_all = $('#add_all');
	this.del_all = $('#del_all');
	this.sel_btn = $(".favorite_list input:[name='buy']");
}
selectAll.prototype = {
	init:function(){
		var that = this;
		this.select_all.click(function(){
			if(that.select_all.attr('checked')==true) {
				that.checkbox_sel();
				that.delete_box_sel();
			}else{
				that.checkbox_cancel();
				that.delete_box_cancel();
			}
		});
		
		this.delete_all.click(function(){
			if(that.delete_all.attr('checked')==true) {
				that.checkbox_sel();
				that.select_box_sel();
			}else{
				that.checkbox_cancel();
				that.select_box_cancel();
			}
		});
		
		this.checkbox_list.each(function(i){
			$(this).click(function(){
				if($(that.checkbox_list[i]).attr('checked')!=true){
					that.select_all.attr('checked','');
					that.delete_all.attr('checked','');
				}
			});					
		});

		this.add_all.click(function(){
			that.get_id();
		});
		
		this.del_all.click(function(){
			that.get_id();	
		});
		
		this.sel_btn.each(function(i){
			$(this).click(function(){
				//////alert($(that.checkbox_list[i]).attr('value'));
			});
		});
	},
	
	checkbox_sel:function(){
		this.checkbox_list.attr('checked','true');
	},
	
	checkbox_cancel:function(){
		this.checkbox_list.attr('checked','');
	},
	
	delete_box_sel:function(){
		this.delete_all.attr('checked','true');
	},
	
	delete_box_cancel:function(){
		this.delete_all.attr('checked','');	
	},
	
	select_box_sel:function(){
		this.select_all.attr('checked','true');	
	},
	
	select_box_cancel:function(){
		this.select_all.attr('checked','');	
	},
	
	get_id:function(){
		var check_list = $(".favorite_list input:checked");
		var select_id = new Array();
		var len = check_list.length;
		for(var i=0;i<len;i++){
			select_id[i] = $(check_list[i]).attr('value');	
		}
	}
}

//弹出窗口
function getPosition(){
	var tag_id = $('.pop_win');
	var del_list = $('.exchange_list .delete');
	var tag_width = tag_id.width();
	var tag_height = tag_id.height();
	var total_height = document.documentElement.clientHeight;
	var total_width = document.documentElement.scrollWidth;
	var left = total_width/2 - tag_width/2;
	var top = total_height/2 - tag_height/2;
	$('.all_win').height(document.body.scrollHeight);
	tag_id.css({'left':left,'top':top});
	$(window).scroll(function(){
		tag_id.css({'top':$(window).scrollTop()+top});						  
	});
	
	$('.clear_list').click(function(){
		$('.con').html('确定要删除所有宝贝吗？');
		tag_id.show();
		$('.all_win').show();		 
	});
	
	del_list.each(function(i){
		$(del_list[i]).click(function(){
			$('.con').html('确认要删除该宝贝吗？');
			tag_id.show();
			$('.all_win').show();		 
		});		  
	});
	
	$('.close span').click(function(){
		tag_id.hide();
		$('.all_win').hide();
	});	
	/*$('.all_win').click(function(){
		tag_id.hide();
		$('.all_win').hide();						 
	});*/
	$('.btn_cancel').click(function(){
		tag_id.hide();
		$('.all_win').hide();						
	});
}

//加入兑换车
function addbike(){
	var add_id = $('.add_win');
	var add_list = $('.list button');
	var total_height = document.documentElement.clientHeight;
	var total_width = document.documentElement.scrollWidth;
	var add_width = add_id.width();
	var add_height = add_id.height();
	var left = total_width/2 - add_width/2;
	var top = total_height/2 - add_height/2;
	$('.all_win').height(document.body.scrollHeight);
	add_id.css({'left':left,'top':top});
	$(window).scroll(function(){
		add_id.css({'top':$(window).scrollTop()+top});						  
	});
	add_list.each(function(i){
		$(add_list[i]).click(function(){
			add_id.show();
			$('.all_win').show();
			setTimeout(function(){
				add_id.hide();
			$('.all_win').hide();			
			},2000);
		});					   
	});
}


//首页收藏效果
function collect(){
	var collect_id = $('.collect');
	//var collect_list = $('#home_list .a_collect');
	var total_height = document.documentElement.clientHeight;
	var total_width = document.documentElement.scrollWidth;
	var collect_width = collect_id.width();
	var collect_height = collect_id.height();
	var left = total_width/2 - collect_width/2;
	var top = total_height/2 - collect_height/2;
	
	collect_id.css({'left':left,'top':top});
	$(window).scroll(function(){
		collect_id.css({'top':$(window).scrollTop()+top});						  
	});
	
	$('.btn_confirm').click(function(){
		$(".pop_win").hide();
		$('.all_win').hide();
	});
	$('.close span').click(function(){
		collect_id.hide();
		$('.all_win').hide();
}	);
	/*collect_list.each(function(i){
		$(collect_list[i]).click(function(){
			collect_id.show();
			$('.all_win').show();
		});						   
	});*/
}

function btn_change(){
	var btn_list01 = $('#home_list .a_collect');
	var btn_list02 = $('#home_list .a_exchange');
	
	btn_list01.each(function(i){
		$(btn_list01[i]).hover(function(){
			$(btn_list01[i]).addClass('a_collect01');
			//$(btn_list01[i]).removeClass('a_collect');
		},function(){
			//$(btn_list01[i]).addClass('a_collect');
			$(btn_list01[i]).removeClass('a_collect01');
		});						 
	});
	btn_list02.each(function(i){
		$(btn_list02[i]).hover(function(){
			$(btn_list02[i]).addClass('a_exchange01');
			//$(btn_list02[i]).removeClass('a_exchange');
		},function(){
			//$(btn_list02[i]).addClass('a_exchange');
			$(btn_list02[i]).removeClass('a_exchange01');
		});						 
	});
}

function go_to(){
	var change_id = $('.go_change');
	var total_height = document.documentElement.clientHeight;
	var total_width = document.documentElement.scrollWidth;
	var change_width = change_id.width();
	var change_height = change_id.height();
	var left = total_width/2 - change_width/2;
	var top = total_height/2 - cchange_height/2;
	
	/*change_id.css({'left':left,'top':top});
	$(window).scroll(function(){
		change_id.css({'top':$(window).scrollTop()+top});						  
	});
	$('.close span').click(function(){
		change_id.hide();
		$('.all_win').hide();
	});*/
	$("#go").click(function(){
		//change_id.show();
		//$('.all_win').show();
		//alert($("input[name='go']"));
		
	});
}
//去兑换
function go_to(){
	var change_id = $('.go_change');
	var total_height = document.documentElement.clientHeight;
	var total_width = document.documentElement.scrollWidth;
	var change_width = change_id.width();
	var change_height = change_id.height();
	var left = total_width/2 - change_width/2;
	var top = total_height/2 - change_height/2;
	
	change_id.css({'left':left,'top':top});
	$(window).scroll(function(){
		change_id.css({'top':$(window).scrollTop()+top});						  
	});
	$('.close span').click(function(){
		change_id.hide();
		$('.all_win').hide();
	});
	
	$("input[name='go']").click(function(){
		change_id.show();
		$('.all_win').show();					
	});	
}

function checkactive(elem){
	var $box = $("#activebox");
	var time = null;
	$("#active").bind('click',function(e){
		if(elem){
			$('.all_win').show();
			$box.show();
			$box.find(".error_meg").html("暂时无活动");
			time = setTimeout(function(){
				$("#activebox").hide();
				$('.all_win').hide();
			},2000);
			e.preventDefault();
		}
	});
	$box.find(".close").click(function(){
		$("#activebox").hide();
		$('.all_win').hide();
		clearTimeout(time);
	});
}
function checkMagzine(act){
	var $box = $("#activebox");
	var time = null;
	$("#magine").bind('click',function(e){
		if(act){
			$('.all_win').show();
			$box.show();
			$box.find(".error_meg").html("暂时无杂志！");
			time = setTimeout(function(){
				$("#activebox").hide();
				$('.all_win').hide();
			},2000);
			e.preventDefault();
		}
	});
	$box.find(".close").click(function(){
		$("#activebox").hide();
		$('.all_win').hide();
		clearTimeout(time);
	});	
}
$(document).ready(function(){
	var $box = $("#activebox");
	var width = document.documentElement.scrollWidth;
	var boxwidth = $box.width();
	var left = width/2 - boxwidth/2;
	$box.css({'left':left,'top':'150px'});
	checkactive(1);
	checkMagzine(1);
});

$(function(){
	new exchange_list().init();	
	new recommend().init();
	new favorite().init();
	new second().init();
	new pop_form().init();
	new sliderdoor().init();
	new modify_pw().init();
	new selectAll().init();
	page_height();
	tween();
	//lr_height();
	getPosition();
	addbike();
	collect();	
	btn_change();
});


