$(document).ready(function(){
	$('#pic_container').click(function(){
	var numberOfPics=$(this).find('div > img').length;
	var next = Math.floor(Math.random()*numberOfPics);
		$(this)
		.scrollTo(
		'#pic_scroller>img:eq('+next+')',{duration:1000}
		);
	});
});
/**
 * jQuery.ScrollTo
 * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 5/25/2009
 *
 * @projectDescription Easy element scrolling using jQuery.
 * http://flesler.blogspot.com/2007/10/jqueryscrollto.html
 * Works with jQuery +1.2.6. Tested on FF 2/3, IE 6/7/8, Opera 9.5/6, Safari 3, Chrome 1 on WinXP.
 *
 * @author Ariel Flesler
 * @version 1.4.2
 *
 * @id jQuery.scrollTo
 * @id jQuery.fn.scrollTo
 * @param {String, Number, DOMElement, jQuery, Object} target Where to scroll the matched elements.
 *	  The different options for target are:
 *		- A number position (will be applied to all axes).
 *		- A string position ('44', '100px', '+=90', etc ) will be applied to all axes
 *		- A jQuery/DOM element ( logically, child of the element to scroll )
 *		- A string selector, that will be relative to the element to scroll ( 'li:eq(2)', etc )
 *		- A hash { top:x, left:y }, x and y can be any kind of number/string like above.
*		- A percentage of the container's dimension/s, for example: 50% to go to the middle.
 *		- The string 'max' for go-to-end. 
 * @param {Number} duration The OVERALL length of the animation, this argument can be the settings object instead.
 * @param {Object,Function} settings Optional set of settings or the onAfter callback.
 *	 @option {String} axis Which axis must be scrolled, use 'x', 'y', 'xy' or 'yx'.
 *	 @option {Number} duration The OVERALL length of the animation.
 *	 @option {String} easing The easing method for the animation.
 *	 @option {Boolean} margin If true, the margin of the target element will be deducted from the final position.
 *	 @option {Object, Number} offset Add/deduct from the end position. One number for both axes or { top:x, left:y }.
 *	 @option {Object, Number} over Add/deduct the height/width multiplied by 'over', can be { top:x, left:y } when using both axes.
 *	 @option {Boolean} queue If true, and both axis are given, the 2nd axis will only be animated after the first one ends.
 *	 @option {Function} onAfter Function to be called after the scrolling ends. 
 *	 @option {Function} onAfterFirst If queuing is activated, this function will be called after the first scrolling ends.
 * @return {jQuery} Returns the same jQuery object, for chaining.
 *
 * @desc Scroll to a fixed position
 * @example $('div').scrollTo( 340 );
 *
 * @desc Scroll relatively to the actual position
 * @example $('div').scrollTo( '+=340px', { axis:'y' } );
 *
 * @dec Scroll using a selector (relative to the scrolled element)
 * @example $('div').scrollTo( 'p.paragraph:eq(2)', 500, { easing:'swing', queue:true, axis:'xy' } );
 *
 * @ Scroll to a DOM element (same for jQuery object)
 * @example var second_child = document.getElementById('container').firstChild.nextSibling;
 *			$('#container').scrollTo( second_child, { duration:500, axis:'x', onAfter:function(){
 *				alert('scrolled!!');																   
 *			}});
 *
 * @desc Scroll on both axes, to different values
 * @example $('div').scrollTo( { top: 300, left:'+=200' }, { axis:'xy', offset:-20 } );
 */
;(function( $ ){
	
	var $scrollTo = $.scrollTo = function( target, duration, settings ){
		$(window).scrollTo( target, duration, settings );
	};

	$scrollTo.defaults = {
		axis:'xy',
		duration: parseFloat($.fn.jquery) >= 1.3 ? 0 : 1
	};

	// Returns the element that needs to be animated to scroll the window.
	// Kept for backwards compatibility (specially for localScroll & serialScroll)
	$scrollTo.window = function( scope ){
		return $(window)._scrollable();
	};

	// Hack, hack, hack :)
	// Returns the real elements to scroll (supports window/iframes, documents and regular nodes)
	$.fn._scrollable = function(){
		return this.map(function(){
			var elem = this,
				isWin = !elem.nodeName || $.inArray( elem.nodeName.toLowerCase(), ['iframe','#document','html','body'] ) != -1;

				if( !isWin )
					return elem;

			var doc = (elem.contentWindow || elem).document || elem.ownerDocument || elem;
			
			return $.browser.safari || doc.compatMode == 'BackCompat' ?
				doc.body : 
				doc.documentElement;
		});
	};

	$.fn.scrollTo = function( target, duration, settings ){
		if( typeof duration == 'object' ){
			settings = duration;
			duration = 0;
		}
		if( typeof settings == 'function' )
			settings = { onAfter:settings };
			
		if( target == 'max' )
			target = 9e9;
			
		settings = $.extend( {}, $scrollTo.defaults, settings );
		// Speed is still recognized for backwards compatibility
		duration = duration || settings.speed || settings.duration;
		// Make sure the settings are given right
		settings.queue = settings.queue && settings.axis.length > 1;
		
		if( settings.queue )
			// Let's keep the overall duration
			duration /= 2;
		settings.offset = both( settings.offset );
		settings.over = both( settings.over );

		return this._scrollable().each(function(){
			var elem = this,
				$elem = $(elem),
				targ = target, toff, attr = {},
				win = $elem.is('html,body');

			switch( typeof targ ){
				// A number will pass the regex
				case 'number':
				case 'string':
					if( /^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(targ) ){
						targ = both( targ );
						// We are done
						break;
					}
					// Relative selector, no break!
					targ = $(targ,this);
				case 'object':
					// DOMElement / jQuery
					if( targ.is || targ.style )
						// Get the real position of the target 
						toff = (targ = $(targ)).offset();
			}
			$.each( settings.axis.split(''), function( i, axis ){
				var Pos	= axis == 'x' ? 'Left' : 'Top',
					pos = Pos.toLowerCase(),
					key = 'scroll' + Pos,
					old = elem[key],
					max = $scrollTo.max(elem, axis);

				if( toff ){// jQuery / DOMElement
					attr[key] = toff[pos] + ( win ? 0 : old - $elem.offset()[pos] );

					// If it's a dom element, reduce the margin
					if( settings.margin ){
						attr[key] -= parseInt(targ.css('margin'+Pos)) || 0;
						attr[key] -= parseInt(targ.css('border'+Pos+'Width')) || 0;
					}
					
					attr[key] += settings.offset[pos] || 0;
					
					if( settings.over[pos] )
						// Scroll to a fraction of its width/height
						attr[key] += targ[axis=='x'?'width':'height']() * settings.over[pos];
				}else{ 
					var val = targ[pos];
					// Handle percentage values
					attr[key] = val.slice && val.slice(-1) == '%' ? 
						parseFloat(val) / 100 * max
						: val;
				}

				// Number or 'number'
				if( /^\d+$/.test(attr[key]) )
					// Check the limits
					attr[key] = attr[key] <= 0 ? 0 : Math.min( attr[key], max );

				// Queueing axes
				if( !i && settings.queue ){
					// Don't waste time animating, if there's no need.
					if( old != attr[key] )
						// Intermediate animation
						animate( settings.onAfterFirst );
					// Don't animate this axis again in the next iteration.
					delete attr[key];
				}
			});

			animate( settings.onAfter );			

			function animate( callback ){
				$elem.animate( attr, duration, settings.easing, callback && function(){
					callback.call(this, target, settings);
				});
			};

		}).end();
	};
	
	// Max scrolling position, works on quirks mode
	// It only fails (not too badly) on IE, quirks mode.
	$scrollTo.max = function( elem, axis ){
		var Dim = axis == 'x' ? 'Width' : 'Height',
			scroll = 'scroll'+Dim;
		
		if( !$(elem).is('html,body') )
			return elem[scroll] - $(elem)[Dim.toLowerCase()]();
		
		var size = 'client' + Dim,
			html = elem.ownerDocument.documentElement,
			body = elem.ownerDocument.body;

		return Math.max( html[scroll], body[scroll] ) 
			 - Math.min( html[size]  , body[size]   );
			
	};

	function both( val ){
		return typeof val == 'object' ? val : { top:val, left:val };
	};

})( jQuery );
#pic_container {
  overflow: hidden;
  height: 200px;
  width: 200px;
  margin-bottom: 15px;
}

#pic_scroller {
  height: 600px;
  width: 800px;
  overflow: hidden;
}

#pic_scroller img {
  float: left;
}
<!doctype html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <title>StarTrackr!</title>
  
  <link rel="stylesheet" href="../../css/base.css" type="text/css" media="screen" charset="utf-8" />
  <link rel="stylesheet" href="style.css" type="text/css" media="screen" charset="utf-8" />
  
  <script src="../../lib/jquery-1.7.1.min.js" type="text/javascript" ></script>
  <script src="jquery.scrollTo.js" type="text/javascript" charset="utf-8"></script>
  <script type="text/javascript" src="script.js"></script>
</head>
<body>
  <div id="container">
    <div id="header">
      <h1>StarTrackr!</h1>
    </div>
    <div id="content">
      <h2>
        Welcome!
      </h2>
      <div id="navigation">
        <ul>
          <li id="home"><a href="#">Home</a></li>
          <li><a href="#">Buy Now!</a></li>
          <li><a href="#">About Us</a></li>
          <li><a href="#">Gift Ideas</a></li>
        </ul>
      </div>
      <p id="intro">
        Welcome to <strong>StarTrackr!</strong> the planet's premier celebrity tracking and monitoring service. Need to know where in the world the best bands, musicians or producers are within 2.2 square meters? You've come to the right place. We have a very special special on B-grade celebs this week, so hurry in!    
      </p>
      <p id="disclaimer">
        Disclaimer! This service is not intended for the those with criminal intent. Celebrities are kind of like people so their privacy should be respected.
      </p>
      
      <h2>Around Town Last Night</h2>
      <div id="pic_container">
        <div id="pic_scroller">
          <img alt="Glendatronix" src="../../images/glenda_200.jpg" />
          <img alt="Darth Fader" src="../../images/fader_200.jpg" />
          <img alt="Beau Dandy" src="../../images/beau_200.jpg" />
          <img alt="Johnny Stardust" src="../../images/johnny_200.jpg" />
          <img alt="Mo' Fat" src="../../images/mofat_200.jpg" />
          <img alt="Glendatronix" src="../../images/kellie_200.jpg" />
          <img alt="Darth Fader" src="../../images/fader_200.jpg" />
          <img alt="Beau Dandy" src="../../images/beau_200.jpg" />
          <img alt="Johnny Stardust" src="../../images/johnny_200.jpg" />
          <img alt="Mo' Fat" src="../../images/mofat_200.jpg" />
          <img alt="Glendatronix" src="../../images/glenda_200.jpg" />
          <img alt="Darth Fader" src="../../images/fader_200.jpg" />
        </div>
     </div>
      
      <div id="news">
        <h2>Latest News</h2>
        <p>
          Which member of the seminal calypso/lectro band <em>C&amp;C Music Sweatshop</em> was spotted last night at <em>Dirt</em>, the trendy New York restaurant that serves only food caught and retrieved by the chef's own hands?
          <span class="spoiler">Yes! It's the ever-effervescent, <em>Glendatronix</em>!</span>
        </p>
        <p>Who lost their recording contract today? <span class="spoiler">The Zaxntines!</span></p>
      </div>
      <div id="celebs">
        <h2 class="heading">Our Celebrities</h2>
        <p class="info">
          We have an ever changing roster of newly chipped celebrities. But it can take as little as a week for the little critters to realise they've been tagged - so you have to be fast! 
        </p>
        <table class="data">
          <thead>
            <tr>
              <th>ID</th>
              <th>Name</th>
              <th>Occupation</th>
              <th>Approx. Location</th>
              <th>Price</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td>203A</td>
              <td>Johny Stardust (<a href="../../images/johnny_400.jpg" class="lightbox">pic</a>)</td>
              <td>Front-man</td>
              <td>Los Angeles</td>
              <td>$39.95</td>
            </tr>
            <tr>
              <td>141B</td>
              <td>Beau Dandy (<a href="../../images/beau_400.jpg" class="lightbox">pic</a>)</td>
              <td>Singer</td>
              <td>New York</td>
              <td>$39.95</td>
            </tr>
            <tr>
              <td>2031</td>
              <td>Mo' Fat (<a href="../../images/mofat_400.jpg" class="lightbox">pic</a>)</td>
              <td>Producer</td>
              <td>New York</td>
              <td>$19.95</td>
            </tr>
            <tr>
              <td>007F</td>
              <td>Kellie Kelly (<a href="../../images/kellie_400.jpg" class="lightbox">pic</a>)</td>
              <td>Singer</td>
              <td>Omaha</td>
              <td>$11.95</td>
            </tr>
            <tr>
              <td>8A05</td>
              <td>Darth Fader (<a href="../../images/fader_400.jpg" class="lightbox">pic</a>)</td>
              <td>DJ</td>
              <td>London</td>
              <td>$19.95</td>
            </tr>
            <tr>
              <td>6636</td>
              <td>Glendatronix  (<a href="../../images/glenda_400.jpg" class="lightbox">pic</a>)</td>
              <td>Keytarist</td>
              <td>London</td>
              <td>$39.95</td>
            </tr>
          </tbody>
        </table>
      </div>
      
      <div id="comment">
        <h2>Leave a comment</h2>
        name:<br />
        <input type="text" /><br/>
        comment:<br/>
        <textarea rows="5" cols="30"></textarea>
      </div>
      
      <h2>Fine Print</h2>
      <p id="fine_print">
        Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.    
      </p>   
    </div>

    <div id="footer">
      <p>
        &copy; Copyright 2010 CelebriTracker Productions
      </p>
      <a href="#">Top of page</a>
    </div>
  </div>
</body>
</html>

By admin

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.