
jQuery.cookie=function(name,value,options){if(typeof value!='undefined'){options=options||{};if(value===null){value='';options.expires=-1;}
var expires='';if(options.expires&&(typeof options.expires=='number'||options.expires.toUTCString)){var date;if(typeof options.expires=='number'){date=new Date();date.setTime(date.getTime()+(options.expires*24*60*60*1000));}else{date=options.expires;}
expires='; expires='+date.toUTCString();}
var path=options.path?'; path='+(options.path):'';var domain=options.domain?'; domain='+(options.domain):'';var secure=options.secure?'; secure':'';document.cookie=[name,'=',encodeURIComponent(value),expires,path,domain,secure].join('');}else{var cookieValue=null;if(document.cookie&&document.cookie!=''){var cookies=document.cookie.split(';');for(var i=0;i<cookies.length;i++){var cookie=jQuery.trim(cookies[i]);if(cookie.substring(0,name.length+1)==(name+'=')){cookieValue=decodeURIComponent(cookie.substring(name.length+1));break;}}}
return cookieValue;}};

Array.prototype.inArray = function (value){var i;for (i=0; i < this.length; i++){if (this[i] === value){return true;}}return false;}


//外部调用的close box
function close_msg_box(){
    try{
        $('#floatbox').remove();
        $('#floatbox-overlay').remove();
        // Show some elements to avoid conflict with overlay in IE. These elements appear above the overlay.
        $('embed, object, select').css({ 'visibility' : 'visible' });
    }catch(e){}
}

function setCookie(name,value,noExpire,noyear,domain)
{
	//if(noExpire==null)noExpire=true;
	var strExpires='';
	if(noExpire)
	{
		expires=new Date();
		if(noyear==null) noExpire = (1000*86400*365)*noExpire;
		expires.setTime(expires.getTime()+noExpire);
		var strExpires="expires="+expires.toGMTString()+"; ";
	}
	var strdomain = "";
	if(domain==null){
		domain = '.lashou.com';
		var strdomain = ";domain="+domain;
	}
	document.cookie=name+"="+escape(value)+"; "+strExpires+"path=/"+strdomain;
}


function getCookie(name)
{
	cookie_name=name+"=";
	cookie_length=document.cookie.length;
	cookie_begin=0;
	while(cookie_begin<cookie_length)
	{
		value_begin=cookie_begin+cookie_name.length;
		if(document.cookie.substring(cookie_begin,value_begin)==cookie_name)
		{
			var value_end=document.cookie.indexOf(";",value_begin);
			if(value_end==-1)
			{
				value_end=cookie_length;
			}
			return unescape(document.cookie.substring(value_begin,value_end))
		}
		cookie_begin=document.cookie.indexOf(" ",cookie_begin)+1;
		if(cookie_begin==0)
		{
			break;
		}
	}
	return null;
}

function delCookie(name,domain)
{
	var expireNow=new Date();
	var strdomain = "";
	if(domain==null){
		domain = '.lashou.com';
		var strdomain = ";domain="+domain;
	}
	document.cookie=name+"=; expires=Thu, 01-Jan-70 00:00:01 GMT; path=/"+strdomain;
}

function china_mobile(s,d,e){
	  try{}catch(e){}
	  var f='http://go.139.com/ishare.do?';
	  var u = arguments[3];
	  var title = arguments[4]?arguments[4]:(d.title);
	  var p=['shareUrl=',e(u),'&title=',e(title),'&sid=55ef0c0718677b912f7368585a76afdd'].join('');
	  function a(){
	   if(!window.open([f,p].join(''),'mb',['toolbar=0,status=0,resizable=1,location=0,scrollbars=1,width=800,height=600,left=',(s.width-620)/2,',top=',(s.height-450)/2].join('')))u.href=[f,p].join('');
	  };
	   if(/Firefox/.test(navigator.userAgent)){
	   setTimeout(a,0)
	   }else{
	   a()
	   }
 }

 function hint(id){
	if(!id) return;
	var obj = document.getElementById(id);
	obj.title = obj.getAttribute('title');
	if(!obj.title) return;
	obj.onblur = function(){
		obj.style.color = "#999999";
		if(!obj.value || obj.value == obj.title){
			 obj.value = obj.title
		}
	}
	obj.onfocus = function(){
		obj.style.color = "#333333";
		if(obj.value == obj.title){
			 obj.value = '';
		}
	}
	obj.onblur();
}

function message_tip(value){
	setCookie('message_counts',value);
	close_msg_box();
}

function sns_share()
{
	$('.share ul li a').click(function(){
		var goods_id = $(this).parents('.goods').attr('id');
		goods_id = goods_id.substring(6);
		var title_h1 = $(this).parents('.share').next().find('h1');
		var city_name = title_h1.find('font').html();
		var title = title_h1.find('a').html();
		var title_qq = encodeURIComponent('#拉手网##'+city_name+'# @lashouwangbj 今日团购：'+title);
		title = encodeURIComponent('#拉手网##'+city_name+'#今日团购：'+title);
		var url = title_h1.find('a').attr('href');
		var encode_url = encodeURIComponent(url);
		var li_class = $(this).parent().attr('class');
		var encoded_pic_url = eval('encoded_pic_url_'+goods_id);
		if(li_class == 'sina'){
			var to_url = 'http://v.t.sina.com.cn/share/share.php?appkey=54350967&url='+encode_url+'&title='+title+'&pic='+encoded_pic_url;
		} else if(li_class == 'tengx'){
			var to_url = 'http://v.t.qq.com/share/share.php?appkey=b5269a602928480f83d3dc98a1fe3e54&url='+encode_url+'&title='+title_qq+'&pic='+encoded_pic_url;
		} else if(li_class == 'kaixin'){
			var to_url = 'http://www.kaixin001.com/repaste/share.php?rurl='+encode_url+'&rtitle='+title+'&rcontent='+encode_url;
		} else if(li_class == 'renren'){
			var to_url = 'http://share.renren.com/share/buttonshare.do?link='+encode_url+'&title='+title;
		} else if(li_class == 'douban'){
			var to_url = 'http://www.douban.com/recommend/?url='+encode_url+'&title='+title;
		} else if(li_class == 'sohu'){
			var to_url = 'http://bai.sohu.com/share/blank/addbutton.do?from=lashou&link='+encode_url;
		}
		$(this).attr('href', to_url);
	});
}

//返回顶部按钮
function show_goback(page_name)
{
	if(page_name != 'index2'){
		var nav_num = 0;loc_url = location.href;
		var domain = loc_url.substring(7);
		domain = domain.substring(0, domain.indexOf('/'));
		var is_show_by_page = 0;    //是否显示按钮根据不同的页面
		var back_links = $('.mainnav .nav ul li a');
		back_links.each(function(i){
			if(loc_url.indexOf($(back_links[i]).attr('href')) == 7+domain.length) {
				nav_num = i;
				is_show_by_page = 1;
				return false;
			}
		});
		if(is_show_by_page == 0 && loc_url == 'http://'+domain+'/') {
			is_show_by_page = 1;
		}
		if(is_show_by_page == 0) {
			return false;
		}
		var re = 90;
	}else{
		var re = 240;
		is_show_by_page = 1;
	}
    var fe = $('#go_lstop');
    var top_h = $('#go_lstop').height();
    var footer_top = $('.g_footer').offset().top;
    if(nav_num == 0) {
        top_h -= 148; 
    }
    function fixed_goback() {
        var y = $(window).scrollTop();
		if(y < 600) {
            fe.stop();
            fe.hide();
            return false;
        } else {
            fe.show();
        }
        var top, ua = get_navigator();
        var h = $(window).height() - re;
        if(ua == 'ie6') {
            if(footer_top <= y + h + top_h) {
                top = footer_top - top_h;
            } else {
                top = y + h;
            }
        } else {
            if(footer_top <= y + h + top_h) {
                top = footer_top - y - top_h;
            } else {
                top = h;
            }
        }
        var window_width = $(window).width();
        var left = (window_width + 950) / 2;
        fe.css('top', top + 'px');
        fe.css('margin-left', left + 'px');
    }
    $(window).scroll( function(){fixed_goback();} );
    $(window).resize( function(){fixed_goback();} );
}

//返回浏览器版本
function get_navigator()
{
    var ua = navigator.userAgent.toLowerCase();
    if(ua.indexOf('msie 6.0') > -1) {
        return 'ie6';
    } else if(ua.indexOf('firefox') > -1) {
        return 'firefox';
    }
    return false;
}

function zhuji_show(state){
	if(state=='show'){
		$('.zhuji_hide').show();
		$('#zhuji_all').replaceWith('<p class="shou_zuji" id="zhuji_all"><a  href="javascript:void(0);" onclick="zhuji_show(\'hide\');">点击收起</a></p>');
	}else if(state=='hide'){
		$('.zhuji_hide').hide();
		$('#zhuji_all').replaceWith('<p class="more_zuji" id="zhuji_all"><a  href="javascript:void(0);" onclick="zhuji_show(\'show\');">查看更多</a></p>')
	}
}

function index_fenye_set(type){
	if(type=='set'){
		setCookie('index_page_set',1,1000);
	}else if(type=='del'){
		delCookie('index_page_set');
	}
	window.location.replace(window.location.href);
}

function changImg()
{
	$('#img').attr('src','/img.php?rand='+Math.random());
}


$(function(){
	
	$('#n_help,#n_ml').find('a').mouseover(function(){
		$(this).next('ul').show().mouseover(function(){$(this).show()}).mouseout(function(){$(this).hide()});
	}).mouseout(function(){
		$(this).next('ul').hide();
	})
});

//ipad offset
if ( /webkit.*mobile/i.test(navigator.userAgent)) {
  (function($) {
      $.fn.offsetOld = $.fn.offset;
      $.fn.offset = function() {
        var result = this.offsetOld();
        result.top -= window.scrollY;
        result.left -= window.scrollX;
        return result;
      };
  })(jQuery);
}

(function($){
	var st = null;
	$.fn.tip = function(){
		$(this).mouseover(function(){
			var result = $(this).offset();
			if ( /webkit/i.test(navigator.userAgent)) {
				result.top = result.top +15;
			}
			var tipdiv = $(this).parent().find('.tipdiv');
			if(st){
				clearTimeout(st)
			}
			st = setTimeout(function(){				
				tipdiv.css({top:(parseInt(result.top)+20)+'px',left:parseInt(result.left)+'px'}).show();
				var a = tipdiv.find('.adre_widtd');
				var b = a.find('div');
				var marginTop = b.height() - a.height();
				if(marginTop > 0){
					b.css('margin-top','0px');
					b.animate({marginTop:-marginTop+'px'}, Math.ceil(marginTop/20)*1000)
				}
			},500)
		}).mouseout(function(){
			if(st){
				clearTimeout(st)
			}
			var tipdiv = $(this).parent().find('.tipdiv');
			tipdiv.hide()
		})
	}
})(jQuery);
