﻿function setHP(){//设为首页
	var url = "http://" +location.hostname;
	var obj = document.getElementsByTagName("a")[0];
	try{
		obj.style.behavior='url(#default#homepage)';
		obj.setHomePage(url);
	}catch(e){
		alert("浏览器不支持");
	}
}

function addBK(){//加入收藏
	var title = document.title;
	var url = "http://" +location.hostname;
	if(window.sidebar){ 
		window.sidebar.addPanel(title,url,""); 
	}else if( document.all ){
		window.external.addFavorite(url, title);   
	}else if( window.opera && window.print ){
		return true;
	}
}



function Trundle(plist, leftArrow, rightArrow, isGo, accNum) {//图片滚动
    var asInterval, acc, fetrue;
    acc = accNum * -1;
    fetrue = false;
    var plist = document.getElementById(plist);
    var leftSide = document.getElementById(leftArrow);
    var rightSide = document.getElementById(rightArrow);
    function goScroll() {
        if (!fetrue) {
            if (plist.scrollLeft == 0) {
                acc = acc * -1;
            }
            if (plist.scrollLeft == plist.scrollWidth - plist.offsetWidth) {
                acc = acc * -1;
            }
        }
        plist.scrollLeft += acc;
    }
    function autoScroll() {
        asInterval = setInterval(function() { goScroll() }, 50);
    }
    function stopScroll(obj) {
        clearInterval(asInterval);
        obj.onmouseout = function() {
            autoScroll();
        }
    }
    function manualScroll(obj, nacc) {
//        acc = nacc;
//        fetrue = true;
        obj.onmousedown = function() {
            acc = nacc * 4;
            fetrue = true;
        }
        obj.onmouseup = function() {
            acc = nacc;
        }
        obj.onmouseout = function() {
            fetrue = false;
        }
    }
	if(leftArrow.length>0){
    leftSide.onmouseover = function() { manualScroll(leftSide, accNum) }
	}
	if(rightArrow.length>0){
    rightSide.onmouseover = function() { manualScroll(rightSide, accNum * -1) }
	}
    plist.onmouseover = function() { stopScroll(plist); }

    if (isGo) autoScroll();

}



function activeVerifyCode(vcPath) {//点击生成验证码
    $(".verifyCode").focus(function() {
        var pos = $(this).position();
        $("<img />")
			.addClass("verifyCodeImage")
			.attr("src", vcPath + "?t=" + Math.round(Math.random() * 1000))
			.css({
			    "position": "absolute",
			    "left": pos.left + $(this).outerWidth()+5 + "px",
			    "top": pos.top + "px"
			})
			.insertAfter(this);
    }).blur(function() {
        $(".verifyCodeImage").remove();
    })
}


//按比例生成缩略图
(function($){
	$.fn.jNarrow = function(maxWidth, maxHeight, options){
		$(this).each(function(index,o){
			var img = document.createElement("img");
			img.onload = function(){
				if( img.width >= maxWidth ){
					img.height = img.height * maxWidth / img.width;
					img.width = maxWidth
				}
				if( maxHeight && img.height >= maxHeight ){
					img.width = img.width * maxHeight / img.height;
					img.height = maxHeight
				}
				$(o).css({
					"width": img.width +"px",
					"height": img.height +"px"
				});
				dispose()
			}
			var dispose = function(){
				img = null
			}
			img.src = $(o).attr("src");
		});
	}
})(jQuery);

