﻿$(function() {

    correctPNG();
    externallinks();

    //关键词搜索
    $("#keywords").focus(function() {
        if ($.trim($(this).val()) == "在此输入关键词") $(this).val("");
    })
    $("#keywords").blur(function() {
        if ($.trim($(this).val()) == "") $(this).val("在此输入关键词");
    })
    $(".search_btn").click(function() {
        var keywords = $("#keywords").val();
        var keybiaoshi = $(this).parent().parent().parent().attr("id");
        if (keywords == "在此输入关键词" || $.trim(keywords) == "") {
            alert("请输入您的搜索关键词！");
            return false;
        }
        else {
            if (keybiaoshi == "search2") {
                topPage.search();
            }
            if (keybiaoshi == "search3") {
                topPage.jjsearch();
             }
             if (keybiaoshi == "search") {
                topPage.dzsearch();
            }
            return false;
        }
    })

    //定制信息提示
    $('.custom_box').hover(function(){
			$('.custom_info').animate({width: "toggle"},100)
		},function(){
			$('.custom_info').animate({width: "toggle"},100);
		});

    $("#web_sub_fav ul li.car").hover(
	  function() {
	      $(this).addClass("arrow");
	      $("#shopping_car").show();
	  }, function() {
	      $(this).removeClass("arrow");
	      $("#shopping_car").hide();
	  }
	);

    //购物车处理
    $("#shopping_car").hover(
	  function() {
	      $("#web_sub_fav ul li.car").addClass("arrow");
	      $(this).show();
	  }, function() {
	      $("#web_sub_fav ul li.car").removeClass("arrow");
	      $(this).hide();
	  }
	);

    //Menu高亮处理
    var menu_num = 0;
    var body_class = $('body').attr("class").substr(1);
    $("#menu div dl dd").removeClass("on");
    if (body_class != "") {
        menu_num = body_class;
        $("#menu div dl dd:eq(" + menu_num + ")").addClass("on");
    } else {
        $("#menu .home_menu").addClass("home_menu_on");
    }

    //设计师页面Menu高亮处理
    $("#menu2 p").removeClass("on");
    $("#menu2 p:eq(" + menu_num + ")").addClass("on");

    //返回顶部
    $("#copy").after("<div id=\"gototop\"><a href=\"#\" title=\"点击返回到顶部\">&nbsp;</a></div>");
    $('#gototop').topLink({
        min: 100,
        fadeSpeed: 500
    });
    $('#gototop').click(function() {
        if ($.browser.safari) {//这里判断浏览器是否为safari 
            $('body').animate({ scrollTop: 0 }, 'slow');
            return false; //返回false可以避免在原链接后加上# 
        } else {
            $('html').animate({ scrollTop: 0 }, 500);
            return false;
        }
    });

    //定制页面导航菜单效果
    $("#b").hover(
	  function() {
	      var obj = $(this).find("div");
	      if (obj.is(":hidden")) {
	          obj.slideDown(200);
	          $(this).find("a:first").addClass("arrow");
	      }
	  }, function() {
	      $(this).find("div").slideUp(200);
	      $(this).find("a:first").removeClass("arrow");
	  }
	);

    //设计师页面导航菜单效果
    $("#menu2 > div").hover(
	  function() {
	      var obj = $(this).find(".show_sub");
	      if (obj.is(":hidden")) {
	          obj.slideDown(200);
	      }
	  }, function() {
	      $(this).find(".show_sub").slideUp(200);
	  }
	);


    //在线客服
    //$("#copy").after("<div id=\"online\"><a href=\"http://chat16.live800.com/live800/chatClient/chatbox.jsp?companyID=101963&amp;configID=29352&amp;jid=2042801916&amp;enterurl=http%3A%2F%2Fwww.7d.com.cn%2F&amp;timestamp=1275565527512\" title=\"在线客服\" target=\"_blank\">&nbsp;<\/a></div>");
    $("#online").show(500);
    kefu = function(id, _top, _right) {
        var me = id.charAt ? document.getElementById(id) : id, d1 = document.body, d2 = document.documentElement;
        d1.style.height = d2.style.height = '100%'; me.style.top = _top ? _top + 'px' : 0; me.style.right = _right + "px"; //[(_left>0?'left':'left')]=_left?Math.abs(_left)+'px':0;
        me.style.position = 'absolute';
        setInterval(function() { me.style.top = parseInt(me.style.top) + (Math.max(d1.scrollTop, d2.scrollTop) + _top - parseInt(me.style.top)) * 0.1 + 'px'; }, 10 + parseInt(Math.random() * 20));
        return arguments.callee;
    };
    var t = 142;
    var w = 10;
    if ($("#banner_main").length > 0) t = 158;

    kefu('online', t, w);

    //Hover效果
    $(".hover").hover(
	  function() {
	      $(this).addClass("hover");
	  }, function() {
	      $(this).removeClass("hover");
	  }
	);


});
	

//plugin
jQuery.fn.topLink = function(settings) {
	settings = jQuery.extend({
		min: 1,
		fadeSpeed: 200
	}, settings);
	return this.each(function() {
		//listen for scroll
		var el = $(this);
		el.hide(); //in case the user forgot
		$(window).scroll(function() {
			if($(window).scrollTop() >= settings.min){
				el.fadeIn(settings.fadeSpeed);
			}
			else{
				el.fadeOut(settings.fadeSpeed);
			}
		});
	});
};


function externallinks() {   
    if (!document.getElementsByTagName) return;   
    var anchors = document.getElementsByTagName("a");   
    for (var i=0; i<anchors.length; i++){   
       var anchor = anchors[i];   
       if (anchor.getAttribute("href") && anchor.getAttribute("rel")=="external") anchor.target="_blank";
    }   
}   
window.onload = externallinks;

function addcom(){
	var idmax=3;
	if(document.getElementById("anonymous").checked == true){
        document.getElementById("id1").style.display='none';
		document.getElementById("id2").style.display='none';
        document.getElementById("id3").style.display='';
	}else{
        document.getElementById("id1").style.display='';
		document.getElementById("id2").style.display='';
        document.getElementById("id3").style.display='none';
	}
}

function SetFont(size){
	document.getElementById("txt").style.fontSize=size;
}

function bookmark(){
	var title=document.title;
	var url=document.location.href;
	if (window.sidebar) window.sidebar.addPanel(title, url, "");
	else if( window.opera && window.print ){
	  var mbm = document.createElement('a');
	  mbm.setAttribute('rel','sidebar');
	  mbm.setAttribute('href',url);
	  mbm.setAttribute('title',title);
	  mbm.click();
	}else if(document.all) window.external.AddFavorite( url, title);
}

function copyToClipBoard(){ 
    var txt=""; 
    txt+=document.title; 
    txt+=""; 
    txt+=this.location.href;
    if (window.clipboardData) {   
        window.clipboardData.clearData();   
        window.clipboardData.setData("Text", txt);   
    } else if (navigator.userAgent.indexOf("Opera") != -1) {   
        window.location = txt;   
    } else if (window.netscape) {   
        try {   
            netscape.security.PrivilegeManager   
                    .enablePrivilege("UniversalXPConnect");   
        } catch (e) {   
            alert("你使用的FireFox浏览器,复制功能被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车。\n然后将“signed.applets.codebase_principal_support”双击，设置为“true”");   
            return;   
        }   
        var clip = Components.classes['@mozilla.org/widget/clipboard;1']   
                .createInstance(Components.interfaces.nsIClipboard);   
        if (!clip)   
            return;   
        var trans = Components.classes['@mozilla.org/widget/transferable;1']   
                .createInstance(Components.interfaces.nsITransferable);   
        if (!trans)   
            return;   
        trans.addDataFlavor('text/unicode');   
        var str = new Object();   
        var len = new Object();   
        var str = Components.classes["@mozilla.org/supports-string;1"]   
                .createInstance(Components.interfaces.nsISupportsString);   
        var copytext = txt;   
        str.data = copytext;   
        trans.setTransferData("text/unicode", str, copytext.length * 2);   
        var clipid = Components.interfaces.nsIClipboard;   
        if (!clip)   
            return false;   
        clip.setData(trans, null, clipid.kGlobalClipboard);   
    }  
    alert("复制成功，请粘贴到你的QQ/MSN上推荐给你的好友"); 
} 

jQuery.cookie = function(name, value, options) {
if (typeof value != 'undefined') {
   options = options || {};
   if (value === null) {
    value = '';
    options = $.extend({}, options);
    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;
}
};

function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6. 
{ 
    var arVersion = navigator.appVersion.split("MSIE") 
    var version = parseFloat(arVersion[1]) 
    if ((version >= 5.5) && (document.body.filters)) 
    { 
       for(var j=0; j<document.images.length; j++) 
       { 
          var img = document.images[j] 
          var imgName = img.src.toUpperCase() 
          if (imgName.substring(imgName.length-3, imgName.length) == "PNG") 
          { 
             var imgID = (img.id) ? "id='" + img.id + "' " : "" 
             var imgClass = (img.className) ? "class='" + img.className + "' " : "" 
             var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' " 
             var imgStyle = "display:inline-block;" + img.style.cssText 
             if (img.align == "left") imgStyle = "float:left;" + imgStyle 
             if (img.align == "right") imgStyle = "float:right;" + imgStyle 
             if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle 
             var strNewHTML = "<ins " + imgID + imgClass + imgTitle 
             + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";" 
             + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" 
             + "(src=\'" + img.src + "\');\"></ins>" 
             img.outerHTML = strNewHTML 
             j = j-1 
          } 
       } 
    }     
} 
//window.attachEvent("onload", correctPNG);

//新加部分
function topPage(){};
//绑定登录状态
topPage.bindLoginStatus =function()
{
	$.ajax
	(
		{
		  type:"GET",
		  url:"/NewHandler/UserState2.ashx",
		  success: function(txt)
		  {		 
			    var arr = txt.split("|");   
				 //已登录
			    if(arr[0] == "1")
			    {	
			        $("#liUserInfo").html("你好，<a href='/home/usercenter.aspx'>"+arr[4]+"</a>");
			        $("#liTopRegister").html("<a href='/home/exit.aspx'>退出登录</a>");
			        $("#liTopLogin").html("<a href='/home/usercenter.aspx'>我的7D</a>");
			    }
			    else
			    {
			        $("#liTopLogin").html("<a href='/login.aspx'>登录</a>");
			        $("#liTopRegister").html("<a href='/login.aspx'>注册</a>");
			    }
			    
			    var shopping_number=parseInt(arr[1])+parseInt(arr[3]);
			    $("#spanTopCartNumeric").text(arr[1]);
			    $("#spanTopDZCartNumeric").text(arr[3]);
			    $("#web_sub_fav ul li.car ins").text(shopping_number);
	            $("#shopping_car p span:first").text(shopping_number);
		  }
		}
	);
}

//头部广告图
topPage.imageShow = function()
{
  $.ajax
	(
		{
		  type:"GET",
		  url:"/NewHandler/ImagesShow.ashx",
		  data: {"imagid":"29"},//广告id
		  success: function(strAll)
		  {
			  $("#information").html(strAll);
			 
		  },
		  error: function()
		  {
			
		  }
		}
	);
}

//搜索
topPage.search = function()
{
	var key = $.trim($("#keywords").val());
	if(key=="在此输入关键词")
	{
		key="";
	}
	window.location.href = '/key-' + key+".html";
}
//定制搜索
topPage.dzsearch = function()
{
	var key = $.trim($("#keywords").val());
	if(key=="在此输入关键词")
	{
		key="";
	}	
	window.location.href = '/DZkey-' + key+".html";
}

//Jessiejane搜索
topPage.jjsearch = function() {
    var key = $.trim($("#keywords").val());
    if (key == "在此输入关键词") {
        key = "";
    }
    window.location.href = '/Jessiejanekey-' + key + "-0.html";
}


$(function()
{
	//用户登陆的状态
	topPage.bindLoginStatus();
	topPage.imageShow();         

	$("#keywords").keydown(function(event)
	{
		var code;
		if(window.event)
		{
			code = window.event.keyCode;
		}
		else 
		{
			code = e.which;
		}
		code = parseInt(code);
		
		if(code == 13)
		{
			topPage.search();
			return false;
		}
	});
});

$(this).scroll(function() { // 页面发生scroll事件时触发
var bodyTop = 0;
if (typeof window.pageYOffset != 'undefined') {
bodyTop = window.pageYOffset;
}
else if (typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat')
{
bodyTop = document.documentElement.scrollTop;
}
else if (typeof document.body != 'undefined') {
bodyTop = document.body.scrollTop;
}
$("#top_ceo").css("top", 160 + bodyTop) // 设置层的CSS样式中的top属性
});

