/*

[js] sticky package 04:21:25 23/02/12

15:50:34 10/01/11 - jquery.colorbox.js - 23K
10:09:28 27/09/10 - jquery.jcarousel.js - 14K
10:09:28 27/09/10 - jquery.innerfade.js - 8K
15:53:16 12/01/11 - javalib.js - 18K

*/

/* jquery.colorbox.js */

// ColorBox v1.3.11 - a full featured, light-weight, customizable lightbox based on jQuery 1.3
// Copyright (c) 2010 Jack Moore - jack@colorpowered.com
// Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
(function ($, window) {
	
	var
	// ColorBox Default Settings.	
	// See http://colorpowered.com/colorbox for details.
	defaults = {
		transition: "elastic",
		speed: 300,
		width: false,
		initialWidth: "600",
		innerWidth: false,
		maxWidth: false,
		height: false,
		initialHeight: "450",
		innerHeight: false,
		maxHeight: false,
		scalePhotos: true,
		scrolling: true,
		inline: false,
		html: false,
		iframe: false,
		photo: false,
		href: false,
		title: false,
		rel: false,
		opacity: 0.9,
		preloading: true,
		current: "image {current} of {total}",
		previous: "previous",
		next: "next",
		close: "close",
		open: false,
		loop: true,
		slideshow: false,
		slideshowAuto: true,
		slideshowSpeed: 2500,
		slideshowStart: "start slideshow",
		slideshowStop: "stop slideshow",
		onOpen: false,
		onLoad: false,
		onComplete: false,
		onCleanup: false,
		onClosed: false,
		overlayClose: true,		
		escKey: true,
		arrowKey: true
	},
	
	// Abstracting the HTML and event identifiers for easy rebranding
	colorbox = 'colorbox',
	prefix = 'cbox',
	
	// Events	
	event_open = prefix + '_open',
	event_load = prefix + '_load',
	event_complete = prefix + '_complete',
	event_cleanup = prefix + '_cleanup',
	event_closed = prefix + '_closed',
	event_purge = prefix + '_purge',
	event_loaded = prefix + '_loaded',
	
	// Special Handling for IE
	isIE = $.browser.msie && !$.support.opacity, // feature detection alone gave a false positive on at least one phone browser and on some development versions of Chrome.
	isIE6 = isIE && $.browser.version < 7,
	event_ie6 = prefix + '_IE6',

	// Cached jQuery Object Variables
	$overlay,
	$box,
	$wrap,
	$content,
	$topBorder,
	$leftBorder,
	$rightBorder,
	$bottomBorder,
	$related,
	$window,
	$loaded,
	$loadingBay,
	$loadingOverlay,
	$title,
	$current,
	$slideshow,
	$next,
	$prev,
	$close,

	// Variables for cached values or use across multiple functions
	interfaceHeight,
	interfaceWidth,
	loadedHeight,
	loadedWidth,
	element,
	bookmark,
	index,
	settings,
	open,
	active,
	closing = false,
	
	publicMethod,
	boxElement = prefix + 'Element';
	
	// ****************
	// HELPER FUNCTIONS
	// ****************

	// jQuery object generator to reduce code size
	function $div(id, css) { 
		id = id ? ' id="' + prefix + id + '"' : '';
		css = css ? ' style="' + css + '"' : '';
		return $('<div' + id + css + '/>');
	}

	// Convert % values to pixels
	function setSize(size, dimension) {
		dimension = dimension === 'x' ? $window.width() : $window.height();
		return (typeof size === 'string') ? Math.round((/%/.test(size) ? (dimension / 100) * parseInt(size, 10) : parseInt(size, 10))) : size;
	}
	
	// Checks an href to see if it is a photo.
	// There is a force photo option (photo: true) for hrefs that cannot be matched by this regex.
	function isImage(url, target) {
		url = $.isFunction(url) ? url.call(target) : url;
		return settings.photo || /\.(gif|png|jpg|jpeg|bmp)(?:\?([^#]*))?(?:#(\.*))?$/i.test(url);
	}
	
	// Assigns function results to their respective settings.  This allows functions to be used as values.
	function process(settings) {
		for (var i in settings) {
			if ($.isFunction(settings[i]) && i.substring(0, 2) !== 'on') { // checks to make sure the function isn't one of the callbacks, they will be handled at the appropriate time.
			    settings[i] = settings[i].call(element);
			}
		}
		settings.rel = settings.rel || element.rel || 'nofollow';
		settings.href = settings.href || $(element).attr('href');
		settings.title = settings.title || element.title;
		return settings;
	}

	function trigger(event, callback) {
		if (callback) {
			callback.call(element);
		}
		$.event.trigger(event);
	}

	// Slideshow functionality
	function slideshow() {
		var
		timeOut,
		className = prefix + "Slideshow_",
		click = "click." + prefix,
		start,
		stop,
		clear;
		
		if (settings.slideshow && $related[1]) {
			start = function () {
				$slideshow
					.text(settings.slideshowStop)
					.unbind(click)
					.bind(event_complete, function () {
						if (index < $related.length - 1 || settings.loop) {
							timeOut = setTimeout(publicMethod.next, settings.slideshowSpeed);
						}
					})
					.bind(event_load, function () {
						clearTimeout(timeOut);	
					})
					.one(click, stop);
				$box.removeClass(className + "off").addClass(className + "on");
				timeOut = setTimeout(publicMethod.next, settings.slideshowSpeed);
			};
			
			stop = function () {
				clearTimeout(timeOut);
				$slideshow
					.text(settings.slideshowStart)
					.unbind(event_complete + ' ' + event_load + ' ' + click)
					.one(click, start);
				$box.removeClass(className + "on").addClass(className + "off");
			};
			
			$slideshow.bind(event_closed, function () {
				clearTimeout(timeOut);
			});
			
			if ($box.hasClass(className + "on") || (settings.slideshowAuto && !$box.hasClass(className + "off"))) {
				start();
			} else {
				stop();
			}
		}
	}

	function launch(elem) {
		if (!closing) {
			
			element = elem;
			
			settings = process($.extend({}, $.data(element, colorbox)));
			
			$related = $(element);
			
			index = 0;
			
			if (settings.rel !== 'nofollow') {
				$related = $('.' + boxElement).filter(function () {
					var relRelated = $.data(this, colorbox).rel || this.rel;
					return (relRelated === settings.rel);
				});
				index = $related.index(element);
				
				// Check direct calls to ColorBox.
				if (index === -1) {
					$related = $related.add(element);
					index = $related.length - 1;
				}
			}
			
			if (!open) {
				open = active = true; // Prevents the page-change action from queuing up if the visitor holds down the left or right keys.
				
				$box.show();
				
				bookmark = element;
				
				try {
					bookmark.blur(); // Remove the focus from the calling element.
				}catch (e) {}
				
				// +settings.opacity avoids a problem in IE when using non-zero-prefixed-string-values, like '.5'
				$overlay.css({"opacity": +settings.opacity, "cursor": settings.overlayClose ? "pointer" : "auto"}).show();
				
				// Opens inital empty ColorBox prior to content being loaded.
				settings.w = setSize(settings.initialWidth, 'x');
				settings.h = setSize(settings.initialHeight, 'y');
				publicMethod.position(0);
				
				if (isIE6) {
					$window.bind('resize.' + event_ie6 + ' scroll.' + event_ie6, function () {
						$overlay.css({width: $window.width(), height: $window.height(), top: $window.scrollTop(), left: $window.scrollLeft()});
					}).trigger('scroll.' + event_ie6);
				}
				
				trigger(event_open, settings.onOpen);
				
				$current.add($prev).add($next).add($slideshow).add($title).hide();
				
				$close.html(settings.close).show();
			}
			
			publicMethod.load(true);
		}
	}

	// ****************
	// PUBLIC FUNCTIONS
	// Usage format: $.fn.colorbox.close();
	// Usage from within an iframe: parent.$.fn.colorbox.close();
	// ****************
	
	publicMethod = $.fn[colorbox] = $[colorbox] = function (options, callback) {
		var $this = this, autoOpen;
		
		if (!$this[0] && $this.selector) { // if a selector was given and it didn't match any elements, go ahead and exit.
			return $this;
		}
		
		options = options || {};
		
		if (callback) {
			options.onComplete = callback;
		}
		
		if (!$this[0] || $this.selector === undefined) { // detects $.colorbox() and $.fn.colorbox()
			$this = $('<a/>');
			options.open = true; // assume an immediate open
		}
		
		$this.each(function () {
			$.data(this, colorbox, $.extend({}, $.data(this, colorbox) || defaults, options));
			$(this).addClass(boxElement);
		});
		
		autoOpen = options.open;
		
		if ($.isFunction(autoOpen)) {
			autoOpen = autoOpen.call($this);
		}
		
		if (autoOpen) {
			launch($this[0]);
		}
		
		return $this;
	};

	// Initialize ColorBox: store common calculations, preload the interface graphics, append the html.
	// This preps colorbox for a speedy open when clicked, and lightens the burdon on the browser by only
	// having to run once, instead of each time colorbox is opened.
	publicMethod.init = function () {
		// Create & Append jQuery Objects
		$window = $(window);
		$box = $div().attr({id: colorbox, 'class': isIE ? prefix + 'IE' : ''});
		$overlay = $div("Overlay", isIE6 ? 'position:absolute' : '').hide();
		
		$wrap = $div("Wrapper");
		$content = $div("Content").append(
			$loaded = $div("LoadedContent", 'width:0; height:0; overflow:hidden'),
			$loadingOverlay = $div("LoadingOverlay").add($div("LoadingGraphic")),
			$title = $div("Title"),
			$current = $div("Current"),
			$next = $div("Next"),
			$prev = $div("Previous"),
			$slideshow = $div("Slideshow").bind(event_open, slideshow),
			$close = $div("Close")
		);
		$wrap.append( // The 3x3 Grid that makes up ColorBox
			$div().append(
				$div("TopLeft"),
				$topBorder = $div("TopCenter"),
				$div("TopRight")
			),
			$div(false, 'clear:left').append(
				$leftBorder = $div("MiddleLeft"),
				$content,
				$rightBorder = $div("MiddleRight")
			),
			$div(false, 'clear:left').append(
				$div("BottomLeft"),
				$bottomBorder = $div("BottomCenter"),
				$div("BottomRight")
			)
		).children().children().css({'float': 'left'});
		
		$loadingBay = $div(false, 'position:absolute; width:9999px; visibility:hidden; display:none');
		
		$('body').prepend($overlay, $box.append($wrap, $loadingBay));
		
		$content.children()
		.hover(function () {
			$(this).addClass('hover');
		}, function () {
			$(this).removeClass('hover');
		}).addClass('hover');
		
		// Cache values needed for size calculations
		interfaceHeight = $topBorder.height() + $bottomBorder.height() + $content.outerHeight(true) - $content.height();//Subtraction needed for IE6
		interfaceWidth = $leftBorder.width() + $rightBorder.width() + $content.outerWidth(true) - $content.width();
		loadedHeight = $loaded.outerHeight(true);
		loadedWidth = $loaded.outerWidth(true);
		
		// Setting padding to remove the need to do size conversions during the animation step.
		$box.css({"padding-bottom": interfaceHeight, "padding-right": interfaceWidth}).hide();
		
		// Setup button events.
		$next.click(publicMethod.next);
		$prev.click(publicMethod.prev);
		$close.click(publicMethod.close);
		
		// Adding the 'hover' class allowed the browser to load the hover-state
		// background graphics.  The class can now can be removed.
		$content.children().removeClass('hover');
		
		$('.' + boxElement).live('click', function (e) {
			// checks to see if it was a non-left mouse-click and for clicks modified with ctrl, shift, or alt.
			if (!((e.button !== 0 && typeof e.button !== 'undefined') || e.ctrlKey || e.shiftKey || e.altKey)) {
				e.preventDefault();
				launch(this);
			}
		});
		
		$overlay.click(function () {
			if (settings.overlayClose) {
				publicMethod.close();
			}
		});
		
		// Set Navigation Key Bindings
		$(document).bind("keydown", function (e) {
			if (open && settings.escKey && e.keyCode === 27) {
				e.preventDefault();
				publicMethod.close();
			}
			if (open && settings.arrowKey && !active && $related[1]) {
				if (e.keyCode === 37 && (index || settings.loop)) {
					e.preventDefault();
					$prev.click();
				} else if (e.keyCode === 39 && (index < $related.length - 1 || settings.loop)) {
					e.preventDefault();
					$next.click();
				}
			}
		});
	};
	
	publicMethod.remove = function () {
		$box.add($overlay).remove();
		$('.' + boxElement).die('click').removeData(colorbox).removeClass(boxElement);
	};

	publicMethod.position = function (speed, loadedCallback) {
		var
		animate_speed,
		// keeps the top and left positions within the browser's viewport.
		posTop = Math.max(document.documentElement.clientHeight - settings.h - loadedHeight - interfaceHeight, 0) / 2 + $window.scrollTop(),
		posLeft = Math.max($window.width() - settings.w - loadedWidth - interfaceWidth, 0) / 2 + $window.scrollLeft();
		
		// setting the speed to 0 to reduce the delay between same-sized content.
		animate_speed = ($box.width() === settings.w + loadedWidth && $box.height() === settings.h + loadedHeight) ? 0 : speed;
		
		// this gives the wrapper plenty of breathing room so it's floated contents can move around smoothly,
		// but it has to be shrank down around the size of div#colorbox when it's done.  If not,
		// it can invoke an obscure IE bug when using iframes.
		$wrap[0].style.width = $wrap[0].style.height = "9999px";
		
		function modalDimensions(that) {
			// loading overlay height has to be explicitly set for IE6.
			$topBorder[0].style.width = $bottomBorder[0].style.width = $content[0].style.width = that.style.width;
			$loadingOverlay[0].style.height = $loadingOverlay[1].style.height = $content[0].style.height = $leftBorder[0].style.height = $rightBorder[0].style.height = that.style.height;
		}
		
		$box.dequeue().animate({width: settings.w + loadedWidth, height: settings.h + loadedHeight, top: posTop, left: posLeft}, {
			duration: animate_speed,
			complete: function () {
				modalDimensions(this);
				
				active = false;
				
				// shrink the wrapper down to exactly the size of colorbox to avoid a bug in IE's iframe implementation.
				$wrap[0].style.width = (settings.w + loadedWidth + interfaceWidth) + "px";
				$wrap[0].style.height = (settings.h + loadedHeight + interfaceHeight) + "px";
				
				if (loadedCallback) {
					loadedCallback();
				}
			},
			step: function () {
				modalDimensions(this);
			}
		});
	};

	publicMethod.resize = function (options) {
		if (open) {
			options = options || {};
			
			if (options.width) {
				settings.w = setSize(options.width, 'x') - loadedWidth - interfaceWidth;
			}
			if (options.innerWidth) {
				settings.w = setSize(options.innerWidth, 'x');
			}
			$loaded.css({width: settings.w});
			
			if (options.height) {
				settings.h = setSize(options.height, 'y') - loadedHeight - interfaceHeight;
			}
			if (options.innerHeight) {
				settings.h = setSize(options.innerHeight, 'y');
			}
			if (!options.innerHeight && !options.height) {				
				var $child = $loaded.wrapInner("<div style='overflow:auto'></div>").children(); // temporary wrapper to get an accurate estimate of just how high the total content should be.
				settings.h = $child.height();
				$child.replaceWith($child.children()); // ditch the temporary wrapper div used in height calculation
			}
			$loaded.css({height: settings.h});
			
			publicMethod.position(settings.transition === "none" ? 0 : settings.speed);
		}
	};

	publicMethod.prep = function (object) {
		if (!open) {
			return;
		}
		
		var photo,
		speed = settings.transition === "none" ? 0 : settings.speed;
		
		$window.unbind('resize.' + prefix);
		$loaded.remove();
		$loaded = $div('LoadedContent').html(object);
		
		function getWidth() {
			settings.w = settings.w || $loaded.width();
			settings.w = settings.mw && settings.mw < settings.w ? settings.mw : settings.w;
			return settings.w;
		}
		function getHeight() {
			settings.h = settings.h || $loaded.height();
			settings.h = settings.mh && settings.mh < settings.h ? settings.mh : settings.h;
			return settings.h;
		}
		
		$loaded.hide()
		.appendTo($loadingBay.show())// content has to be appended to the DOM for accurate size calculations.
		.css({width: getWidth(), overflow: settings.scrolling ? 'auto' : 'hidden'})
		.css({height: getHeight()})// sets the height independently from the width in case the new width influences the value of height.
		.prependTo($content);
		
		$loadingBay.hide();
		
		// floating the IMG removes the bottom line-height and fixed a problem where IE miscalculates the width of the parent element as 100% of the document width.
		$('#' + prefix + 'Photo').css({cssFloat: 'none', marginLeft: 'auto', marginRight: 'auto'});
		
		// Hides SELECT elements in IE6 because they would otherwise sit on top of the overlay.
		if (isIE6) {
			$('select').not($box.find('select')).filter(function () {
				return this.style.visibility !== 'hidden';
			}).css({'visibility': 'hidden'}).one(event_cleanup, function () {
				this.style.visibility = 'inherit';
			});
		}
				
		function setPosition(s) {
			var prev, prevSrc, next, nextSrc, total = $related.length, loop = settings.loop;
			publicMethod.position(s, function () {
				function defilter() {
					if (isIE) {
						//IE adds a filter when ColorBox fades in and out that can cause problems if the loaded content contains transparent pngs.
						$box[0].style.filter = false;
					}
				}
				
				if (!open) {
					return;
				}
				
				if (isIE) {
					//This fadeIn helps the bicubic resampling to kick-in.
					if (photo) {
						$loaded.fadeIn(100);
					}
				}
				
				$loaded.show();
				
				trigger(event_loaded);
				
				$title.show().html(settings.title);
				
				if (total > 1) { // handle grouping
					$current.html(settings.current.replace(/\{current\}/, index + 1).replace(/\{total\}/, total)).show();
					
					$next[(loop || index < total - 1) ? "show" : "hide"]().html(settings.next);
					$prev[(loop || index) ? "show" : "hide"]().html(settings.previous);
					
					prev = index ? $related[index - 1] : $related[total - 1];
					next = index < total - 1 ? $related[index + 1] : $related[0];
					
					if (settings.slideshow) {
						$slideshow.show();
					}
					
					// Preloads images within a rel group
					if (settings.preloading) {
						nextSrc = $.data(next, colorbox).href || next.href;
						prevSrc = $.data(prev, colorbox).href || prev.href;
						
						if (isImage(nextSrc, next)) {
							$('<img/>')[0].src = nextSrc;
						}
						
						if (isImage(prevSrc, prev)) {
							$('<img/>')[0].src = prevSrc;
						}
					}
				}
				
				$loadingOverlay.hide();
				
				if (settings.transition === 'fade') {
					$box.fadeTo(speed, 1, function () {
						defilter();
					});
				} else {
					defilter();
				}
				
				$window.bind('resize.' + prefix, function () {
					publicMethod.position(0);
				});
				
				trigger(event_complete, settings.onComplete);
			});
		}
		
		if (settings.transition === 'fade') {
			$box.fadeTo(speed, 0, function () {
				setPosition(0);
			});
		} else {
			setPosition(speed);
		}
	};

	publicMethod.load = function (launched) {
		var href, img, setResize, prep = publicMethod.prep;
		
		active = true;
		element = $related[index];
		
		if (!launched) {
			settings = process($.extend({}, $.data(element, colorbox)));
		}
		
		trigger(event_purge);
		
		trigger(event_load, settings.onLoad);
		
		settings.h = settings.height ?
				setSize(settings.height, 'y') - loadedHeight - interfaceHeight :
				settings.innerHeight && setSize(settings.innerHeight, 'y');
		
		settings.w = settings.width ?
				setSize(settings.width, 'x') - loadedWidth - interfaceWidth :
				settings.innerWidth && setSize(settings.innerWidth, 'x');
		
		// Sets the minimum dimensions for use in image scaling
		settings.mw = settings.w;
		settings.mh = settings.h;
		
		// Re-evaluate the minimum width and height based on maxWidth and maxHeight values.
		// If the width or height exceed the maxWidth or maxHeight, use the maximum values instead.
		if (settings.maxWidth) {
			settings.mw = setSize(settings.maxWidth, 'x') - loadedWidth - interfaceWidth;
			settings.mw = settings.w && settings.w < settings.mw ? settings.w : settings.mw;
		}
		if (settings.maxHeight) {
			settings.mh = setSize(settings.maxHeight, 'y') - loadedHeight - interfaceHeight;
			settings.mh = settings.h && settings.h < settings.mh ? settings.h : settings.mh;
		}
		
		href = settings.href;
		
		$loadingOverlay.show();
		
		if (settings.inline) {
			// Inserts an empty placeholder where inline content is being pulled from.
			// An event is bound to put inline content back when ColorBox closes or loads new content.
			$div().hide().insertBefore($(href)[0]).one(event_purge, function () {
				$(this).replaceWith($loaded.children());
			});
			prep($(href));
		} else if (settings.iframe) {
			// IFrame element won't be added to the DOM until it is ready to be displayed,
			// to avoid problems with DOM-ready JS that might be trying to run in that iframe.
			$box.one(event_loaded, function () {
				var $iframe = $("<iframe name='" + new Date().getTime() + "' frameborder=0" + (settings.scrolling ? "" : " scrolling='no'") + (isIE ? " allowtransparency='true'" : '') + " style='width:100%; height:100%; border:0; display:block;'/>");
				$iframe[0].src = settings.href;
				$iframe.appendTo($loaded).one(event_purge, function () {
					$iframe[0].src = 'about:blank';
				});
			});
			
			prep(" ");
		} else if (settings.html) {
			prep(settings.html);
		} else if (isImage(href, element)) {
			img = new Image();
			img.onload = function () {
				var percent;
				img.onload = null;
				img.id = prefix + 'Photo';
				$(img).css({border: 'none', display: 'block', cssFloat: 'left'});
				if (settings.scalePhotos) {
					setResize = function () {
						img.height -= img.height * percent;
						img.width -= img.width * percent;	
					};
					if (settings.mw && img.width > settings.mw) {
						percent = (img.width - settings.mw) / img.width;
						setResize();
					}
					if (settings.mh && img.height > settings.mh) {
						percent = (img.height - settings.mh) / img.height;
						setResize();
					}
				}
				
				if (settings.h) {
					img.style.marginTop = Math.max(settings.h - img.height, 0) / 2 + 'px';
				}
				
				if ($related[1] && (index < $related.length - 1 || settings.loop)) {
					$(img).css({cursor: 'pointer'}).click(publicMethod.next);
				}
				
				if (isIE) {
					img.style.msInterpolationMode = 'bicubic';
				}
				
				setTimeout(function () { // Chrome will sometimes report a 0 by 0 size if there isn't pause in execution
					prep(img);
				}, 1);
			};
			
			setTimeout(function () { // Opera 10.6+ will sometimes load the src before the onload function is set
				img.src = href;
			}, 1);
			
		} else {
			$div().appendTo($loadingBay).load(href, function (data, status, xhr) {
				prep(status === 'error' ? 'Request unsuccessful: ' + xhr.statusText : this);
			});
		}
	};

	// Navigates to the next page/image in a set.
	publicMethod.next = function () {
		if (!active) {
			index = index < $related.length - 1 ? index + 1 : 0;
			publicMethod.load();
		}
	};
	
	publicMethod.prev = function () {
		if (!active) {
			index = index ? index - 1 : $related.length - 1;
			publicMethod.load();
		}
	};

	// Note: to use this within an iframe use the following format: parent.$.fn.colorbox.close();
	publicMethod.close = function () {
		if (open && !closing) {
			closing = true;
			
			open = false;
			
			trigger(event_cleanup, settings.onCleanup);
			
			$window.unbind('.' + prefix + ' .' + event_ie6);
			
			$overlay.fadeTo('fast', 0);
			
			$box.stop().fadeTo('fast', 0, function () {
				
				trigger(event_purge);
				
				$loaded.remove();
				
				$box.add($overlay).css({'opacity': 1, cursor: 'auto'}).hide();
				
				try {
					bookmark.focus();
				} catch (e) {
					// do nothing
				}
				
				setTimeout(function () {
					closing = false;
					trigger(event_closed, settings.onClosed);
				}, 1);
			});
		}
	};

	// A method for fetching the current element ColorBox is referencing.
	// returns a jQuery object.
	publicMethod.element = function () {
		return $(element);
	};

	publicMethod.settings = defaults;

	// Initializes ColorBox when the DOM has loaded
	$(publicMethod.init);

}(jQuery, this));

/* jquery.jcarousel.js */

(function($){$.fn.jcarousel=function(o){return this.each(function(){new $jc(this,o);});};var defaults={vertical:false,start:1,offset:1,size:null,scroll:3,visible:null,animation:'normal',easing:'swing',auto:0,wrap:null,initCallback:null,reloadCallback:null,itemLoadCallback:null,itemFirstInCallback:null,itemFirstOutCallback:null,itemLastInCallback:null,itemLastOutCallback:null,itemVisibleInCallback:null,itemVisibleOutCallback:null,buttonNextHTML:'<div></div>',buttonPrevHTML:'<div></div>',buttonNextEvent:'click',buttonPrevEvent:'click',buttonNextCallback:null,buttonPrevCallback:null};$.jcarousel=function(e,o){this.options=$.extend({},defaults,o||{});this.locked=false;this.container=null;this.clip=null;this.list=null;this.buttonNext=null;this.buttonPrev=null;this.wh=!this.options.vertical?'width':'height';this.lt=!this.options.vertical?'left':'top';var skin='',split=e.className.split(' ');for(var i=0;i<split.length;i++){if(split[i].indexOf('jcarousel-skin')!=-1){$(e).removeClass(split[i]);var skin=split[i];break;}}
if(e.nodeName=='UL'||e.nodeName=='OL'){this.list=$(e);this.container=this.list.parent();if(this.container.hasClass('jcarousel-clip')){if(!this.container.parent().hasClass('jcarousel-container'))
this.container=this.container.wrap('<div></div>');this.container=this.container.parent();}else if(!this.container.hasClass('jcarousel-container'))
this.container=this.list.wrap('<div></div>').parent();}else{this.container=$(e);this.list=$(e).find('>ul,>ol,div>ul,div>ol');}
if(skin!=''&&this.container.parent()[0].className.indexOf('jcarousel-skin')==-1)
this.container.wrap('<div class=" '+skin+'"></div>');this.clip=this.list.parent();if(!this.clip.length||!this.clip.hasClass('jcarousel-clip'))
this.clip=this.list.wrap('<div></div>').parent();this.buttonPrev=$('.jcarousel-prev',this.container);if(this.buttonPrev.size()==0&&this.options.buttonPrevHTML!=null)
this.buttonPrev=this.clip.before(this.options.buttonPrevHTML).prev();this.buttonPrev.addClass(this.className('jcarousel-prev'));this.buttonNext=$('.jcarousel-next',this.container);if(this.buttonNext.size()==0&&this.options.buttonNextHTML!=null)
this.buttonNext=this.clip.before(this.options.buttonNextHTML).prev();this.buttonNext.addClass(this.className('jcarousel-next'));this.clip.addClass(this.className('jcarousel-clip'));this.list.addClass(this.className('jcarousel-list'));this.container.addClass(this.className('jcarousel-container'));var di=this.options.visible!=null?Math.ceil(this.clipping()/this.options.visible):null;var li=this.list.children('li');var self=this;if(li.size()>0){var wh=0,i=this.options.offset;li.each(function(){self.format(this,i++);wh+=self.dimension(this,di);});this.list.css(this.wh,wh+'px');if(!o||o.size===undefined)
this.options.size=li.size();}
this.container.css('display','block');this.buttonNext.css('display','block');this.buttonPrev.css('display','block');this.funcNext=function(){self.next();};this.funcPrev=function(){self.prev();};this.funcResize=function(){self.reload();};if(this.options.initCallback!=null)
this.options.initCallback(this,'init');if($.browser.safari){this.buttons(false,false);$(window).bind('load',function(){self.setup();});}else
this.setup();};var $jc=$.jcarousel;$jc.fn=$jc.prototype={jcarousel:'0.2.3'};$jc.fn.extend=$jc.extend=$.extend;$jc.fn.extend({setup:function(){this.first=null;this.last=null;this.prevFirst=null;this.prevLast=null;this.animating=false;this.timer=null;this.tail=null;this.inTail=false;if(this.locked)
return;this.list.css(this.lt,this.pos(this.options.offset)+'px');var p=this.pos(this.options.start);this.prevFirst=this.prevLast=null;this.animate(p,false);$(window).unbind('resize',this.funcResize).bind('resize',this.funcResize);},reset:function(){this.list.empty();this.list.css(this.lt,'0px');this.list.css(this.wh,'10px');if(this.options.initCallback!=null)
this.options.initCallback(this,'reset');this.setup();},reload:function(){if(this.tail!=null&&this.inTail)
this.list.css(this.lt,$jc.intval(this.list.css(this.lt))+this.tail);this.tail=null;this.inTail=false;if(this.options.reloadCallback!=null)
this.options.reloadCallback(this);if(this.options.visible!=null){var self=this;var di=Math.ceil(this.clipping()/this.options.visible),wh=0,lt=0;$('li',this.list).each(function(i){wh+=self.dimension(this,di);if(i+1<self.first)
lt=wh;});this.list.css(this.wh,wh+'px');this.list.css(this.lt,-lt+'px');}
this.scroll(this.first,false);},lock:function(){this.locked=true;this.buttons();},unlock:function(){this.locked=false;this.buttons();},size:function(s){if(s!=undefined){this.options.size=s;if(!this.locked)
this.buttons();}
return this.options.size;},has:function(i,i2){if(i2==undefined||!i2)
i2=i;if(this.options.size!==null&&i2>this.options.size)
i2=this.options.size;for(var j=i;j<=i2;j++){var e=this.get(j);if(!e.length||e.hasClass('jcarousel-item-placeholder'))
return false;}
return true;},get:function(i){return $('.jcarousel-item-'+i,this.list);},add:function(i,s){var e=this.get(i),old=0,add=0;if(e.length==0){var c,e=this.create(i),j=$jc.intval(i);while(c=this.get(--j)){if(j<=0||c.length){j<=0?this.list.prepend(e):c.after(e);break;}}}else
old=this.dimension(e);e.removeClass(this.className('jcarousel-item-placeholder'));typeof s=='string'?e.html(s):e.empty().append(s);var di=this.options.visible!=null?Math.ceil(this.clipping()/this.options.visible):null;var wh=this.dimension(e,di)-old;if(i>0&&i<this.first)
this.list.css(this.lt,$jc.intval(this.list.css(this.lt))-wh+'px');this.list.css(this.wh,$jc.intval(this.list.css(this.wh))+wh+'px');return e;},remove:function(i){var e=this.get(i);if(!e.length||(i>=this.first&&i<=this.last))
return;var d=this.dimension(e);if(i<this.first)
this.list.css(this.lt,$jc.intval(this.list.css(this.lt))+d+'px');e.remove();this.list.css(this.wh,$jc.intval(this.list.css(this.wh))-d+'px');},next:function(){this.stopAuto();if(this.tail!=null&&!this.inTail)
this.scrollTail(false);else
this.scroll(((this.options.wrap=='both'||this.options.wrap=='last')&&this.options.size!=null&&this.last==this.options.size)?1:this.first+this.options.scroll);},prev:function(){this.stopAuto();if(this.tail!=null&&this.inTail)
this.scrollTail(true);else
this.scroll(((this.options.wrap=='both'||this.options.wrap=='first')&&this.options.size!=null&&this.first==1)?this.options.size:this.first-this.options.scroll);},scrollTail:function(b){if(this.locked||this.animating||!this.tail)
return;var pos=$jc.intval(this.list.css(this.lt));!b?pos-=this.tail:pos+=this.tail;this.inTail=!b;this.prevFirst=this.first;this.prevLast=this.last;this.animate(pos);},scroll:function(i,a){if(this.locked||this.animating)
return;this.animate(this.pos(i),a);},pos:function(i){if(this.locked||this.animating)
return;if(this.options.wrap!='circular')
i=i<1?1:(this.options.size&&i>this.options.size?this.options.size:i);var back=this.first>i;var pos=$jc.intval(this.list.css(this.lt));var f=this.options.wrap!='circular'&&this.first<=1?1:this.first;var c=back?this.get(f):this.get(this.last);var j=back?f:f-1;var e=null,l=0,p=false,d=0;while(back?--j>=i:++j<i){e=this.get(j);p=!e.length;if(e.length==0){e=this.create(j).addClass(this.className('jcarousel-item-placeholder'));c[back?'before':'after'](e);}
c=e;d=this.dimension(e);if(p)
l+=d;if(this.first!=null&&(this.options.wrap=='circular'||(j>=1&&(this.options.size==null||j<=this.options.size))))
pos=back?pos+d:pos-d;}
var clipping=this.clipping();var cache=[];var visible=0,j=i,v=0;var c=this.get(i-1);while(++visible){e=this.get(j);p=!e.length;if(e.length==0){e=this.create(j).addClass(this.className('jcarousel-item-placeholder'));c.length==0?this.list.prepend(e):c[back?'before':'after'](e);}
c=e;var d=this.dimension(e);if(d==0){return 0;}
if(this.options.wrap!='circular'&&this.options.size!==null&&j>this.options.size)
cache.push(e);else if(p)
l+=d;v+=d;if(v>=clipping)
break;j++;}
for(var x=0;x<cache.length;x++)
cache[x].remove();if(l>0){this.list.css(this.wh,this.dimension(this.list)+l+'px');if(back){pos-=l;this.list.css(this.lt,$jc.intval(this.list.css(this.lt))-l+'px');}}
var last=i+visible-1;if(this.options.wrap!='circular'&&this.options.size&&last>this.options.size)
last=this.options.size;if(j>last){visible=0,j=last,v=0;while(++visible){var e=this.get(j--);if(!e.length)
break;v+=this.dimension(e);if(v>=clipping)
break;}}
var first=last-visible+1;if(this.options.wrap!='circular'&&first<1)
first=1;if(this.inTail&&back){pos+=this.tail;this.inTail=false;}
this.tail=null;if(this.options.wrap!='circular'&&last==this.options.size&&(last-visible+1)>=1){var m=$jc.margin(this.get(last),!this.options.vertical?'marginRight':'marginBottom');if((v-m)>clipping)
this.tail=v-clipping-m;}
while(i-->first)
pos+=this.dimension(this.get(i));this.prevFirst=this.first;this.prevLast=this.last;this.first=first;this.last=last;return pos;},animate:function(p,a){if(this.locked||this.animating)
return;this.animating=true;var self=this;var scrolled=function(){self.animating=false;if(p==0)
self.list.css(self.lt,0);if(self.options.wrap=='both'||self.options.wrap=='last'||self.options.size==null||self.last<self.options.size)
self.startAuto();self.buttons();self.notify('onAfterAnimation');};this.notify('onBeforeAnimation');if(!this.options.animation||a==false){this.list.css(this.lt,p+'px');scrolled();}else{var o=!this.options.vertical?{'left':p}:{'top':p};this.list.animate(o,this.options.animation,this.options.easing,scrolled);}},startAuto:function(s){if(s!=undefined)
this.options.auto=s;if(this.options.auto==0)
return this.stopAuto();if(this.timer!=null)
return;var self=this;this.timer=setTimeout(function(){self.next();},this.options.auto*1000);},stopAuto:function(){if(this.timer==null)
return;clearTimeout(this.timer);this.timer=null;},buttons:function(n,p){if(n==undefined||n==null){var n=!this.locked&&this.options.size!==0&&((this.options.wrap&&this.options.wrap!='first')||this.options.size==null||this.last<this.options.size);if(!this.locked&&(!this.options.wrap||this.options.wrap=='first')&&this.options.size!=null&&this.last>=this.options.size)
n=this.tail!=null&&!this.inTail;}
if(p==undefined||p==null){var p=!this.locked&&this.options.size!==0&&((this.options.wrap&&this.options.wrap!='last')||this.first>1);if(!this.locked&&(!this.options.wrap||this.options.wrap=='last')&&this.options.size!=null&&this.first==1)
p=this.tail!=null&&this.inTail;}
var self=this;this.buttonNext[n?'bind':'unbind'](this.options.buttonNextEvent,this.funcNext)[n?'removeClass':'addClass'](this.className('jcarousel-next-disabled')).attr('disabled',n?false:true);this.buttonPrev[p?'bind':'unbind'](this.options.buttonPrevEvent,this.funcPrev)[p?'removeClass':'addClass'](this.className('jcarousel-prev-disabled')).attr('disabled',p?false:true);if(this.buttonNext.length>0&&(this.buttonNext[0].jcarouselstate==undefined||this.buttonNext[0].jcarouselstate!=n)&&this.options.buttonNextCallback!=null){this.buttonNext.each(function(){self.options.buttonNextCallback(self,this,n);});this.buttonNext[0].jcarouselstate=n;}
if(this.buttonPrev.length>0&&(this.buttonPrev[0].jcarouselstate==undefined||this.buttonPrev[0].jcarouselstate!=p)&&this.options.buttonPrevCallback!=null){this.buttonPrev.each(function(){self.options.buttonPrevCallback(self,this,p);});this.buttonPrev[0].jcarouselstate=p;}},notify:function(evt){var state=this.prevFirst==null?'init':(this.prevFirst<this.first?'next':'prev');this.callback('itemLoadCallback',evt,state);if(this.prevFirst!==this.first){this.callback('itemFirstInCallback',evt,state,this.first);this.callback('itemFirstOutCallback',evt,state,this.prevFirst);}
if(this.prevLast!==this.last){this.callback('itemLastInCallback',evt,state,this.last);this.callback('itemLastOutCallback',evt,state,this.prevLast);}
this.callback('itemVisibleInCallback',evt,state,this.first,this.last,this.prevFirst,this.prevLast);this.callback('itemVisibleOutCallback',evt,state,this.prevFirst,this.prevLast,this.first,this.last);},callback:function(cb,evt,state,i1,i2,i3,i4){if(this.options[cb]==undefined||(typeof this.options[cb]!='object'&&evt!='onAfterAnimation'))
return;var callback=typeof this.options[cb]=='object'?this.options[cb][evt]:this.options[cb];if(!$.isFunction(callback))
return;var self=this;if(i1===undefined)
callback(self,state,evt);else if(i2===undefined)
this.get(i1).each(function(){callback(self,this,i1,state,evt);});else{for(var i=i1;i<=i2;i++)
if(i!==null&&!(i>=i3&&i<=i4))
this.get(i).each(function(){callback(self,this,i,state,evt);});}},create:function(i){return this.format('<li></li>',i);},format:function(e,i){var $e=$(e).addClass(this.className('jcarousel-item')).addClass(this.className('jcarousel-item-'+i));$e.attr('jcarouselindex',i);return $e;},className:function(c){return c+' '+c+(!this.options.vertical?'-horizontal':'-vertical');},dimension:function(e,d){var el=e.jquery!=undefined?e[0]:e;var old=!this.options.vertical?el.offsetWidth+$jc.margin(el,'marginLeft')+$jc.margin(el,'marginRight'):el.offsetHeight+$jc.margin(el,'marginTop')+$jc.margin(el,'marginBottom');if(d==undefined||old==d)
return old;var w=!this.options.vertical?d-$jc.margin(el,'marginLeft')-$jc.margin(el,'marginRight'):d-$jc.margin(el,'marginTop')-$jc.margin(el,'marginBottom');$(el).css(this.wh,w+'px');return this.dimension(el);},clipping:function(){return!this.options.vertical?this.clip[0].offsetWidth-$jc.intval(this.clip.css('borderLeftWidth'))-$jc.intval(this.clip.css('borderRightWidth')):this.clip[0].offsetHeight-$jc.intval(this.clip.css('borderTopWidth'))-$jc.intval(this.clip.css('borderBottomWidth'));},index:function(i,s){if(s==undefined)
s=this.options.size;return Math.round((((i-1)/s)-Math.floor((i-1)/s))*s)+1;}});$jc.extend({defaults:function(d){return $.extend(defaults,d||{});},margin:function(e,p){if(!e)
return 0;var el=e.jquery!=undefined?e[0]:e;if(p=='marginRight'&&$.browser.safari){var old={'display':'block','float':'none','width':'auto'},oWidth,oWidth2;$.swap(el,old,function(){oWidth=el.offsetWidth;});old['marginRight']=0;$.swap(el,old,function(){oWidth2=el.offsetWidth;});return oWidth2-oWidth;}
return $jc.intval($.css(el,p));},intval:function(v){v=parseInt(v);return isNaN(v)?0:v;}});})(jQuery);
/* jquery.innerfade.js */

(function($){$.fn.innerfade=function(_1){var _2;var _3;var _4;var _5;var _6;return this.each(function(){$.innerfade(this,_1);});};jQuery.pause=function(){var _7=$("ul#"+settings.slide_ui_parent+" li");var _8=$("#"+settings.pause_button_id+" span").html();if(_8=="pause"){$("#"+settings.pause_button_id+" span").html("play");settings.slide_timer_on="no";$("#"+settings.pause_button_id).attr("class","paused_button");}else{$("#"+settings.pause_button_id+" span").html("pause");settings.slide_timer_on="yes";$("#"+settings.pause_button_id).attr("class","pause_button");button_class=$("#button_selected").attr("class");split_button_class_string=button_class.split("_");button_class_string=split_button_class_string.pop();curr_slide_id_number=parseFloat(button_class_string);next_slide_id_number=curr_slide_id_number-1;setTimeout(function(){$.innerfade.next(_7,settings,curr_slide_id_number,next_slide_id_number);},0);}};jQuery.next=function(){var _9=$("ul#"+settings.slide_ui_parent+" li");$("#"+settings.pause_button_id+" span").html("play");$("#"+settings.pause_button_id).attr("class","paused_button");button_class=$("#button_selected").attr("class");split_button_class_string=button_class.split("_");button_class_string=split_button_class_string.pop();curr_slide_id_number=parseFloat(button_class_string)+1;next_slide_id_number=curr_slide_id_number-1;settings.slide_timer_on="no";if((curr_slide_id_number)<_9.length){$.skip();}};jQuery.prev=function(){var _a=$("ul#"+settings.slide_ui_parent+" li");$("#"+settings.pause_button_id+" span").html("play");$("#"+settings.pause_button_id).attr("class","paused_button");button_class=$("#button_selected").attr("class");split_button_class_string=button_class.split("_");button_class_string=split_button_class_string.pop();curr_slide_id_number=parseFloat(button_class_string)-1;next_slide_id_number=curr_slide_id_number-1;settings.slide_timer_on="no";if((curr_slide_id_number)>=0){$.skip();}};jQuery.first=function(){$("#"+settings.pause_button_id+" span").html("play");$("#"+settings.pause_button_id).attr("class","paused_button");curr_slide_id_number=0;next_slide_id_number=curr_slide_id_number-1;settings.slide_timer_on="no";$.skip();};jQuery.last=function(){var _b=$("ul#"+settings.slide_ui_parent+" li");$("#"+settings.pause_button_id+" span").html("play");$("#"+settings.pause_button_id).attr("class","paused_button");curr_slide_id_number=_b.length-1;next_slide_id_number=curr_slide_id_number-1;settings.slide_timer_on="no";$.skip();};jQuery.setOptionsButtonEvent=function(){$("#"+settings.slide_nav_id+" li").each(function(){$(this).click(function(){$("#"+settings.pause_button_id+" span").html("play");$("#"+settings.pause_button_id).attr("class","paused_button");button_class=$(this).attr("class");split_button_class_string=button_class.split("_");button_class_string=split_button_class_string.pop();curr_slide_id_number=parseFloat(button_class_string);next_slide_id_number=curr_slide_id_number-1;settings.slide_timer_on="no";$.skip();});});};$.innerfade=function(_c,_d){settings={"animationtype":"fade","speed":"normal","type":"sequence","timeout":5000,"containerheight":"auto","runningclass":"innerfade","children":null,"slide_timer_on":"yes","slide_ui_parent":null,"slide_ui_text":null,"pause_button_id":null,"slide_nav_id":null};var _e;var _f;if(_d){$.extend(settings,_d);}if(settings.children===null){_e=$(_c).children();}else{_e=$(_c).children(settings.children);}if(_e.length>1){if(settings.slide_ui_text!="null"){_f=$("ul#"+settings.slide_ui_text+" li");}$(_c).css("position","relative").css("height",settings.containerheight).addClass(settings.runningclass);for(var i=0;i<_e.length;i++){$(_e[i]).css("z-index",String(_e.length-i)).css("position","absolute").hide();if(settings.slide_ui_text!="null"){$(_f[i]).css("z-index",String(_f.length-i)).css("position","absolute").hide();}}if(settings.type=="sequence"){setTimeout(function(){$.innerfade.next(_e,settings,1,0);},settings.timeout);$(_e[0]).show();if(settings.slide_ui_text!="null"){$(_f[0]).show();}if(settings.slide_nav_id!="null"){$("#"+settings.slide_nav_id+" li").removeAttr("id");$("#"+settings.slide_nav_id+" .slide_0").attr("id","button_selected");}}else{if(settings.type=="random"){next_slide_id_number=Math.floor(Math.random()*(_e.length));setTimeout(function(){do{curr_slide_id_number=Math.floor(Math.random()*(_e.length));}while(next_slide_id_number==curr_slide_id_number);$.innerfade.next(_e,settings,curr_slide_id_number,next_slide_id_number);},settings.timeout);$(_e[next_slide_id_number]).show();if(settings.slide_ui_text!="null"){$(_f[next_slide_id_number]).show();}}else{if(settings.type=="random_start"){settings.type="sequence";curr_slide_id_number=Math.floor(Math.random()*(_e.length));setTimeout(function(){$.innerfade.next(_e,settings,(curr_slide_id_number+1)%_e.length,curr_slide_id_number);},settings.timeout);$(_e[curr_slide_id_number]).show();if(settings.slide_ui_text!="null"){$(_f[curr_slide_id_number]).show();}}else{alert("Innerfade-Type must either be 'sequence', 'random' or 'random_start'");}}}}};$.skip=function(){var _10=$("ul#"+settings.slide_ui_parent+" li");if(settings.slide_ui_text!="null"){var _11=$("ul#"+settings.slide_ui_text+" li");}for(var i=0;i<_10.length;i++){if(settings.animationtype=="fade"){$(_10[i]).fadeOut(settings.speed);if(settings.slide_ui_text!="null"){$(_11[i]).fadeOut(settings.speed);}}else{$(_10[i]).slideUp(settings.speed);if(settings.slide_ui_text!="null"){$(_11[i]).slideUp(settings.speed);}}}if(settings.animationtype=="fade"){$(_10[curr_slide_id_number]).fadeIn(settings.speed,function(){removeFilter($(this)[0]);});if(settings.slide_ui_text!="null"){$(_11[curr_slide_id_number]).fadeIn(settings.speed,function(){removeFilter($(this)[0]);});}}else{$(_10[curr_slide_id_number]).slideDown(settings.speed,function(){removeFilter($(this)[0]);});if(settings.slide_ui_text!="null"){$(_11[curr_slide_id_number]).slideDown(settings.speed,function(){removeFilter($(this)[0]);});}}if(settings.slide_nav_id!="null"){$("#"+settings.slide_nav_id+" li").removeAttr("id");$("#"+settings.slide_nav_id+" .slide_"+curr_slide_id_number).attr("id","button_selected");}};$.innerfade.next=function(_12,_13,_14,_15){var _16;if(_13.slide_ui_text!="null"){_16=$("ul#"+_13.slide_ui_text+" li");}if(_13.slide_timer_on=="yes"){if(_13.animationtype=="slide"){$(_12[_15]).slideUp(_13.speed);$(_12[_14]).slideDown(_13.speed);$(_12[_15]).slideUp(_13.speed);if(_13.slide_ui_text!="null"){$(_16[_15]).slideUp(_13.speed);}$(_12[_14]).slideDown(_13.speed,function(){removeFilter($(this)[0]);});if(_13.slide_ui_text!="null"){$(_16[_14]).slideDown(_13.speed,function(){removeFilter($(this)[0]);});}if(_13.slide_nav_id!="null"){$("#"+_13.slide_nav_id+" li").removeAttr("id");$("#"+_13.slide_nav_id+" .slide_"+_14).attr("id","button_selected");}}else{if(_13.animationtype=="fade"){$(_12[_15]).fadeOut(_13.speed);if(_13.slide_ui_text!="null"){$(_16[_15]).fadeOut(_13.speed);}$(_12[_14]).fadeIn(_13.speed,function(){removeFilter($(this)[0]);});if(_13.slide_ui_text!="null"){$(_16[_14]).fadeIn(_13.speed,function(){removeFilter($(this)[0]);});}if(_13.slide_nav_id!="null"){$("#"+_13.slide_nav_id+" li").removeAttr("id");$("#"+_13.slide_nav_id+" .slide_"+_14).attr("id","button_selected");}}else{alert("Innerfade-animationtype must either be 'slide' or 'fade'");}}if(_13.type=="sequence"){if((_14+1)<_12.length){_14=_14+1;_15=_14-1;}else{_14=0;_15=_12.length-1;}}else{if(_13.type=="random"){_15=_14;while(_14==_15){_14=Math.floor(Math.random()*_12.length);}}else{alert("Innerfade-Type must either be 'sequence', 'random' or 'random_start'");}}setTimeout((function(){$.innerfade.next(_12,_13,_14,_15);}),_13.timeout);}};})(jQuery);function removeFilter(_17){if(_17.style.removeAttribute){_17.style.removeAttribute("filter");}};
/* javalib.js */

function redirect_url(url){
	window.location=url;
}

function preload(_images,id){
        if (!_images) return;
        $('#busy').fadeIn();
        var gotime = _images.length;
        $.each(_images,function(e) {
                $(new Image()).load(function() {
                        if (--gotime < 1) {
                                $('#busy').hide();
                                if (typeof id != 'undefined' ) $(id).fadeIn();
                                window.status = '';
                        } else {
                                window.status = gotime + " remaining - "+this.src;
                        }
                }).attr('src',this);
        });
}

var image_zoom_timer = 0;
function image_zoom(id,speed,delay,w,h,step_w,step_h,div_w,div_h){
	var step_w = (step_w == null) ? 0 : step_w;
	var step_h = (step_h == null) ? 0 : step_h;
	var div_w  = (div_w == null) ? 0 : div_w;
	var div_h  = (div_h == null) ? 0 : div_h;
	var w = (w == null) ? 0 : w;
	var h = (h == null) ? 0 : h;
	if (!step_w) {
		w = $(id).width();	ow = w;
		h = $(id).height();	oh = h;
		if (!w) {
			setTimeout("image_zoom('"+id+"',"+speed+","+delay+")",2000);
			return;
		}
		ratio = w/h;
		if (w>h){
			step_w = 1;
			step_h = 1/ratio;
		} else {
			step_w = 1/ratio;
			step_h = 1;
		}
		step_w *= speed;
		step_h *= speed;
		div = $(id).parents("div").get(0).id;
		div_w = $('#'+div).width();
		div_h = $('#'+div).height();
		// firelog("image_zoom('"+id+"',"+speed+","+delay+","+w+","+h+","+step_w+","+step_h+","+div_w+","+div_h+")");
	}
	w = w - step_w;
	h = h - step_h;
	if (h>=div_h && w>=div_w) {
		$(id).width(w).height(h);
		window.status = "Img Zoom : timer : "+image_zoom_timer+" div_w "+div_w+" div_h "+div_h+" speed "+speed+" delay "+delay+ " w "+Math.floor(w)+"/"+ow+" h "+Math.floor(h)+"/"+oh+" step_w "+step_w+" step_h "+step_h+" ratio "+ratio;
		image_zoom_timer = setTimeout("image_zoom('"+id+"',"+speed+","+delay+","+w+","+h+","+step_w+","+step_h+","+div_w+","+div_h+")",delay);
	} else {
		//window.status = 'Zoom Complete';
	}
}

function image_zoom_cancel(){
	if (image_zoom_timer) {
		window.status = "Img Zoom : cancelled";
		clearTimeout(image_zoom_timer);
	}
}

function jcarousel_initCallback(carousel)
{
    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
}

function highlight_inputs() {
	$(".input_button").live('mouseover', function(){
		$(this).addClass('input_button_hover');
	});
	$(".input_button").live('mouseout', function(){
		$(this).removeClass('input_button_hover');
	});
	elements = ".input_qty, .input_select, .input_text, .input_checkbox, .input_radio, .input_textarea";
	// detect IE not input_select, dissapears when you mouse off in IE */
	if (!$.support.leadingWhitespace) elements = ".input_qty, .input_text, .input_checkbox, .input_radio, .input_textarea";
	$(elements).live('mouseover', function(){ 
		$(this).addClass("input_hover");
	});
	$(elements).live('mouseout', function(){ 
		$(this).removeClass("input_hover");
	});
}

function firelog(s){
	if (typeof(console)!="undefined") console.log(s);
}

function checkId(id){
	if (!id) return;
	id = id.replace("#","");
	if (!id) return;
	c = $('#'+id).length;
	//firelog("checkId "+id+" "+c);
	return (c > 0);
}

auto_div_height_animating = new Array;
function auto_div_height(id,monitor){
	if (auto_div_height_animating[id]) return;
	if (!checkId(monitor)) {
		firelog("auto_div_height : "+monitor+' removed from dom');
		return;
	}
	//firelog("auto_div_height : ('"+id+"','"+monitor+"')");
	container = id.replace('#','')+"_container";
	cid = "#"+container;
	if (!checkId(cid)) $(id).wrap("<div id='"+container+"'></div>");
	ch = $(cid).height();
	c  = $(id).height();
	if (c != ch){
		auto_div_height_animating[id] = true;
		firelog("auto_div_height : animating c "+c+" ch "+ch+" monitor "+monitor);
		$(cid).animate(
			{ height : c }, 500,
			function() {
				firelog("auto_div_height : animation complete "+monitor);
				auto_div_height_animating[id] = false;
				if ($(id).css('display') == 'none') $(id).fadeIn();
				setTimeout("auto_div_height('"+id+"','"+monitor+"')",500);
			}	
		);
	} else {
		$(cid).css('backgroundImage','none');
		if ($(id).css('display') == 'none') $(id).fadeIn();
		//firelog("auto_div_height : c "+c+" ch "+ch+" id "+id+" cid "+cid+" "+monitor);
		setTimeout("auto_div_height('"+id+"','"+monitor+"')",500);
	}
}

// stop ajax forms being submitted for invalid forms
function check_form(formData, jqForm, options){ 
	valid = $(options.id).valid();
	return valid;
}

pause_jcarousel = false;
function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt) {
	if (pause_jcarousel) return;
    var idx = carousel.index(i, mycarousel_itemList.length);
    carousel.add(i, mycarousel_itemList[idx - 1].html);
}

function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt) {
    carousel.remove(i);
}

function datePicker(id) {
	$("#"+id).datepicker({ 
		dateFormat: 'dd/mm/yy', 
		changeMonth: true,
		changeYear: true,
		showAnim: 'slideDown'
	});
}
function datePickerIPTC(id) {
	$("#"+id).datepicker({ 
		dateFormat: 'yymmdd', 
		changeMonth: true,
		changeYear: true,
		showAnim: 'slideDown'
	});
}

function centerDiv(div) {
	divW = $(div).width();
	divH = $(div).height();
	width  = $(window).width();
	height = $(window).height();
	x = (width/2)-(divW/2);
	y = (height/2)-(divH/2)+$(window).scrollTop();
	$(div).css('top',y).css('left',x);
	$(div).fadeIn();
}

function popup_div(img) {
	$('#popup_div').fadeOut().html("<img id='popup_img' src='/tmp'+img+'>");
	setTimeout("centerDiv('#popup_div')",2000);
}

function popup_div_no_fade(img) {
	$('#popup_div_no_fade').hide().html("<img id='popup_img' src='/tmp"+img+"'>");
	centerDiv('#popup_div_no_fade');
}

// required for $('#id').load('page.php?params=have spaces in them')
function urlencode (str) {
    var hexStr = function (dec) {
        return '%' + dec.toString(16).toUpperCase();
    };
 
    var ret = '',
            unreserved = /[\w.-]/; // A-Za-z0-9_.- // Tilde is not here for historical reasons; to preserve it, use rawurlencode instead
    str = (str+'').toString();
 
    for (var i = 0, dl = str.length; i < dl; i++) {
        var ch = str.charAt(i);
        if (unreserved.test(ch)) {
            ret += ch;
        }
        else {
            var code = str.charCodeAt(i);
            // Reserved assumed to be in UTF-8, as in PHP
            if (code === 32) {
                ret += '+'; // %20 in rawurlencode
            }
            else if (code < 128) { // 1 byte
                ret += hexStr(code);
            }
            else if (code >= 128 && code < 2048) { // 2 bytes
                ret += hexStr((code >> 6) | 0xC0);
                ret += hexStr((code & 0x3F) | 0x80);
            }
            else if (code >= 2048 && code < 65536) { // 3 bytes
                ret += hexStr((code >> 12) | 0xE0);
                ret += hexStr(((code >> 6) & 0x3F) | 0x80);
                ret += hexStr((code & 0x3F) | 0x80);
            }
            else if (code >= 65536) { // 4 bytes
                ret += hexStr((code >> 18) | 0xF0);
                ret += hexStr(((code >> 12) & 0x3F) | 0x80);
                ret += hexStr(((code >> 6) & 0x3F) | 0x80);
                ret += hexStr((code & 0x3F) | 0x80);
            }
        }
    }
    return ret;
}

function id_check(){
	var allTags = document.body.getElementsByTagName('*');
	var ids = [];
	for (var tg = 0; tg< allTags.length; tg++) {
		var tag = allTags[tg];
		if (tag.id) {
			if (ids[tag.id] && tag.id != ',ilink' && tag.id != 'filename') ids.push(tag.id+'\n');
			else ids[tag.id] = 1;
		}
	}
	alert(ids);
}

function toggle_checkbox(id) {
	el = document.getElementById(id); 
	if (!el) {
		walert("Cannot set checkbox, no such id ["+id+"]");
		return;
	}
	el.value = 1-el.value;
}

function Height() {	return $(body).height(); }
function Width() {	return $(body).width(); }
function getHeight() { return Height(); }
function getWidth() { return Width(); }

function set_valid(nm,is_valid){
	return;
	e = document.getElementById("valid_"+nm);
	if (!e) {
		walert("Cannot find id to display error looking for valid_"+nm);
	} else {
		if (is_valid) e.innerHTML = "";
		else e.innerHTML = "<img alt='This field is required.' src='/shared/cart_warning.gif'>";
	}
}

function err_row(nm,s){
	set_valid(nm,false);
	nm = nm.replace('_',' ');
	return "<li>"+nm+" "+s+"</li>\n";
}

// validate + set_valid for old carts
function validate_form(formname){
	var txt = ""; 
	e = document.getElementById(formname);
	if (!e){
		walert("Cannot validate "+formname+" no such id.");
		return true;
	}
	check_password = false;
	fields = e.elements;
	password = confirm_password = "";
	for(i=0; i<fields.length; i++)
	{
		nm  = fields[i].name;
		id  = fields[i].id;
		val = fields[i].value;
//		txt = txt + id + " " + nm + " " + "[" + val + "]<br>";
		if (id.length<8) continue;
		s = id.slice(0,8);
		if (s!="id_valid") continue;
		set_valid(nm,true);
		fields[i].style.background='#FFFFFF';
		if (id=="id_valid_not_null" && val.length==0) {
			fields[i].style.background='#FF7777';
			txt = txt + err_row(nm,"is a mandatory field.");
		}
		if (id=="id_valid_email" && !echeck(val)){
			fields[i].style.background='#FF7777';
			txt = txt + err_row(nm,"is not a valid email address.");
		}
		if (id=="id_valid_credit_card" && !checkcreditcard(val)){
			fields[i].style.background='#FF7777';
			txt = txt + err_row(nm,"is not a valid credit card number.");
		}
		if (id=="id_valid_terms"){
			val = fields[i].checked;
			if (val==false){
				alert("You must accept our terms and conditions before you can place your order.");
				return;
			}
		}
		if (nm=="password") password = val;
		if (nm=="confirm_password") {
			check_password = true;
			confirm_password = val;
		}
	}
	if (check_password && (password != confirm_password)){
		txt = txt + err_row(nm,"your passwords do not match");
		set_valid("password",false);
		set_valid("confirm_password",false);
	}
	if (txt) {
		err.innerHTML=txt
		return false;
	} else err.innerHTML="";
	return true;
}

function saveFormId(fn){
	formId = document.getElementById(fn);
	if (formId) {
		$('#spinner').show();
		formId.submit();
	} else alert('cannot save: bad form id: '+fn);
}

function conf(s){
	return window.confirm(s);
}

var activeEditors = new Array()

function activateEditor(id) {
    //alert("activate "+id);
	activeEditors[activeEditors.length] = id;
    toggleEditor(id);
}

function deactivateEditors() {
	//alert('active '+activeEditors.length);
    for(x=0;x<activeEditors.length;x++) {
		walert("Removing editor "+x);
        toggleEditor(activeEditors[x])
    }
    activeEditors.length = 0;
}

// functions
function toggleEditor(id) {
	var elm = document.getElementById(id);
	if (!elm) {
		walert("no such id "+id);
		return;
	}
	if (tinyMCE.getInstanceById(id) == null){
		walert('add' + id);
		tinyMCE.execCommand('mceAddControl', false, id);
	} else {
		walert('focus' + id);
		tinyMCE.execCommand('mceFocus', false, id);
		walert('remove' + id);
		tinyMCE.execCommand('mceRemoveControl', false, id);
	}
} 

function popup(URL,w,h) {
	aWindow=window.open(URL, "thewindow", "toolbar=no, width="+w+", height="+h+", status=no, scrollbars=yes, resize=no, menubars=no");
}

function popup_full(URL,w,h) {
	aWindow=window.open(URL, "thewindow", "toolbar=no, width="+w+", height="+h+", status=yes, scrollbars=yes, resize=yes, menubars=no");
}

function popup_clean(URL,w,h) {
	aWindow=window.open(URL, "", "toolbar=no, width="+w+", height="+h+", status=no, scrollbars=no, resize=no, menubars=no");
}

function popup_scroll(URL,w,h) {
	aWindow=window.open(URL, "", "toolbar=no, width="+w+", height="+h+", status=no, scrollbars=yes, resize=no, menubars=no");
}

function putFocus(formInst, elementInst) {
	if (document.forms.length > 0) {
		if (document.forms[formInst].elements[elementInst]) {
			document.forms[formInst].elements[elementInst].focus();
		}
	}
}

function placeFocus() {
	if (document.forms.length > 0) {
		var field = document.forms[0];
		for (i = 0; i < field.length; i++) {
			if ((field.elements[i].type == "text") || (field.elements[i].type == "textarea") || (field.elements[i].type.toString().charAt(0) == "s")) {
				document.forms[0].elements[i].focus();
				break;
			}
		}
	}
}

function checkcreditcard(object_value){
	if (object_value.length == 0)
		return false;
	var white_space = " -";
	var creditcard_string="";
	var check_char;

	for (var i = 0; i < object_value.length; i++)
	{
		check_char = white_space.indexOf(object_value.charAt(i));
		if (check_char < 0)
			creditcard_string += object_value.substring(i, (i + 1));
	}	

	if (creditcard_string.length < 13 || creditcard_string.length > 19)
		return false;

	if (creditcard_string.charAt(0) == "+")
		return false;

	if (!_CF_checkinteger(creditcard_string))
		return false;

	var doubledigit = creditcard_string.length % 2 == 1 ? false : true;
	var checkdigit = 0;
	var tempdigit;

	for (var i = 0; i < creditcard_string.length; i++)
	{
		tempdigit = eval(creditcard_string.charAt(i));

		if (doubledigit)
		{
			tempdigit *= 2;
			checkdigit += (tempdigit % 10);

			if ((tempdigit / 10) >= 1.0)
				checkdigit++;

			doubledigit = false;
		}
		else
		{
			checkdigit += tempdigit;
			doubledigit = true;
		}
	}	
	return (checkdigit % 10) == 0 ? true : false;
}

var debugId = false;	

function walert(s){	window.status = s; }

function malert(s){
	if (debugId==1) alert(s);
	if (debugId==2) walert(s);
}

function setDebugId(v){
	// 1 alert // 2 status bar
	walert("debugId ("+v+")");
	debugId=v;
}

function getId(id) {
	return $('#'+id);
}

var lastId = 0;	
function statId(id){
	if (debugId) alert("statId "+id);
	if (!checkId(id)) return;
	display = $(id).css('display');
	opacity = $(id).css('opacity');
	//firelog("statId "+id+" display "+display+" opacity "+opacity);
	if (display=="none" || opacity==0) return 0;
	else return 1;
}

function hideId(id){
	if (debugId) alert("hideId "+id);
	if (!checkId(id)) return;
	$('#'+id).hide();
}

function showId(id,mode){
	if (debugId) alert("showId "+id);
	if (!checkId(id)) return;
	var mode = (mode == null) ? 0 : mode;
	if (!mode) lastId = id;
	$('#'+id).show();
}

function toggleId(id,mode){
	if (debugId) malert("toggleId "+id);
	if (!checkId(id)) return;
	var mode = (mode == null) ? 0 : mode;
	if (!mode && lastId != id) hideId(lastId);
	$('#'+id).toggle();
}

function vislayer(){    
	this.lastId = '';
} 

vislayer.prototype.stat = function (id){
	if (!checkId(id)) return;
	opacity = $('#'+id).css('opacity');
	state   = $('#'+id).css('display');
	if (debugId) alert(id+" is display ["+state+"] opacity ["+opacity+"]");
	if (state=="block") return 1; else return 0;
}

vislayer.prototype.show = function (id,mode){
	if (debugId) malert("show "+id);
	if (!checkId(id)) return;
	var mode = (mode == null) ? 0 : mode;
	if (!mode) this.lastId = id;
	$('#'+id).show().css('opacity',1);
}

vislayer.prototype.hide = function (id){
	if (debugId) malert("hide "+id);
	if (!checkId(id)) return;
	$('#'+id).hide();
}

vislayer.prototype.toggle = function (id,mode){
	if (debugId) malert("toggle "+id);
	if (!checkId(id)) return;
	var mode = (mode == null) ? 0 : mode;
	if (!mode && this.lastId != id) this.hide(this.lastId);
	if (this.stat(id)) this.hide(id); else this.show(id,mode);
}

vislayer.prototype.slideDown = function (id,mode){
	if (debugId) malert("slideDown "+id);
	if (!checkId(id)) return;
	var mode = (mode == null) ? 0 : mode;
	if (!mode) this.lastId = id;
	$('#'+id).slideDown("slow").css('opacity',1);
}

vislayer.prototype.slideUp = function (id){
	if (debugId) malert("slideUp "+id);
	if (!checkId(id)) return;
	$('#'+id).slideUp("slow");
}

vislayer.prototype.slideUpDown = function (id,mode){
	if (debugId) malert("slideUpDown "+id);
	if (!checkId(id)) return;
	realthis = this;
	$('#'+this.lastId).slideUp("slow", function () { realthis.slideDown(id,mode); } );
}

vislayer.prototype.faderIn = function (id,mode){
	if (debugId) malert("fadeIn "+id);
	if (!checkId(id)) return;
	var mode = (mode == null) ? 0 : mode;
	if (!mode) this.lastId = id;
	alert("last "+this.lastId);
	$('#'+id).fadeIn().css('opacity',1);
}

vislayer.prototype.faderOut = function (id){
	if (debugId) malert("faderOut "+id+" busy "+this.busy);
	if (!checkId(id)) return;
	$('#'+id).fadeOut("slow", function () { this.busy = false; malert("faderOut "+id+" busy "+this.busy); } );
}

vislayer.prototype.faderInOut = function (id,mode){
	if (typeof(this.busy) == "undefined") this.busy = false;
	if (debugId) malert("faderInOut "+id+" busy "+this.busy);
	if (!checkId(id)) return;
	if (this.busy) return;
	realthis = this;
	previousId = this.lastId;
	if (previousId == id) $('#'+id).fadeIn("slow");
	else {
		this.busy = true;
		$('#'+id).fadeIn("slow", function () { realthis.faderOut(previousId,mode); walert("busy "+this.busy); } );
	}
	if (!mode) this.lastId = id;
}

vislayer.prototype.slideToggle = function (id,mode){
	if (debugId) malert("slideToggle "+id);
	if (!checkId(id)) return;
	var mode = (mode == null) ? 0 : mode;
	// a panel is open, and its not this one // close it first
	if (this.stat(this.lastId) && this.lastId != id) {
		this.slideUpDown(id,mode);
	} else {
		if (this.stat(id)) this.slideUp(id); else this.slideDown(id,mode);
	}
}

