jQuery.fn.loadthumb = function(options) {
	options = $.extend({
		 src : "",
		 fun:function(){}
	},options);
	var _self = this;
	_self.hide();
	var img = new Image();
	$(img).load(function(){
		_self.attr("src", options.src);
		options.fun(_self);
	}).attr("src", options.src);  
	return _self;
}
var common = {
    //<a href="javascript:void(0)" onClick="addBookmark()">favorites</a>
    addBookmark: function(){
        var url = parent.location.href;
        if (window.sidebar) {
            window.sidebar.addPanel(document.title, url, "");
        }
        else 
            if (document.all) {
                window.external.AddFavorite(url, document.title);
            }
            else 
                if (window.opera && window.print) {
                    return true;
                }
    },
    //<a href="javascript:void(0)" onclick="setHome(this,window.location)">set home</a> 
    setHome: function(obj, vrl){
        try {
            obj.style.behavior = 'url(#default#homepage)';
            obj.setHomePage(vrl);
        } 
        catch (e) {
            if (window.netscape) {
                try {
                    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
                } 
                catch (e) { //Sorry! Your browser does not support direct Homepage
                    alert('"抱歉！您的浏览器不支持直接设为首页。请在浏览器地址栏输入"about:config"并回车然后将[signed.applets.codebase_principal_support]设置为"true"，点击"加入收藏"后忽略安全提示，即可设置成功。"');
                }
                var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
                prefs.setCharPref('browser.startup.homepage', vrl);
            }
        }
    },
    lightbox: function(){
        $.getScript(webpath + 'js/jquery.include.js', function(){
            var files = [webpath + 'css/jquery.lightbox-0.5.css', webpath + 'js/jquery.lightbox-0.5.pack.js'];
            $.include(files, function(){
                if ($('.lightbox img').size() > 0) {
					var maxwidth=$('.lightbox').attr('maxwidth');
                    $('.lightbox img').width() > maxwidth ? $('.lightbox img').width(maxwidth) : $('.lightbox img').width($('.lightbox img').width());
                    $('.lightbox img').css('cursor', 'pointer').lightBox();
                }
            });
        });
    },
	resize:function(){
		if($('.h-v-resize').size()>0){
			$('.h-v-resize').each(function(){
				var mw=$(this).attr('maxwidth');
				var mh=$(this).attr('maxheight');
				var mt=$(this).attr('mtop');
				var ml=$(this).attr('mleft');
				$('img.resize',this).each(function(){
					$(this).loadthumb({src:$(this).attr('rel')
					,
					fun:function(t){		
					if(t.width()>mw||t.height()>mh)
						t.width()>t.height()?t.width(mw):t.height(mh); 
						
					if(t.height()<mh){
						t.css('margin', ((mh-t.height())/2+parseInt(mt))+'px '+ml+'px').fadeIn('slow');
						}
					else{
						t.css('margin', mt+'px '+ml+'px').fadeIn('slow');
					}
						}
					});
						});
					});		
			}
		},
	cycle:function(){
		if($('.banner').size()>0)
			$('.banner').cycle({
				fx:'fade'
			});
		}
};

$(function(){
	if($('.wrap').height()<$(window).height())
		$('.wrap').height($(window).height());
	$(window).resize(function(){ 
		if($('.wrap').height()<$(window).height())
			$('.wrap').height($(window).height());
	});
	$('#gosearch').click(function(){ 
		window.location.href=''+webpath+'search.asp?bigid='+$('#bigid').val()+'&smallid='+$('#smallid').val()+'&keyword='+$('#keyword').val();
	});
	
	common.resize();
	
/*	if($('.main-products-list').size()>0){
		if($('.main-products-list img').width()>136||$('.main-products-list img').height()>136)$('.main-products-list img').width()>$('.main-products-list img').height()?$('.main-products-list img').width(136):$('.main-products-list img').height(136); 
	if($('.main-products-list img').height()<136)
		$('.main-products-list img').css('margin', (146-$('.main-products-list img').height())/2+' auto');
		}*/
		
	if ($('.main-friendlink ul li').size() * $('.main-friendlink ul li:first').width() > $('.main-friendlink').width()) {
        changelink = function(){
            var f = $('.main-friendlink ul li:first').clone();
            $('.main-friendlink ul').append(f);
            $('.main-friendlink ul li:first').animate({
                width: 0,
                opacity: '0'
            }, {
                duration: 1000,
                complete: function(){
                    $(this).remove();
                }
            });
        };
        var cl;
        $('.main-friendlink ul').hover(function(){
            clearInterval(cl);
        }, function(){
            cl = setInterval('changelink()', 1000);
        });
    }
	
});