[8962] | 1 | /** |
---|
| 2 | * randomPict |
---|
| 3 | * |
---|
| 4 | * release 1.0.0 |
---|
| 5 | */ |
---|
| 6 | function randomPict(opt) |
---|
| 7 | { |
---|
| 8 | var options={ |
---|
| 9 | fixedHeight:0, |
---|
| 10 | pictures:[], |
---|
| 11 | showName:'n', |
---|
| 12 | showComment:'n', |
---|
| 13 | delay:0 |
---|
| 14 | }, |
---|
| 15 | properties={ |
---|
| 16 | vIntervalID:0, |
---|
| 17 | vCurrentPict:0, |
---|
| 18 | nameDOM:'', |
---|
| 19 | commentDOM:'', |
---|
| 20 | img:new Image() |
---|
| 21 | }, |
---|
| 22 | |
---|
| 23 | init = function (opt) |
---|
| 24 | { |
---|
| 25 | $.extend(options, opt); |
---|
| 26 | |
---|
| 27 | switch(options.showName) |
---|
| 28 | { |
---|
| 29 | case 'o': |
---|
| 30 | properties.nameDOM='iammRPicNameO'; |
---|
| 31 | break; |
---|
| 32 | case 'u': |
---|
| 33 | properties.nameDOM='iammRPicNameU'; |
---|
| 34 | break; |
---|
| 35 | } |
---|
| 36 | switch(options.showComment) |
---|
| 37 | { |
---|
| 38 | case 'o': |
---|
| 39 | properties.commentDOM='iammRPicCommentO'; |
---|
| 40 | break; |
---|
| 41 | case 'u': |
---|
| 42 | properties.commentDOM='iammRPicCommentU'; |
---|
| 43 | break; |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | if(properties.nameDOM!='') $('#'+properties.nameDOM).css('display', 'block'); |
---|
| 47 | if(properties.commentDOM!='') $('#'+properties.commentDOM).css('display', 'block'); |
---|
| 48 | |
---|
| 49 | if(options.delay>0) properties.vIntervalID = window.setInterval(getNextPicture, options.delay); |
---|
| 50 | |
---|
| 51 | if(options.fixedHeight>0) $('#irandompicinner').css('height', options.fixedHeight+'px'); |
---|
| 52 | |
---|
| 53 | preloadImages(); |
---|
| 54 | }, |
---|
| 55 | |
---|
| 56 | preloadImages = function () |
---|
| 57 | { |
---|
| 58 | $(properties.img).bind('load', |
---|
| 59 | function () |
---|
| 60 | { |
---|
| 61 | properties.vCurrentPict++; |
---|
| 62 | if(properties.vCurrentPict>=options.pictures.length) |
---|
| 63 | { |
---|
| 64 | properties.vCurrentPict=-1; |
---|
| 65 | getNextPicture(); |
---|
| 66 | } |
---|
| 67 | else |
---|
| 68 | { |
---|
| 69 | properties.img.src=options.pictures[properties.vCurrentPict].thumb; |
---|
| 70 | } |
---|
| 71 | } |
---|
| 72 | ); |
---|
| 73 | properties.img.src=options.pictures[properties.vCurrentPict].thumb; |
---|
| 74 | }, |
---|
| 75 | |
---|
| 76 | computePositionTop = function() |
---|
| 77 | { |
---|
[9002] | 78 | $("#iamm_ill0").css({top:($('#irandompicinner').innerHeight()-$("#iamm_ill0").innerHeight())/2}); |
---|
[8962] | 79 | }, |
---|
| 80 | |
---|
| 81 | getNextPicture = function() |
---|
| 82 | { |
---|
| 83 | properties.vCurrentPict++; |
---|
| 84 | if(properties.vCurrentPict>=options.pictures.length) properties.vCurrentPict=0; |
---|
| 85 | |
---|
| 86 | $('#iamm_ill0').fadeTo(200, 0, |
---|
| 87 | function () |
---|
| 88 | { |
---|
| 89 | if(properties.nameDOM!='') $('#'+properties.nameDOM).html(options.pictures[properties.vCurrentPict].name); |
---|
| 90 | if(properties.commentDOM!='') $('#'+properties.commentDOM).html(options.pictures[properties.vCurrentPict].comment); |
---|
| 91 | |
---|
| 92 | $('#iammRPicLink').attr('href', options.pictures[properties.vCurrentPict].link); |
---|
| 93 | $('#iammRPicImg').attr('src', options.pictures[properties.vCurrentPict].thumb); |
---|
| 94 | computePositionTop(); |
---|
| 95 | $('#iamm_ill0').fadeTo(200, 1); |
---|
| 96 | } |
---|
| 97 | ); |
---|
| 98 | |
---|
| 99 | }; |
---|
| 100 | |
---|
| 101 | init(opt); |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | |
---|
| 105 | $(document).ready( |
---|
| 106 | function () |
---|
| 107 | { |
---|
| 108 | var rPict=new randomPict(randomPictOpt); |
---|
| 109 | } |
---|
| 110 | ); |
---|