
$(document).ready(
  function() {
	  
	//open external links in a new window
	//externalLinksByHref();
	  
	//Homepage Slideshow
    if($(".home-feature-image").length > 0){
      StartHomeSlideShow();
    }
    
	//Homepage News
    //buggy when divs are loaded as display: none
    //refer: http://code.google.com/p/jscrollpane/issues/detail?id=30
    //$('.scroll-pane').jScrollPane();
		
	//Showcase Index
    if ($('div.showcase-index').length > 0) {
      $('div.showcase-index div.items div img').bind('mouseover mouseout', function () {
    	$(this).parent().parent().parent().toggleClass('showcase-index-hover');
      });
      $('div.showcase-index ul a').bind("mouseover", revealShowcaseInfo );
      $('div.showcase-index ul a').bind("mouseout", hideShowcaseInfo );
      $('div.showcase-index div.items div a').bind("mouseover", revealShowcaseInfo );
      $('div.showcase-index div.items div a').bind("mouseout", hideShowcaseInfo );
    }
	
    //Showcase Detail - enable slideshows
    if ($('div.showcase-detail').length > 0) {
      $('div#content-body a.slide').bind("click", revealSlideShow );
    }

    //Slideshow Layer - enable navigation
    if ($('div#content-slideshow').length > 0) {
      $('div#content-slideshow p.close-button a').bind("click", hideSlideShow );
      $('div#content-slideshow p.nav a').bind("click", nextSlide );
    }
    
    //General pages
    if ($('ul.thumbnails').length > 0) {
      $('ul.thumbnails a').bind("click", revealSlideShow );
    }
  }
);


//Homepage Slideshow functions

var IntervalSeconds = 6; // Time between images. [in seconds]

function StartHomeSlideShow(){
  setInterval("changeHomeSlideItem()", IntervalSeconds * 1000);
}

function changeHomeSlideItem(){
  var activeItem=$(".home-feature-image[rel='active']");
  var newItem;
  //console.debug(activeItem.next().length);
  if(activeItem.next(".home-feature-image").length > 0){
	newItem=activeItem.next(".home-feature-image");
  }
  else{
	newItem=$(".home-feature-image:first");	
  }
  activeItem.css("z-index","50").removeAttr("rel");
  newItem.css("z-index","10").attr("rel","active").show();
  activeItem.fadeOut("slow");
}



//Homepage News functions


// FADE VERSION

function newNewsItem(action){
	var activeItem=$("div#content-trim.n1 div#content-body .inner[rel='active']");
	var newItem;
	
	if(activeItem.next(".inner").length > 0){
		newItem=activeItem.next(".inner");			
	}else{
		newItem=$("div#content-trim.n1 div#content-body .inner:first")
	}

	activeItem.fadeOut("fast").removeAttr("rel");
	newItem.fadeIn("fast").attr("rel","active");

}



// SLIDE VERSION
/*
function newNewsItem(action){
	var activeItem=$("div#content-trim.n1 div#content-body .inner[rel='active']");
	var newItem;
	if(action=='prev'){
		if(activeItem.prev().length > 0){
			newItem=activeItem.prev();
		
		// Show Prev
		
		newItem.css("left","400px").css("margin-left:0;");
		newItem.show();
		activeItem.animate({ 
			left: "-400px",
		  }, 1500, "",function(){activeItem.hide().css("left","0");}).removeAttr("rel");
		newItem.animate({ 
			left: "0px",
		  }, 1500).attr("rel","active");
			
		}
	}else if(action=='next'){
	
		if(activeItem.next().length > 0){
			newItem=activeItem.next();
			
		
			// Show Next
			newItem.css("margin-left","-400px");
			newItem.show();
			activeItem.animate({ 
				left: "400px",
			  }, 1500, "",function(){activeItem.hide().css("left","0");}).removeAttr("rel");
			newItem.animate({ 
				marginLeft: "0px",
			  }, 1500).attr("rel","active");
		}

	}
	$("#prevNews").hide();
	$("#nextNews").hide();
	if(newItem.prev(".inner").length > 0){$("#prevNews").show();}
	if(newItem.next(".inner").length > 0){$("#nextNews").show();}

}
*/



//Showcase Index functions

function revealShowcaseInfo() {
  var titletag = $(this).parent().parent().parent().parent().parent().children('div').children('h4');
  var summarytag = $(this).parent().parent().parent().parent().parent().children('div').children('p');
  var title = $(this).children('img').attr('title');
  var summary = $(this).children('img').attr('alt');
  if (summary.length > 0) {
	title = title + ':';
  }
  titletag.text(title);
  summarytag.text(summary);
}

function hideShowcaseInfo() {
  var titletag = $(this).parent().parent().parent().parent().parent().children('div').children('h4');
  var summarytag = $(this).parent().parent().parent().parent().parent().children('div').children('p');
  titletag.html('&nbsp;');
  summarytag.html('&nbsp;');
}



//Showcase Detail functions

function revealSlideShow() {

  //$('div#content').addClass('slideshow-mask');
  $('div#content').fadeTo(0, 0.1);
  if ($.browser.msie && ($.browser.version == '6.0')) {
	$('div#content div.headline').css('left', '47px');
	$('div#content div.headline').css('top', '45px');
	if ($('div.n1').length < 1) {
	  $('div#content-slideshow-container').css('left', '32px');
	  $('div#content-slideshow-container').css('top', '45px');
	}
  }
  if ($.browser.msie && ($.browser.version == '8.0' || $.browser.version == '7.0' || $.browser.version == '6.0')) {
    $('div#content div.headline').fadeTo(0, 0.1);
    $('div#content p.back-link').fadeTo(0, 0.1);
  }
  $('body').bind("click", hideSlideShow );
  
  window.scrollTo(0, 115);
  
  imagesrc = $(this).children('img').attr('src').split('?')[0];
  imagesrc += '?w=835&h=628';
  imagecaption = $(this).children('img').attr('alt');
  //console.debug(imagesrc);

  $('div#content-slideshow-image').html('<img src="' + imagesrc + '" alt="' + imagecaption + '" />');
  $('div#content-slideshow p.caption').html(imagecaption);
  
  $('div#content-slideshow-container').show();
  
  //TODO:
  // div#content-slideshow.style left: container width - imagewidth / 2
  // experiment with re-ordering this function
  
  return false;
  
}

function nextSlide() {
	
  current = $('div#content-slideshow-image').children('img').attr('src').split('?')[0];

  all = $('div.inner p a.slide img, div#content-body ul.thumbnails img');
  //console.debug(all);
  
  for (i=0; i<all.length; i++) {
	test = all[i].getAttribute('src').split('?')[0];
	//console.debug(test);
	if (current == test) {
      if ((i+1) == all.length)
        o = 0;
      else
        o = i+1;
	  imagesrc = all[o].getAttribute('src').split('?')[0];
	  imagesrc += '?w=835&h=628';
	  imagecaption = all[o].getAttribute('longdesc');
	  break;
	}
  }
  
  $('div#content-slideshow-image').html('<img src="' + imagesrc + '" alt="' + imagecaption + '" />');
  $('div#content-slideshow p.caption').html(imagecaption);

  return false;

}

function hideSlideShow() {
  $('div#content-slideshow-container').hide();
  //$('div#content').removeClass('slideshow-mask');
  $('div#content').fadeTo(0, 1);
  if ($.browser.msie && ($.browser.version == '6.0')) {
	$('div#content div.headline').css('left', 'auto');
	$('div#content div.headline').css('top', 'auto');
	$('div#content-slideshow-container').css('left', '70px');
    $('div#content-slideshow-container').css('top', '50px');
    $('div.showcase-detail p.back-link').css('right', '0px');
    $('div.showcase-detail p.back-link').css('padding-right', '12px');
  }
  if ($.browser.msie && ($.browser.version == '8.0' || $.browser.version == '7.0' || $.browser.version == '6.0')) {
    $('div#content div.headline').fadeTo(0, 1);
    $('div#content p.back-link').fadeTo(0, 1);
  }
  $('body').unbind("click", hideSlideShow );
}



//open external links in a new window

/*
**
** Id: external.js,v 1.3 2003/11/29 03:28:33 cpaul Exp $
** Source: /home/data/cvsroot/roslynoxley9/assets/external.js,v $
**
** the 'target' attribute is not XHTML compliant:
**
** <a href="link.html" target="_blank"> 
**
** however, the target parameter is DOM compliant,
** so a workaround is to use javascript to set
** the target for 'external' links
**
** as per: 
** http://www.sitepoint.com/article/1041/3
**
** 29-nov-2003 wrote externalLinksByHref function
**
*/



function externalLinksByRel() {
  if (!document.getElementsByTagName) return;
  var anchors = document.getElementsByTagName('a');
  for (var i=0; i<anchors.length; i++) {
    var anchor = anchors[i];
    if (anchor.getAttribute('href') && anchor.getAttribute('rel') == 'external')
      anchor.target = '_blank';
  }
}


function externalLinksByHref() {
  var base_url = (document.URL ? document.URL : document.location.href).substr(0,(document.URL ? document.URL : document.location.href).indexOf('/',8));
  if (document.getElementsByTagName) {
    var anchors = document.getElementsByTagName('a');
    for (var i=0; i<anchors.length; i++) {
      var anchor = anchors[i];
      if ((anchor.getAttribute('href').indexOf('http:\/\/')==0 || anchor.getAttribute('href').indexOf('https:\/\/')==0)
          && anchor.getAttribute('href').indexOf(base_url)<0) {
        anchor.target = '_blank';
      }
    }
  }
  else if (document.links) {
    var anchors = document.links;
    for (var i=anchors.length-1; i>=0; i--) {
      var anchor = anchors[i];
      if ((anchor.href.indexOf('http:\/\/')==0 || anchor.href.indexOf('https:\/\/')==0)
           && anchor.href.indexOf(base_url)<0) {
        anchor.target = '_blank';
      }
    } 
  }
}




/**
 * jquery.scrollable 1.0.5 - Scroll your HTML with eye candy.
 * 
 * Copyright (c) 2009 Tero Piirainen
 * http://flowplayer.org/tools/scrollable.html
 *
 * Dual licensed under MIT and GPL 2+ licenses
 * http://www.opensource.org/licenses
 *
 * Launch  : March 2008
 * Date: 2009-06-12 11:02:45 +0000 (Fri, 12 Jun 2009)
 * Revision: 1911 
 */
(function($) {
		
	// static constructs
	$.tools = $.tools || {version: {}};
	
	$.tools.version.scrollable = '1.0.5';
				
	var current = null;		

	
	// constructor
	function Scrollable(root, conf) {   

		// current instance
		var self = this;  
		if (!current) { current = self; }		
		
		// generic binding function
		function bind(name, fn) {
			$(self).bind(name, function(e, args)  {
				if (fn && fn.call(this, args.index) === false && args) {
					args.proceed = false;	
				}	
			});	
			
			return self;
		}
		
		// bind all callbacks from configuration
		$.each(conf, function(name, fn) {
			if ($.isFunction(fn)) { bind(name, fn); }
		});   
		
		
		// horizontal flag
		var horizontal = !conf.vertical;				
		
		// wrap (root elements for items)
		var wrap = $(conf.items, root);				
		
		// current index
		var index = 0;		
		
		function find(query, ctx) {
			return query.indexOf("#") != -1 ? $(query).eq(0) : ctx.siblings(query).eq(0);	
		}		
		
		// get handle to navigational elements
		var navi = find(conf.navi, root);
		var prev = find(conf.prev, root);
		var next = find(conf.next, root);
		var prevPage = find(conf.prevPage, root);
		var nextPage = find(conf.nextPage, root);
		
		
		// methods
		$.extend(self, {
			
			getIndex: function() {
				return index;	
			},
	
			getConf: function() {
				return conf;	
			},
			
			getSize: function() {
				return self.getItems().size();	
			},
	
			getPageAmount: function() {
				return Math.ceil(this.getSize() / conf.size); 	
			},
			
			getPageIndex: function() {
				return Math.ceil(index / conf.size);	
			},

			getRoot: function() {
				return root;	
			},
			
			getItemWrap: function() {
				return wrap;	
			},
			
			getItems: function() {
				return wrap.children();	
			},
			
			getVisibleItems: function() {
				return self.getItems().slice(index, index + conf.size);	
			},
			
			/* all seeking functions depend on this */		
			seekTo: function(i, time, fn) {
				
				// default speed
				if (time === undefined) { time = conf.speed; }
				
				// function given as second argument
				if ($.isFunction(time)) {
					fn = time;
					time = conf.speed;
				}
								
				if (i < 0) { i = 0; }				
				if (i > self.getSize() - conf.size) { return self; } 				

				var item = self.getItems().eq(i);					
				if (!item.length) { return self; }				
				
				
				// onBeforeSeek
				var p = {index: i, proceed: true};
				$(self).trigger("onBeforeSeek", p);				
				if (!p.proceed) { return self; }
									
				
				if (horizontal) {
 					var left = -item.position().left;					
					wrap.animate({left: left}, time, conf.easing, fn ? function() { fn.call(self); } : null);
					
				} else {
					var top = -item.position().top;										
					wrap.animate({top: top}, time, conf.easing, fn ? function() { fn.call(self); } : null);							
				}	
				
				
				// navi status update
				if (navi.length) {
					var klass = conf.activeClass;
					var page = Math.ceil(i / conf.size);
					page = Math.min(page, navi.children().length - 1);
					navi.children().removeClass(klass).eq(page).addClass(klass);
				} 
				
				// prev buttons disabled flag
				if (i === 0) {
					prev.add(prevPage).addClass(conf.disabledClass);					
				} else {
					prev.add(prevPage).removeClass(conf.disabledClass);
				}
								
				// next buttons disabled flag
				if (i >= self.getSize() - conf.size) {
					next.add(nextPage).addClass(conf.disabledClass);
				} else {
					next.add(nextPage).removeClass(conf.disabledClass);
				}				
				
				current = self;
				index = i;				
				
				// onSeek after index being updated
				$(self).trigger("onSeek", {index: i});				
				return self; 
			},			
			
				
			move: function(offset, time, fn) {
				var to = index + offset;
				if (conf.loop && to > (self.getSize() - conf.size)) {
					to = 0;	
				}
				return this.seekTo(to, time, fn);
			},
			
			next: function(time, fn) {
				return this.move(1, time, fn);	
			},
			
			prev: function(time, fn) {
				return this.move(-1, time, fn);	
			},
			
			movePage: function(offset, time, fn) {
				return this.move(conf.size * offset, time, fn);		
			},
			
			setPage: function(page, time, fn) {
				var size = conf.size;
				var index = size * page;
				var lastPage = index + size >= this.getSize(); 
				if (lastPage) {
					index = this.getSize() - conf.size;
				}
				return this.seekTo(index, time, fn);
			},
			
			prevPage: function(time, fn) {
				return this.setPage(this.getPageIndex() - 1, time, fn);
			},  
	
			nextPage: function(time, fn) {
				return this.setPage(this.getPageIndex() + 1, time, fn);
			}, 
			
			begin: function(time, fn) {
				return this.seekTo(0, time, fn);	
			},
			
			end: function(time, fn) {
				return this.seekTo(this.getSize() - conf.size, time, fn);	
			},
			
			reload: function() {
				return load();	
			},
			
			click: function(index, time, fn) {
				
				var item = self.getItems().eq(index);
				var klass = conf.activeClass;			
				
				// check that index is sane
				if (index < 0 || index >= this.getSize()) { return self; }
					
				
				// special case with two items
				if (conf.size == 2) {
					if (index == self.getIndex()) { index--; }
					self.getItems().removeClass(klass);
					item.addClass(klass);					
					return this.seekTo(index, time, fn);
				}
				

				if (!item.hasClass(klass)) {				
					self.getItems().removeClass(klass);
					item.addClass(klass);
					var delta = Math.floor(conf.size / 2);
					var to = index - delta;

					// next to last item must work
					if (to > self.getSize() - conf.size) { 
						to = self.getSize() - conf.size; 
					}
					
					if (to !== index) {
						return this.seekTo(to, time, fn);		
					}				 
				}
				
				return self;
			},

			// callback functions
			onBeforeSeek: function(fn) {
				return bind("onBeforeSeek", fn); 		
			},
			
			onSeek: function(fn) {
				return bind("onSeek", fn); 		
			}
			
		});
	
		
		// mousewheel
		if ($.isFunction($.fn.mousewheel)) { 
			root.bind("mousewheel.scrollable", function(e, delta)  {
				// opera goes to opposite direction
				var step = $.browser.opera ? 1 : -1;
				
				self.move(delta > 0 ? step : -step, 50);
				return false;
			});
		}  
		
		// prev button		
		prev.addClass(conf.disabledClass).click(function() { 
			self.prev(); 
		});
		

		// next button
		next.click(function() { 
			self.next(); 
		});
		
		// prev page button
		nextPage.click(function() { 
			self.nextPage(); 
		});
		

		// next page button
		prevPage.addClass(conf.disabledClass).click(function() { 
			self.prevPage(); 
		});		

		
		// keyboard
		if (conf.keyboard) {			

			// keyboard works on one instance at the time. thus we need to unbind first
			$(document).unbind("keydown.scrollable").bind("keydown.scrollable", function(evt) {
				
				var el = current;	
				if (!el || evt.altKey || evt.ctrlKey) { return; }
					
				if (horizontal && (evt.keyCode == 37 || evt.keyCode == 39)) {					
					el.move(evt.keyCode == 37 ? -1 : 1);
					return evt.preventDefault();
				}	
				
				if (!horizontal && (evt.keyCode == 38 || evt.keyCode == 40)) {
					el.move(evt.keyCode == 38 ? -1 : 1);
					return evt.preventDefault();
				}
				
				return true;
				
			});	 
		}

		// navi 			
		function load() {			
	
			// generate new entries
			if (navi.is(":empty") || navi.data("me") == self) {
				
				navi.empty();
				navi.data("me", self);
				
				for (var i = 0; i < self.getPageAmount(); i++) {		
					
					var item = $("<" + conf.naviItem + "/>").attr("href", i).click(function(e) {							
						var el = $(this);
						el.parent().children().removeClass(conf.activeClass);
						el.addClass(conf.activeClass);
						self.setPage(el.attr("href"));
						return e.preventDefault();
					});
					
					if (i === 0) { item.addClass(conf.activeClass); }
					navi.append(item);					
				}
				
			// assign onClick events to existing entries
			} else {
				
				// find a entries first -> syntaxically correct
				var els = navi.children(); 
				
				els.each(function(i)  {
					var item = $(this);
					item.attr("href", i);
					if (i === 0) { item.addClass(conf.activeClass); }
					
					item.click(function() {
						navi.find("." + conf.activeClass).removeClass(conf.activeClass);
						item.addClass(conf.activeClass);
						self.setPage(item.attr("href"));
					});
					
				});
			}
			
			
			// item.click()
			if (conf.clickable) {
				self.getItems().each(function(index, arg) {
					var el = $(this);
					if (!el.data("set")) {
						el.bind("click.scrollable", function() {
							self.click(index);		
						});
						el.data("set", true);
					}
				});				
			}
			
			
			// hover
			if (conf.hoverClass) {
				self.getItems().hover(function()  {
					$(this).addClass(conf.hoverClass);		
				}, function() {
					$(this).removeClass(conf.hoverClass);	
				});
			}			
			
			return self;
		}
		
		load();
		
		
		// interval stuff
		var timer = null;

		function setTimer() {

			// do not start additional timer if already exists
			if (timer) { return; }
			
			// construct new timer
			timer = setInterval(function()  {
					
				// check if interval is being changed dynamically during runtime
				if (conf.interval === 0) {					
					clearInterval(timer);
					timer = 0;
					return;
				}			
				
				self.next();				
			}, conf.interval);
		}	
		
		if (conf.interval > 0) {			
			
			// when mouse enters, autoscroll stops
			root.hover(function() {			
				clearInterval(timer);		
				timer = 0;
				
			}, function() {		
				setTimer();	
			});
			
			setTimer();	
		}
		
	} 

		
	// jQuery plugin implementation
	$.fn.scrollable = function(conf) { 
			
		// already constructed --> return API
		var el = this.eq(typeof conf == 'number' ? conf : 0).data("scrollable");
		if (el) { return el; }		
		
 
		var opts = {
			
			// basics
			size: 5,
			vertical:false,			
			clickable: true,
			loop: false,
			interval: 0,			
			speed: 400,
			keyboard: true,			
			
			// other
			activeClass:'active',
			disabledClass: 'disabled',
			hoverClass: null,			
			easing: 'swing',
			
			// navigational elements
			items: '.items',
			prev: '.prev',
			next: '.next',
			prevPage: '.prevPage',
			nextPage: '.nextPage',			
			navi: '.navi',
			naviItem: 'a',
			api:false,

			
			// callbacks
			onBeforeSeek: null,
			onSeek: null
			
		}; 
		
		
		$.extend(opts, conf);		
		
		this.each(function() {			
			el = new Scrollable($(this), opts);
			$(this).data("scrollable", el);	
		});
		
		return opts.api ? el: this; 
		
	};
			
	
})(jQuery);













/* 
 * 
 * 
/**
 * jquery.scrollable 0.11. Making HTML elements scroll.
 * 
 * http://flowplayer.org/tools/scrollable.html
 *
 * Copyright (c) 2008 Tero Piirainen (tero@flowplayer.org)
 *
 * Released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 * 
 * >> Basically you can do anything you want but leave this header as is <<
 *
 * Since  : 0.01 - 03/01/2008
 * Version: 0.11 - 05/29/2008

(function($) {
		
	// plugin initialization
	$.fn.extend({
		scrollable: function(arg1, arg2, arg3) { 
			
			return this.each(function() {
				if (typeof arg1 == "string") {
					var el = $.data(this, "scrollable");
					el[arg1].apply(el, [arg2, arg3]);
					
				} else { 
					new $.scrollable(this, arg1, arg2);
				}
			});
		}		
	});
		
	// constructor
	$.scrollable = function(el, opts) {   
			
		// store this instance
		$.data(el, "scrollable", this);
		
		this.init(el, opts); 
	};
	
	
	// methods
	$.extend($.scrollable.prototype, { 
			
		init: function(el, config)  {
			 
			// current instance
			var self = this;  
			
			var opts = {								
				size: 5,
				horizontal:false,				
				activeClass:'active',
				speed: 300,
				onSeek: null,
				
				// jquery selectors
				items: '.items',
				prev:'.prev',
				next:'.next',
				navi:'.navi',
				naviItem:'span'
			}; 
	
			this.opts = $.extend(opts, config); 			
	
			// root / itemRoot
			var root = this.root = $(el);			
			var itemRoot = $(opts.items, root);			
			if (!itemRoot.length) itemRoot = root;			
				
			// wrap itemRoot.children() inside container
			itemRoot.css({position:'relative', overflow:'hidden', visibility:'visible'});
			itemRoot.children().wrapAll('<div class="__scrollable" style="position:absolute"/>');
			
			this.wrap = itemRoot.children(":first");
			this.wrap.css(opts.horizontal ? "width" : "height", "200000em").after('<br clear="all"/>');			
			this.items = this.wrap.children();
			this.index = 0;

			
			// set height based on size
			if (opts.horizontal) {
				itemRoot.width(opts.size * (this.items.eq(1).offset().left - this.items.eq(0).offset().left) -2);	
			} else {
				itemRoot.height(opts.size * (this.items.eq(1).offset().top - this.items.eq(0).offset().top) -2);	
			} 
	
			// mousewheel
			if ($.isFunction($.fn.mousewheel)) { 
				root.bind("mousewheel.scrollable", function(event, delta)  { 
					self.move(-delta, 50);		
					return false;
				});
			} 
	
			// keyboard
			$(window).bind("keypress.scrollable", function(evt) {

				if ($(evt.target).parents(".__scrollable").length) {
					
					if (opts.horizontal && (evt.keyCode == 37 || evt.keyCode == 39)) {
						self.move(evt.keyCode == 37 ? -1 : 1);
						return false;
					}	
					
					if (!opts.horizontal && (evt.keyCode == 38 || evt.keyCode == 40)) {
						self.move(evt.keyCode == 38 ? -1 : 1);
						return false;
					}
				}
				
				return true;
				
			});	
			
			
			// item.click()
			this.items.each(function(index, arg) {
				$(this).bind("click.scrollable", function() {
					self.click(index);		
				});
			});

			this.activeIndex = 0;
			
			// prev
			$(opts.prev, root).click(function() { self.prev() });
			

			// next
			$(opts.next, root).click(function() { self.next() });
			

			// navi 			
			$(opts.navi, root).each(function() { 				
				var navi = $(this);
				
				var status = self.getStatus();
				
				// generate new entries
				if (navi.is(":empty")) {
					for (var i = 0; i < status.pages; i++) {		
						
						var item = $("<" + opts.naviItem + "/>").attr("page", i).click(function() {							
							var el = $(this);
							el.parent().children().removeClass(opts.activeClass);
							el.addClass(opts.activeClass);
							self.setPage(el.attr("page"));
							
						});
						
						if (i == 0) item.addClass(opts.activeClass);
						navi.append(item);					
					}
					
				// assign onClick events to existing entries
				} else {
					
					navi.children().each(function(i)  {
						var item = $(this);
						item.attr("page", i);
						if (i == 0) item.addClass(opts.activeClass);
						
						item.click(function() {
							item.parent().children().removeClass(opts.activeClass);
							item.addClass(opts.activeClass);
							self.setPage(item.attr("page"));
						});
						
					});
				}
				
			});			
			
		},
		

		click: function(index) {

			var item = this.items.eq(index);
			var klass = this.opts.activeClass;
			
			if (!item.hasClass(klass) && (index >= 0 || index < this.items.size())) { 
				
				var prev = this.items.eq(this.activeIndex).removeClass(klass);
				item.addClass(klass);   
				
				this.seekTo(index - Math.floor(this.opts.size / 2));
				this.activeIndex = index;
			}  
		},
		
		getStatus: function() {
			var len =  this.items.size();
			var s = {
				length: len, 
				index: this.index, 
				size: this.opts.size,
				pages: Math.floor(len / this.opts.size),
				page: Math.floor(this.index / this.opts.size)
			};

			return s;
		}, 

		
		// all other seeking functions depend on this generic seeking function		
		seekTo: function(index, time) {
			
			if (index < 0) index = 0;			
			index = Math.min(index, this.items.length - this.opts.size);			
			
			var item = this.items.eq(index);			
			if (item.size() == 0) return false; 			
			this.index = index;

			
			if (this.opts.horizontal) {
				var left = this.wrap.offset().left - item.offset().left;				
				this.wrap.animate({left: left}, time || this.opts.speed);
				
			} else {
				var top = this.wrap.offset().top - item.offset().top;
				this.wrap.animate({top: top}, time || this.opts.speed);							
			}

			// custom onSeek callback
			if ($.isFunction(this.opts.onSeek)) {
				this.opts.onSeek.call(this.getStatus());
			}
			
			// navi status update
			var navi = $(this.opts.navi, this.root);
			
			if (navi.length) {
				var klass = this.opts.activeClass;
				var page = Math.round(index / this.opts.size);
				navi.children().removeClass(klass).eq(page).addClass(klass);
			}
			
			
			return true; 
		},
		
			
		move: function(offset, time) {
			this.seekTo(this.index + offset, time);
		},
		
		next: function(time) {
			this.move(1, time);	
		},
		
		prev: function(time) {
			this.move(-1, time);	
		},
		
		movePage: function(offset, time) {
			this.move(this.opts.size * offset, time);		
		},
		
		setPage: function(index, time) {
			this.seekTo(this.opts.size * index, time);
		},
		
		prevPage: function(time) {
			var page = Math.floor(this.index / this.opts.size);
			this.seekTo(this.opts.size * (page-1), time);
		},  

		nextPage: function(time) {
			var page = Math.floor(this.index / this.opts.size);
			this.seekTo(this.opts.size * (page+1), time);
		}, 
		
		begin: function(time) {
			this.seekTo(0, time);	
		},
		
		end: function(time) {
			this.seekTo(this.items.size() - this.opts.size, time);	
		}

		
	});  
	
})(jQuery);


*/



