function resizePhoto(id, w, h) { if ($(id).width() > w) { $(id).width(w); } if ($(id).height() > h) { $(id).height(h); } } random = function(min, max, exact) { var native_random = Math.random; if (arguments.length === 0) { return native_random(); } else if (arguments.length === 1) { max = min; min = 0; } var range = min + (native_random() * (max - min)); return exact === void (0) ? Math.round(range) : range.toFixed(exact); }; var shareButton = { url: location.href, title: '', description: '', init: function (data) { if (typeof (data.url) != 'undefined') this.url = data.url; if (typeof (data.title) != 'undefined') this.title = data.title; if (typeof (data.description) != 'undefined') this.description = data.description; }, bind: function (data) { this.init(data); $('#shareBtn_sina').attr('title', '分享到新浪微博').click(function () { shareButton.toSina(); }); $('#shareBtn_nest').attr('title', '分享到网易微博').click(function () { shareButton.toNest(); }); $('#shareBtn_tencent').attr('title', '分享到腾讯微博').click(function () { shareButton.toTencent(); }); $('#shareBtn_renren').attr('title', '分享到人人网').click(function () { shareButton.toXiaonei(); }); $('#shareBtn_kaixin').attr('title', '分享到开心网').click(function () { shareButton.toKaixin(); }); $('#shareBtn_douban').attr('title', '分享到豆瓣网').click(function () { shareButton.toDouban(); }); $('#shareBtn_163').attr('title', '分享到网易梦幻人生').click(function () { shareButton.toNetease(); }); $('#shareBtn_qzone').attr('title', '分享到Qzone').click(function () { shareButton.toQzone(); }); }, toTencent: function () { var shareUrl = 'http://v.t.qq.com/share/share.php?'; var appKey = ''; shareUrl += 'url=' + encodeURIComponent(this.url) + '&appkey=' + appKey + '&title=' + encodeURIComponent(this.title); toshare(); window.open(shareUrl); }, toNest: function () { var shareUrl = 'http://t.163.com/article/user/checkLogin.do?'; shareUrl += 'link=' + encodeURIComponent(this.url) + '&source=&info=' + encodeURIComponent(this.title) + ' ' + encodeURIComponent(this.url); toshare(); window.open(shareUrl); }, toXiaonei: function () { var shareUrl = 'http://share.renren.com/share/buttonshare.do?'; shareUrl += 'link=' + encodeURIComponent(this.url); shareUrl += '&title=' + encodeURIComponent(this.title); toshare(); window.open(shareUrl); }, toSina: function () { var shareUrl = 'http://v.t.sina.com.cn/share/share.php?'; shareUrl += 'url=' + encodeURIComponent(this.url); shareUrl += '&title=' + encodeURIComponent(this.title); shareUrl += '&pic='; toshare(); window.open(shareUrl); }, toKaixin: function () { var shareUrl = 'http://www.kaixin001.com/~repaste/repaste.php?'; shareUrl += 'rurl=' + encodeURIComponent(this.url); shareUrl += '&rtitle=' + encodeURIComponent(this.title); shareUrl += '&rcontent=' + encodeURIComponent(this.description); toshare(); window.open(shareUrl); }, toDouban: function () { var shareUrl = 'http://www.douban.com/recommend/?'; shareUrl += 'url=' + encodeURIComponent(this.url); shareUrl += '&title=' + encodeURIComponent(this.title); toshare(); window.open(shareUrl); }, toNetease: function () { var shareUrl = 'http://dream.163.com/share/link/?'; shareUrl += 'url=' + encodeURIComponent(this.url); shareUrl += '&title=' + encodeURIComponent(this.title); shareUrl += '&content=' + encodeURIComponent(this.description); toshare(); window.open(shareUrl); }, toQzone: function () { var shareUrl = 'http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=' + encodeURIComponent(this.url); toshare(); window.open(shareUrl); } }; var utils = { getEvent: function(evt) { var evt = window.event || evt, c, cnt; if (!evt && window.Event) { c = arguments.callee; cnt = 0; while (c) { if ((evt = c.arguments[0]) && typeof (evt.srcElement) != "undefined") { break; } else if (cnt > 9) { break; } c = c.caller; ++cnt; } } return evt; }, mouseX: function(evt) { evt = this.getEvent(evt); return evt.pageX || (evt.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft)); }, mouseY: function(evt) { evt = this.getEvent(evt); return evt.pageY || (evt.clientY + (document.documentElement.scrollTop || document.body.scrollTop)); } }; function createAds(data, options, index) { var defaults = { selectedClass: 'selected', normalClass: 'normal', prevClass: 'prev', nextClass: 'next', delay: 3000, auto: true }; var options = $.extend(defaults, options); var ads = eval(data); var container = $(options.container); var btns = container.find(options.buttons); var hover = false; init(); show(index); function init() { if (data != '') { var btns = ''; for (var i = 0; i < ads.length; i++) { btns += ''; } btns += ''; $(options.buttons).html(btns); bindEvent(); autoPlay(); } else { container.hide(); } }; function bindEvent() { container.mouseover(function () { hover = true; }).mouseleave(function () { hover = false; }); btns.children('.item').click(function () { show(btns.children('.item').index($(this))); }); container.find('.' + options.prevClass).click(function () { var index = parseInt(btns.children('.' + options.selectedClass).attr('index')) - 1; if (index < 0) { index = 0; $(this).attr('disalbed', 'disabled'); } show(index); }); container.find('.' + options.nextClass).click(function () { var index = parseInt(btns.children('.' + options.selectedClass).attr('index')) + 1; if (index > btns.children('.item').length - 1) { index = btns.children('.item').length - 1; $(this).attr('disalbed', 'disabled'); } show(index); }); }; function show(index) { if (ads.length > 0) { var data = ads[index]; container.find('.photo').attr('src', data.img).attr('title', data.ititle); container.find('.title').attr('href', data.url).attr('title', data.ititle).attr('target', '_blank').html(data.title); container.find('.photo').parent('a').attr('href', data.url).attr('target', '_blank'); btns.children('.item').removeClass(options.selectedClass).addClass(options.normalClass).eq(index).removeClass(options.normalClass).addClass(options.selectedClass); } }; function autoPlay() { if (!options.auto) return; if (!hover) { var index = parseInt(btns.children('.' + options.selectedClass).attr('index')) + 1; if (index > btns.children('.item').length - 1 || isNaN(index)) { index = 0; btns.children('.' + options.prevClass).attr('disalbed', 'disabled'); } show(index); } setTimeout(function () { autoPlay(); }, options.delay); }; }