var tb_pathToImage = "http://lib.madewithlove.cz/images/progress_bar.gif";
var admin_box_visible = false;
$(document).ready(function() {
	
	if ($('fieldset.collapsible').length > 0) {
		$("fieldset.collapsible").collapse();
	}
	if ($('fieldset.collapsible').length > 0) {
		$(".block h3.collapsible").collapse();
	}

	$(".invite_header a").click(function(e) {
		$("#invite_add").toggle("slow");
	});
	
	//MWL TOP
	$("#mwl_top .menu").mouseup(function(e) {return false;});
	$(document).mouseup(function(e) {$("#mwl_top .menu").removeClass("collapsed");});
	
	$("#mwl_top .menu > a").click(function(e) {
		var this_id = $(this).parent().attr('id');
		if(this_id != 'mwl_top_signup') {
			e.preventDefault();
			$("#mwl_top .menu").each(function(index) {
				var parent_id = $(this).attr('id');
				if(parent_id != this_id) $(this).removeClass('collapsed');
			});
			$(this).parent().toggleClass("collapsed");
			return false;	
		}
	});

	
	$("#home_info #title_register").hover(function() {
		$(this).animate({ backgroundColor: "#66666", color: "#FFFFFF" }, 200);
	},function() {
		$(this).animate({ backgroundColor: "#A8003F", color: "#FFFFFF" }, 200);
	});	 
	
	//Scroll to top
	//$('#page_top').scrollTo(0,0,{easing:'swing'});
	//Detail Images
	$("#content_page_buy_detail_next_images .thumbnail a").click(function () {
		$('#content_page_buy_detail_main_image_picture').attr('src', $(this).attr('href'));
		return false;
	});
	
	//Message close button
	$("#messages li").append("<div id=\"messages_close\"><span>X</span></div>");
	$('#messages_close').click(function () {
		$("#messages li").hide();
	});
	/*orders*/
	$('#user_dashboard_orders .admin_table tr').click(function(index) {
		var link = $('.order_detail_link', this).attr('href');
		window.location = link;
		return true;
	});
	$('body.shop_administration #site_admin_orders .admin_table tr').click(function(index) {
		var link = $('.order_detail_link', this).attr('href');
		window.location = link;
		return true;
	});
	//$("select, input:checkbox, input:radio, input:file").uniform();
	/*TABS*/
	var container_width = 0;
	var elements_width = 0;
	var more_tabs_width = 60;
	var last_id = '';
	var more_tabs_content = '';
	var added = false;
	
	container_width = $('#content_tabs').width(true);
	
	if($('#content_tabs li').length > 0) {
	$('#content_tabs li').each(function(index) {
    	elements_width = elements_width + $(this).width(true);
		if(container_width > (elements_width + more_tabs_width)) {
			last_id = $(this).attr('id');
		}
		else {
			if(added == false)
			{
				$('#content_tabs ul').append('<li id="more_tabs"><a id="more_tabs_link">&raquo;</a></li>');
				$('#more_tabs').insertAfter($('#' + last_id));
				$('#more_tabs').append('<ul style="z-index: 100000" id="tabs_submenu"></ul>');
				added = true;
			} 
			more_tabs_content = more_tabs_content + '<li id="' + $(this).attr('id') + '">' + $(this).html() + '</li>';
			//more_tabs_content = '<li id="' + $(this).attr('id') + '">' + '<a href="#CONTACT_INVOICEnull"><span>Faktura�n� �daje</span></a>' + '</li>';
			//alert($(this).html());
			$(this).hide();
		}
  	});
	$('#tabs_submenu').append(more_tabs_content);
}
	//$('#tabs_submenu a').click(function() {alert($(this).attr('href'));})
	
	if ($('#featured_artist ul').length > 0) {
		/*carousel*/
		/*jQuery('#featured_artist ul').jcarousel({
			auto: 7,
			wrap: 'both',
			vertical: true,
			scroll: 1
		});*/
	}
	
	/* ostatni zbozi v detailu */
	if ($('#other_images_carousel').length > 0) {
		$('#other_images_carousel').infiniteCarousel({
			textholderHeight: .5,
			displayThumbnails: false,
			autoHideControls: true,
			inView: 1,
			advance: 1,
			padding: '17px',
			displayProgressBar: false,
			prevNextInternal: true,
			autoHideCaptions: true,
			imagePath: "http://lib.madewithlove.cz/js/infinitecarousel/images/"
		});
	}
	
	bindThickBoxEvents();
	$('#header_navigation_theming a').colorbox({href:"nastaveni_vzhledu.htm",iframe:false,opacity:0,width:'500px', height: '500px',overlayClose:false,title:'Theming'});
	/*$(".cb-enable").click(function(){
		var parent = $(this).parents('.switch');
		$('.cb-disable',parent).removeClass('selected');
		$(this).addClass('selected');
		$('.checkbox',parent).attr('checked', true);
	});
	$(".cb-disable").click(function(){
		var parent = $(this).parents('.switch');
		$('.cb-enable',parent).removeClass('selected');
		$(this).addClass('selected');
		$('.checkbox',parent).attr('checked', false);
	});*/
	/*$("checkbox").button();*/
	
	//$('#BLOG_LISTnull div.block').mwlgallery();
	$('.blog_article:not(.blog_articles_list .blog_article)').mwlgallery();
	
	
	
	/*Admin_box*/
//	$(document).mouseup(function(e) {$('#admin_box_links').hide();admin_box_visible = false;$('#admin_box #admin_box_header').removeClass('active');});
//	$('#admin_box #admin_box_header').click(function(index) {
//		$(this).addClass('active');
//		//alert(admin_box_visible);
//		if(admin_box_visible == false) {
//			$('#admin_box_links').show();
//			admin_box_visible = true;
//		}
//		else
//		{
//			$('#admin_box_links').hide();
//			admin_box_visible = false;
//		}
//		
//	})
});

function thickbox_window_close_it() 
{
//	tb_remove();
	$.fn.colorbox.close()
}

function thickbox_window_close(url, reload) 
{
//	tb_remove();
	$.fn.colorbox.close()
	var wcall=wicketAjaxGet(url, null, null, function() {return true;});

	if(reload){
		window.location.reload();
	}
	
	return !wcall;
}

//function removeThickBoxEvents() {
//    $('a.thickbox').each(function(i) {
//        $(this).unbind('click');
//    });
//}

function bindThickBoxEvents() {
	if ($('a.thickbox').length > 0) {
		$('a.thickbox').colorbox(
			{
				iframe:true, 
				innerWidth: function(){
					return $(this).attr('colorbox:width');
				}, 
				innerHeight: function(){
					return $(this).attr('colorbox:height');
				},
				fixedPosition: true,
				overlayClose: false
			}
		);
	}
	if ($("a[rel='gallery']").length > 0) {
		$("a[rel='gallery']").colorbox({
			iframe:false, 
			maxWidth: 600, 
			maxHeight: 600,
			current: "obrázek: {current} z {total}",
			previous: "předchozí",
			next: "následující",
			close: "zavřít",
			fixedPosition: true,
			overlayClose: true
		});
	}
//	if ($("a[rel='galleria']").length > 0) {
//		$("a[rel='galleria']").colorbox({
//			iframe:false, 
//			maxWidth: 600, 
//			maxHeight: 600,
//			current: "obrázek: {current} z {total}",
//			previous: "předchozí",
//			next: "následující",
//			close: "zavřít",
//			fixedPosition: true,
//			overlayClose: true
//		});
//	}
//	removeThickBoxEvents();
//	tb_init('a.thickbox, area.thickbox, input.thickbox');
}

wicketGlobalPostCallHandler = function () {
	bindThickBoxEvents();
	//Cufon.replace('h2')('h3')('h4')('#navigation_menu ul li a')('legend')('label.title')('#header_right ul li a')('#TB_ajaxWindowTitle');
	//Cufon.now();
}


$.fn.collapse = function() {
	return this.each(function() {
		$(this).find("legend").addClass('collapsible').click(function() {
		if ($(this).parent().hasClass('collapsed'))
			$(this).parent().removeClass('collapsed').addClass('collapsible');
			$(this).removeClass('collapsed');
			$(this).parent().children().not('legend').toggle("slow", function() {
			if ($(this).is(":visible"))
				$(this).parent().find("legend").addClass('collapsible');
			else
				$(this).parent().addClass('collapsed').find("legend").addClass('collapsed');
			});
		});
	});
};

/*!
 * jCarousel - Riding carousels with jQuery
 *   http://sorgalla.com/jcarousel/
 *
 * Copyright (c) 2006 Jan Sorgalla (http://sorgalla.com)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 *
 * Built on top of the jQuery library
 *   http://jquery.com
 *
 * Inspired by the "Carousel Component" by Bill Scott
 *   http://billwscott.com/carousel/
 */

(function($) {
	/**
	 * Creates a carousel for all matched elements.
	 *
	 * @example $("#mycarousel").jcarousel();
	 * @before <ul id="mycarousel" class="jcarousel-skin-name"><li>First item</li><li>Second item</li></ul>
	 * @result
	 *
	 * <div class="jcarousel-skin-name">
	 *   <div class="jcarousel-container">
	 *     <div class="jcarousel-clip">
	 *       <ul class="jcarousel-list">
	 *         <li class="jcarousel-item-1">First item</li>
	 *         <li class="jcarousel-item-2">Second item</li>
	 *       </ul>
	 *     </div>
	 *     <div disabled="disabled" class="jcarousel-prev jcarousel-prev-disabled"></div>
	 *     <div class="jcarousel-next"></div>
	 *   </div>
	 * </div>
	 *
	 * @method jcarousel
	 * @return jQuery
	 * @param o {Hash|String} A set of key/value pairs to set as configuration properties or a method name to call on a formerly created instance.
	 */
	$.fn.jcarousel = function(o) {
		if (typeof o == 'string') {
			var instance = $(this).data('jcarousel'), args = Array.prototype.slice.call(arguments, 1);
			return instance[o].apply(instance, args);
		} else
			return this.each(function() {
				$(this).data('jcarousel', new $jc(this, o));
			});
	};

	// Default configuration properties.
	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
	};

	/**
	 * The jCarousel object.
	 *
	 * @constructor
	 * @class jcarousel
	 * @param e {HTMLElement} The element to create the carousel for.
	 * @param o {Object} A set of key/value pairs to set as configuration properties.
	 * @cat Plugins/jCarousel
	 */
	$.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';

		// Extract skin class
		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]);
				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 = this.container.find('ul,ol').eq(0);
		}

		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.buttonNext = $('.jcarousel-next', this.container);

		if (this.buttonNext.size() == 0 && this.options.buttonNextHTML != null)
			this.buttonNext = this.clip.after(this.options.buttonNextHTML).next();

		this.buttonNext.addClass(this.className('jcarousel-next'));

		this.buttonPrev = $('.jcarousel-prev', this.container);

		if (this.buttonPrev.size() == 0 && this.options.buttonPrevHTML != null)
			this.buttonPrev = this.clip.after(this.options.buttonPrevHTML).next();

		this.buttonPrev.addClass(this.className('jcarousel-prev'));

		this.clip.addClass(this.className('jcarousel-clip')).css({
			overflow: 'hidden',
			position: 'relative'
		});
		this.list.addClass(this.className('jcarousel-list')).css({
			overflow: 'hidden',
			position: 'relative',
			top: 0,
			left: 0,
			margin: 0,
			padding: 0
		});
		this.container.addClass(this.className('jcarousel-container')).css({
			position: 'relative'
		});

		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');

			// Only set if not explicitly passed as option
			if (!o || o.size === undefined)
				this.options.size = li.size();
		}

		// For whatever reason, .show() does not work in Safari...
		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.jcarousel', function() { self.setup(); });
		} else
			this.setup();
	};

	// Create shortcut for internal use
	var $jc = $.jcarousel;

	$jc.fn = $jc.prototype = {
		jcarousel: '0.2.4'
	};

	$jc.fn.extend = $jc.extend = $.extend;

	$jc.fn.extend({
		/**
		 * Setups the carousel.
		 *
		 * @method setup
		 * @return undefined
		 */
		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.jcarousel', this.funcResize).bind('resize.jcarousel', this.funcResize);
		},

		/**
		 * Clears the list and resets the carousel.
		 *
		 * @method reset
		 * @return undefined
		 */
		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();
		},

		/**
		 * Reloads the carousel and adjusts positions.
		 *
		 * @method reload
		 * @return undefined
		 */
		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);
		},

		/**
		 * Locks the carousel.
		 *
		 * @method lock
		 * @return undefined
		 */
		lock: function() {
			this.locked = true;
			this.buttons();
		},

		/**
		 * Unlocks the carousel.
		 *
		 * @method unlock
		 * @return undefined
		 */
		unlock: function() {
			this.locked = false;
			this.buttons();
		},

		/**
		 * Sets the size of the carousel.
		 *
		 * @method size
		 * @return undefined
		 * @param s {Number} The size of the carousel.
		 */
		size: function(s) {
			if (s != undefined) {
				this.options.size = s;
				if (!this.locked)
					this.buttons();
			}

			return this.options.size;
		},

		/**
		 * Checks whether a list element exists for the given index (or index range).
		 *
		 * @method get
		 * @return bool
		 * @param i {Number} The index of the (first) element.
		 * @param i2 {Number} The index of the last element.
		 */
		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;
		},

		/**
		 * Returns a jQuery object with list element for the given index.
		 *
		 * @method get
		 * @return jQuery
		 * @param i {Number} The index of the element.
		 */
		get: function(i) {
			return $('.jcarousel-item-' + i, this.list);
		},

		/**
		 * Adds an element for the given index to the list.
		 * If the element already exists, it updates the inner html.
		 * Returns the created element as jQuery object.
		 *
		 * @method add
		 * @return jQuery
		 * @param i {Number} The index of the element.
		 * @param s {String} The innerHTML of the element.
		 */
		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;
		},

		/**
		 * Removes an element for the given index from the list.
		 *
		 * @method remove
		 * @return undefined
		 * @param i {Number} The index of the element.
		 */
		remove: function(i) {
			var e = this.get(i);

			// Check if item exists and is not currently visible
			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');
		},

		/**
		 * Moves the carousel forwards.
		 *
		 * @method next
		 * @return undefined
		 */
		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);
		},

		/**
		 * Moves the carousel backwards.
		 *
		 * @method prev
		 * @return undefined
		 */
		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);
		},

		/**
		 * Scrolls the tail of the carousel.
		 *
		 * @method scrollTail
		 * @return undefined
		 * @param b {Boolean} Whether scroll the tail back or forward.
		 */
		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;

			// Save for callbacks
			this.prevFirst = this.first;
			this.prevLast  = this.last;

			this.animate(pos);
		},

		/**
		 * Scrolls the carousel to a certain position.
		 *
		 * @method scroll
		 * @return undefined
		 * @param i {Number} The index of the element to scoll to.
		 * @param a {Boolean} Flag indicating whether to perform animation.
		 */
		scroll: function(i, a) {
			if (this.locked || this.animating)
				return;

			this.animate(this.pos(i), a);
		},

		/**
		 * Prepares the carousel and return the position for a certian index.
		 *
		 * @method pos
		 * @return {Number}
		 * @param i {Number} The index of the element to scoll to.
		 */
		pos: function(i) {
			var pos  = $jc.intval(this.list.css(this.lt));

			if (this.locked || this.animating)
				return pos;

			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;

			// Create placeholders, new list width/height
			// and new list position
			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, g;

			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);

					if (this.first != null && this.options.wrap == 'circular' && this.options.size !== null && (j <= 0 || j > this.options.size)) {
						g = this.get(this.index(j));
						if (g.length)
							this.add(j, g.children().clone(true));
					}
				}

				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;
			}

			// Calculate visible items
			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'));
					// This should only happen on a next scroll
					c.length == 0 ? this.list.prepend(e) : c[back ? 'before' : 'after' ](e);

					if (this.first != null && this.options.wrap == 'circular' && this.options.size !== null && (j <= 0 || j > this.options.size)) {
						g = this.get(this.index(j));
						if (g.length)
							this.add(j, g.find('>*').clone(true));
					}
				}

				c = e;
				var d = this.dimension(e);
				if (d == 0) {
					alert('jCarousel: No width/height set for items. This will cause an infinite loop. Aborting...');
					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++;
			}

			 // Remove out-of-range placeholders
			for (var x = 0; x < cache.length; x++)
				cache[x].remove();

			// Resize list
			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');
				}
			}

			// Calculate first and last item
			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;
			}

			// Adjust position
			while (i-- > first)
				pos += this.dimension(this.get(i));

			// Save visible item range
			this.prevFirst = this.first;
			this.prevLast  = this.last;
			this.first     = first;
			this.last      = last;

			return pos;
		},

		/**
		 * Animates the carousel to a certain position.
		 *
		 * @method animate
		 * @return undefined
		 * @param p {Number} Position to scroll to.
		 * @param a {Boolean} Flag indicating whether to perform animation.
		 */
		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 == 'circular' || 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');

			// Animate
			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);
			}
		},

		/**
		 * Starts autoscrolling.
		 *
		 * @method auto
		 * @return undefined
		 * @param s {Number} Seconds to periodically autoscroll the content.
		 */
		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);
		},

		/**
		 * Stops autoscrolling.
		 *
		 * @method stopAuto
		 * @return undefined
		 */
		stopAuto: function() {
			if (this.timer == null)
				return;

			clearTimeout(this.timer);
			this.timer = null;
		},

		/**
		 * Sets the states of the prev/next buttons.
		 *
		 * @method buttons
		 * @return undefined
		 */
		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 + '.jcarousel', this.funcNext)[n ? 'removeClass' : 'addClass'](this.className('jcarousel-next-disabled')).attr('disabled', n ? false : true);
			this.buttonPrev[p ? 'bind' : 'unbind'](this.options.buttonPrevEvent + '.jcarousel', 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 callback of a specified event.
		 *
		 * @method notify
		 * @return undefined
		 * @param evt {String} The event name
		 */
		notify: function(evt) {
			var state = this.prevFirst == null ? 'init' : (this.prevFirst < this.first ? 'next' : 'prev');

			// Load items
			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)).css({
				'float': 'left',
				'list-style': 'none'
			});
			$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({
		/**
		 * Gets/Sets the global default configuration properties.
		 *
		 * @method defaults
		 * @return {Object}
		 * @param d {Object} A set of key/value pairs to set as configuration properties.
		 */
		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);
//(function(a){a.uniform={options:{selectClass:"selector",radioClass:"radio",checkboxClass:"checker",fileClass:"uploader",filenameClass:"filename",fileBtnClass:"action",fileDefaultText:"No file selected",fileBtnText:"Choose File",checkedClass:"checked",focusClass:"focus",disabledClass:"disabled",activeClass:"active",hoverClass:"hover",useID:true,idPrefix:"uniform",resetSelector:false},elements:[]};if(a.browser.msie&&a.browser.version<7){a.support.selectOpacity=false}else{a.support.selectOpacity=true}a.fn.uniform=function(c){c=a.extend(a.uniform.options,c);var e=this;if(c.resetSelector!=false){a(c.resetSelector).mouseup(function(){function i(){a.uniform.update(e)}setTimeout(i,10)})}function b(k){var l=a("<div />"),i=a("<span />");l.addClass(c.selectClass);if(c.useID){l.attr("id",c.idPrefix+"-"+k.attr("id"))}var j=k.find(":selected:first");if(j.length==0){j=k.find("option:first")}i.html(j.text());k.css("opacity",0);k.wrap(l);k.before(i);l=k.parent("div");i=k.siblings("span");k.bind({"change.uniform":function(){i.text(k.find(":selected").text());l.removeClass(c.activeClass)},"focus.uniform":function(){l.addClass(c.focusClass)},"blur.uniform":function(){l.removeClass(c.focusClass);l.removeClass(c.activeClass)},"mousedown.uniform":function(){l.addClass(c.activeClass)},"mouseup.uniform":function(){l.removeClass(c.activeClass)},"click.uniform":function(){l.removeClass(c.activeClass)},"mouseenter.uniform":function(){l.addClass(c.hoverClass)},"mouseleave.uniform":function(){l.removeClass(c.hoverClass)},"keyup.uniform":function(){i.text(k.find(":selected").text())}});if(a(k).attr("disabled")){l.addClass(c.disabledClass)}a.uniform.noSelect(i);h(k)}function d(j){var k=a("<div />"),i=a("<span />");k.addClass(c.checkboxClass);if(c.useID){k.attr("id",c.idPrefix+"-"+j.attr("id"))}a(j).wrap(k);a(j).wrap(i);i=j.parent();k=i.parent();a(j).css("opacity",0).bind({"focus.uniform":function(){k.addClass(c.focusClass)},"blur.uniform":function(){k.removeClass(c.focusClass)},"click.uniform":function(){if(!a(j).attr("checked")){i.removeClass(c.checkedClass)}else{i.addClass(c.checkedClass)}},"mousedown.uniform":function(){k.addClass(c.activeClass)},"mouseup.uniform":function(){k.removeClass(c.activeClass)},"mouseenter.uniform":function(){k.addClass(c.hoverClass)},"mouseleave.uniform":function(){k.removeClass(c.hoverClass)}});if(a(j).attr("checked")){i.addClass(c.checkedClass)}if(a(j).attr("disabled")){k.addClass(c.disabledClass)}h(j)}function f(j){var k=a("<div />"),i=a("<span />");k.addClass(c.radioClass);if(c.useID){k.attr("id",c.idPrefix+"-"+j.attr("id"))}a(j).wrap(k);a(j).wrap(i);i=j.parent();k=i.parent();a(j).css("opacity",0).bind({"focus.uniform":function(){k.addClass(c.focusClass)},"blur.uniform":function(){k.removeClass(c.focusClass)},"click.uniform":function(){if(!a(j).attr("checked")){i.removeClass(c.checkedClass)}else{a("."+c.radioClass+" span."+c.checkedClass+":has([name='"+a(j).attr("name")+"'])").removeClass(c.checkedClass);i.addClass(c.checkedClass)}},"mousedown.uniform":function(){if(!a(j).is(":disabled")){k.addClass(c.activeClass)}},"mouseup.uniform":function(){k.removeClass(c.activeClass)},"mouseenter.uniform":function(){k.addClass(c.hoverClass)},"mouseleave.uniform":function(){k.removeClass(c.hoverClass)}});if(a(j).attr("checked")){i.addClass(c.checkedClass)}if(a(j).attr("disabled")){k.addClass(c.disabledClass)}h(j)}function g(n){var l=a(n);var o=a("<div />"),m=a("<span>"+c.fileDefaultText+"</span>"),j=a("<span>"+c.fileBtnText+"</span>");o.addClass(c.fileClass);m.addClass(c.filenameClass);j.addClass(c.fileBtnClass);if(c.useID){o.attr("id",c.idPrefix+"-"+l.attr("id"))}l.wrap(o);l.after(j);l.after(m);o=l.closest("div");m=l.siblings("."+c.filenameClass);j=l.siblings("."+c.fileBtnClass);if(!l.attr("size")){var i=o.width();l.attr("size",i/10)}var k=function(){var p=l.val();if(p===""){p=c.fileDefaultText}else{p=p.split(/[\/\\]+/);p=p[(p.length-1)]}m.text(p)};k();l.css("opacity",0).bind({"focus.uniform":function(){o.addClass(c.focusClass)},"blur.uniform":function(){o.removeClass(c.focusClass)},"mousedown.uniform":function(){if(!a(n).is(":disabled")){o.addClass(c.activeClass)}},"mouseup.uniform":function(){o.removeClass(c.activeClass)},"mouseenter.uniform":function(){o.addClass(c.hoverClass)},"mouseleave.uniform":function(){o.removeClass(c.hoverClass)}});if(a.browser.msie){l.bind("click.uniform.ie7",function(){setTimeout(k,0)})}else{l.bind("change.uniform",k)}if(l.attr("disabled")){o.addClass(c.disabledClass)}a.uniform.noSelect(m);a.uniform.noSelect(j);h(n)}a.uniform.restore=function(i){a(i).each(function(){if(a(this).is(":checkbox")){a(this).unwrap().unwrap()}else{if(a(this).is("select")){a(this).siblings("span").remove();a(this).unwrap()}else{if(a(this).is(":radio")){a(this).unwrap().unwrap()}else{if(a(this).is(":file")){a(this).siblings("span").remove();a(this).unwrap()}}}}a(this).unbind(".uniform");a(this).css("opacity","1");var j=a.inArray(a(i),a.uniform.elements);a.uniform.elements.splice(j,1)})};function h(i){i=a(i).get();if(i.length>1){a.each(i,function(j,k){a.uniform.elements.push(k)})}else{a.uniform.elements.push(i)}}a.uniform.noSelect=function(i){function j(){return false}a(i).each(function(){this.onselectstart=this.ondragstart=j;a(this).mousedown(j).css({MozUserSelect:"none"})})};a.uniform.update=function(i){if(i==undefined){i=a(a.uniform.elements)}i=a(i);i.each(function(){var k=a(this);if(k.is("select")){var j=k.siblings("span");var m=k.parent("div");m.removeClass(c.hoverClass+" "+c.focusClass+" "+c.activeClass);j.html(k.find(":selected").text());if(k.is(":disabled")){m.addClass(c.disabledClass)}else{m.removeClass(c.disabledClass)}}else{if(k.is(":checkbox")){var j=k.closest("span");var m=k.closest("div");m.removeClass(c.hoverClass+" "+c.focusClass+" "+c.activeClass);j.removeClass(c.checkedClass);if(k.is(":checked")){j.addClass(c.checkedClass)}if(k.is(":disabled")){m.addClass(c.disabledClass)}else{m.removeClass(c.disabledClass)}}else{if(k.is(":radio")){var j=k.closest("span");var m=k.closest("div");m.removeClass(c.hoverClass+" "+c.focusClass+" "+c.activeClass);j.removeClass(c.checkedClass);if(k.is(":checked")){j.addClass(c.checkedClass)}if(k.is(":disabled")){m.addClass(c.disabledClass)}else{m.removeClass(c.disabledClass)}}else{if(k.is(":file")){var m=k.parent("div");var l=k.siblings(c.filenameClass);btnTag=k.siblings(c.fileBtnClass);m.removeClass(c.hoverClass+" "+c.focusClass+" "+c.activeClass);l.text(k.val());if(k.is(":disabled")){m.addClass(c.disabledClass)}else{m.removeClass(c.disabledClass)}}}}}})};return this.each(function(){if(a.support.selectOpacity){var i=a(this);if(i.is("select")){if(i.attr("multiple")!=true){if(i.attr("size")==undefined||i.attr("size")<=1){b(i)}}}else{if(i.is(":checkbox")){d(i)}else{if(i.is(":radio")){f(i)}else{if(i.is(":file")){g(i)}}}}}})}})(jQuery);


/**
 * jQuery.mwl gallery plugin
 * Copyright (c) 2011 made with love
 * Date: 01/10/2011
 */
(function($){
    $.fn.extend({ 
        //plugin name - animatemenu
        mwlgallery: function(options) {
 
            var defaults = {speed: 200};
            var options = $.extend(defaults, options);

            return this.each(function() {
				var image = $(".blog_images_big").html();				  

				$(".blog_images_big").append('<div id="blog_images_big_preloader" style="position:absolute;top:50%;left:50%;width:120px;margin-left:-60px;background-color:#000;color:#FFF;font-size:12px;z-index:10;padding:5px;text-align:center;">Nahrávám obrázek</div');
				$("#blog_images_big_preloader").hide();
				$(".blog_images_big").attr('style', 'position: relative;');
				$(".blog_images_big").append('<div id="blog_images_big_old" style="position:absolute;top:0px;left:0px;right:0px;bottom:0px;"></div');
				$(".blog_images_big").append('<div id="blog_images_big_active" style="position:absolute;top:0px;left:0px;right:0px;bottom:0px;"></div');
				$(".blog_images_big img").remove();
				$("#blog_images_big_active").html(image);
				$(".blog_images_thumbnails a:first").addClass('active').fadeTo(options.speed, 0.5);
				
				//Carousel
				
				if ($('.blog_images_thumbnails ul').length > 0) {
					$('.blog_images_thumbnails ul').addClass('jcarousel-skin-mwl');
					jQuery('.blog_images_thumbnails ul').jcarousel({
						auto: 0,
						vertical: false,
						scroll: 3
					});
				}

			
				//Progress
				
				//dont run if msie
				if ($.browser.msie) {
					$('#blog_images_big_active img').scale();
					$("#blog_images_big_active").show();
				}
				else
				{
					$('#blog_images_big_active img').scale();
					$("#blog_images_big_active").show();
					/*var images = new Array();
					var count = 0;
					$('.blog_images_thumbnails a').each(function () {
						images[count] = $(this).attr('href');
						count++;
					});
					(function() {
						$.preload(images, {
							init: function(loaded, total) {
								$("#blog_images_big_active").hide();
								$(".blog_images_big").append('<div id="progress" style="position:absolute;top:50%;left:0;width:0;background-color:#000;z-index:20;height:3px;"></div');
							},
							loaded: function(img, loaded, total) {
								var totalw = $(".blog_images_big").width();
								var width = totalw * (loaded / total);
								$("#progress").css({"width":width});
							},
							loaded_all: function(loaded, total) {
								$("#progress").remove();
								var src = $('#blog_images_big_active img').attr('src', src);
								$('<img />').attr('src', src).load(function() {
									$('#blog_images_big_active').html($(this));
									$('#blog_images_big_active img').scale();
									$("#blog_images_big_active").show();
								});
							}
						});
					});*/
				}
				
				var obj = $(this);
						
				$('.blog_images_thumbnails a', obj).click(function() {
					if(!$(this).hasClass('active'))
					{
						$("#blog_images_big_preloader").show();
						$('.blog_images_thumbnails a', obj).removeClass('active').fadeTo(options.speed, 1);
						$(this).addClass('active').fadeTo(options.speed, 0.5);
						
						var e = $(this);
						var src = e.attr('href');
						$("#blog_images_big_old").html($("#blog_images_big_active").html()).animate({opacity: 1,left: '0'}, 0);
						$("#blog_images_big_active").fadeTo(0,0);
						
						if ($.browser.msie) {
							$('#blog_images_big_active img').remove();
							$('#blog_images_big_active').append('<img src="' + src + '" />');
							$('#blog_images_big_active img').scale();
							$("#blog_images_big_preloader").hide();
							$("#blog_images_big_old").animate({opacity: 0,left: '-700'}, 200);
							$("#blog_images_big_active").fadeTo(300,1);
						}
						else
						{	
							$('<img />').attr('src', src).load(function() {
								$('#blog_images_big_active img').remove();
								$('#blog_images_big_active').html($(this));
								$('#blog_images_big_active img').scale();
								$("#blog_images_big_preloader").hide();
								$("#blog_images_big_old").animate({opacity: 0,left: '-700'}, 200);
								$("#blog_images_big_active").fadeTo(300,1);
							});
						}
					}
					
					return false;
				});
			});
        }
    });
})(jQuery);


(function($){

    $.fn.extend({

        scale: function() {
            return this.each( function()
            {
                var obj = $(this);
				/*if(obj.attr('src') && !obj.attr('height')){
                    this.onload = scale;
                } else { */   
                    scale();
                //}
                function scale()
                {
					/*if( !obj.attr('height') ){
                        obj.attr('height', obj.height() );
                        obj.attr('heightwidth', obj.width() );
                    } else {           
                        obj.height(parseInt(obj.attr('height')));
                        obj.width(parseInt(obj.attr('width')));
                    }*/

                    if(obj.outerHeight() > obj.parent().height() && obj.outerWidth() <= obj.parent().width()){
                        matchHeight();       
                    }
                    else if(obj.outerWidth() > obj.parent().width() && obj.outerHeight() <= obj.parent().height()){
                        matchWidth();    
                    }
					else if(obj.outerWidth() > obj.parent().width() && obj.outerHeight() > obj.parent().height()){
                        if(obj.parent().height()/obj.outerHeight() > obj.parent().width()/obj.outerWidth()){
                            matchWidth();
                        } else {
                            matchHeight();
                        }                            
                    }
					
					if(obj.outerHeight() == 0) {
						obj.css('position', 'relative');
					}
					else {
						obj.css('position', 'relative');
	                    obj.css('margin-top', obj.parent().height()/2 - obj.outerHeight()/2);
	                    obj.css('margin-left', obj.parent().width()/2 - obj.outerWidth()/2);
					}
                    

					this.onload = null;               

                }

                function matchHeight()
                {
                    obj.width(obj.outerWidth() * obj.parent().height()/obj.outerHeight() - (obj.outerWidth() - obj.width()));
                    obj.height(obj.parent().height() - (obj.outerHeight() - obj.height()) );
                }

                function matchWidth()
                {
                    obj.height(obj.outerHeight() * obj.parent().width()/obj.outerWidth() - (obj.outerHeight() - obj.height()));
                    obj.width(obj.parent().width() - (obj.outerWidth() - obj.width()));
                }
            });
        }
    });
})(jQuery);


(function($) {
	$.fn.extend({
		preload: function(imgArr, option) {
			var imgList = [];
			var setting = $.extend({
				init: function(loaded, total) {},
				loaded: function(img, loaded, total) {},
				loaded_all: function(loaded, total) {}
			}, option);
			var total = imgArr.length;
			var loaded = 0;
			
			setting.init(0, total);
			for(var i in imgArr) {
				imgList.push($("<img />")
					.attr("src", imgArr[i])
					.load(function() {
						loaded++;
						setting.loaded(this, loaded, total);
						if(loaded == total) {
							setting.loaded_all(loaded, total);
						}
					})
				);
			}
			
		}
	});
})(jQuery);
/**
 * jQuery.scale plugin
 * Copyright (c) 2009 Oregon State Univerisity - info(at)osuosl.org | osuosl.org
 * licensed under GPLv3.
 * Date: 9/4/2009
 *
 * @projectDescription jQuery extension for scaling an object to fit inside its parent while maintaining the aspect ratio
 * @author Rob McGuire-Dale -  rob@osuoslcom
 * @version 1.0
 *
 * @id jQuery.scale
 * @id jQuery.fn.scale
 * @param {String, [String]} In any order, enter "center" (to center the object) and/or "stretch" (to stretch the object to fit inside the parent) and/or "debug" (to turn on verbose logging)
 * @return {jQuery} Returns the same jQuery object, for chaining.
 *
 * jQuery plugin structure based on "A Really Simple jQuery Plugin Tutorial" 
 * (http://www.queness.com/post/112/a-really-simple-jquery-plugin-tutorial) by
 * Kevin Liew
 */
/*(function($){                               // anonymous function wrapper

    $.fn.extend({                           // attach new method to jQuery

        scale: function( arg1, arg2, arg3 ){// declare plugin name and parameter

            // iterate over current set of matched elements
            return this.each( function()
            {
                safelog( "jquery.scale is starting...");

                safelog( "jquery.scale: Using browser \"" + navigator.appName +
                    "\" version \"" + navigator.appVersion + "\"");

                // parse the arguments into flags
                var center = false;
                var stretch = false;
                var debug = false;
                if( arg1 == "center" || arg2 == "center" || arg3 == "center")
                    center = true;
                if( arg1 == "stretch" || arg2 == "stretch" || arg3 == "stretch")
                    stretch = true;
                if( arg1 == "debug" || arg2 == "debug" || arg3 == "debug")
                    debug = true;

                // capture the object
                var obj = $(this);

                // if this is the plugin's first run on the object, and the
                // object is an image, force a reload
                if( obj.attr('src') && 
                    !obj.attr('jquery_scale_orig-height') ){

                    safelog( "jquery.scale: object is an image" );
                    var date = new Date();
                    var cursrc = obj.attr("src");
                    var newsrc = cursrc;
                    if( cursrc.indexOf('?') != -1 )
                        newsrc = cursrc.substring( 0, cursrc.indexOf('?'));
                    newsrc = newsrc + "?" + date.getTime();
                    obj.attr( "src", newsrc );
                    safelog( "jquery.scale: img src changed to " + newsrc + 
                        " to force a reload");
                    this.onload = scale;

                } else {
                    safelog("jquery.scale: object is NOT an image");
                    scale();
                }

                // plugin's main function
                function scale()
                {
                    // if this is the plugin's first run on the object, capture
                    // the object's original dimensions
                    if( !obj.attr('jquery_scale_orig-height') ){
                        obj.attr('jquery_scale_orig-height', obj.height() );
                        obj.attr('jquery_scale_orig-width', obj.width() );

                        safelog( "jquery.scale: is starting for the first " + 
                            "time. Captured the original dimensions of " + 
                            obj.width() + "x" + obj.height() );

                    // if this is NOT the plugin's first run on the object,
                    // reset the object's dimensions
                    } else {           
                        obj.height( parseInt( 
                            obj.attr('jquery_scale_orig-height') ) );
                        obj.width( parseInt( 
                            obj.attr('jquery_scale_orig-width') ) );

                        safelog( "jquery.scale: has been run before. Reset " +
                            "the object to its original dimensions of " + 
                            obj.width() + "x" + obj.height() );
                    }

                    safelog( "jquery.scale: BEFORE scaling, object's outer " +
                        "size = " + obj.outerWidth(  ) + "x" + 
                        obj.outerHeight(  ) + ", object's parent's inner size " +
                        "= " + obj.parent().width() + "x" + 
                        obj.parent().height() );

                    // Object too tall, but width is fine. Need to shorten.
                    if( obj.outerHeight(  ) > obj.parent().height() && 
                        obj.outerWidth(  ) <= obj.parent().width() ){

                        safelog( "jquery.scale: object is too tall, but width" +
                            " is OK" );
                        matchHeight();       
                    }

                    // Object too wide, but height is fine. Need to diet.
                    else if( obj.outerWidth(  ) > obj.parent().width() && 
                             obj.outerHeight(  ) <= obj.parent().height() ){

                        safelog( "jquery.scale: object is too wide, but " +
                            "height is OK" );
                        matchWidth();    
                    }

                    // Object too short and skinny. If "stretch" option enabled,
                    // match the dimenstion that is closer to being correct.
                    else if( obj.outerWidth(  ) < obj.parent().width() && 
                             obj.outerHeight(  ) < obj.parent().height() &&
                             stretch ){

                        safelog( "jquery.scale: object is too short and " +
                            "skinny, and stretch option enabled" );
                        if( obj.parent().height()/obj.outerHeight(  ) <= 
                            obj.parent().width()/obj.outerWidth(  ) ){

                            safelog( "jquery.scale: height is closer to " +
                                "being correct, or height and width are " +
                                "equally close to being correct");
                            matchHeight();

                        } else {
                            safelog( "jquery.scale: width is closer to being " +
                                "correct");
                            matchWidth();
                        }

                    // Object too tall and wide. Need to match the dimension 
                    // that is further from being correct.
                    } else if( obj.outerWidth(  ) > obj.parent().width() && 
                               obj.outerHeight(  ) > obj.parent().height() ){

                        safelog( "jquery.scale: object is too tall and wide");
                        if( obj.parent().height()/obj.outerHeight(  ) >
                            obj.parent().width()/obj.outerWidth(  ) ){

                            safelog( "jquery.scale: width is closer to being " +
                                "correct");
                            matchWidth();

                        } else {
                            safelog( "jquery.scale: height is closer to " +
                                "being correct, or height and width are " +
                                "equally close to being correct");
                            matchHeight();
                        }                            

                    }//else, object is the same size as the parent. Do nothing.

                    // if the center option is enabled, also center the object 
                    // within the parent
                    if( center ){
                        safelog( "jquery.scale: centering option enabled" );
                        obj.css( 'position', 'relative' );
                        obj.css( 'margin-top', 
                             obj.parent().height()/2 - 
                                        obj.outerHeight(  )/2  );
                        obj.css( 'margin-left', 
                             obj.parent().width()/2 - 
                                        obj.outerWidth(  )/2  );
                    }

                    // reset the onload pointer so the object doesn't flicker
                    // when reloaded other ways.
                    this.onload = null;

                    safelog( "jquery.scale: AFTER scaling, object's size = " +
                        obj.outerWidth(  ) + "x" + obj.outerHeight(  ) + 
                        ", object's parent's size = " + 
                        obj.parent().width() + "x" + 
                        obj.parent().height() + ".'" );                    

                }   //END scale

                // match the height while maintaining the aspect ratio
                function matchHeight()
                {
                    safelog( "jquery.scale: matching height" );
                    obj.width( obj.outerWidth(  ) * 
                        obj.parent().height()/obj.outerHeight(  ) - 
                        (obj.outerWidth(  ) - obj.width()));
                    obj.height( obj.parent().height() - 
                        (obj.outerHeight(  ) - obj.height()) );
                }

                // match the width while maintaining the aspect ratio
                function matchWidth()
                {
                    safelog( "jquery.scale: matching width" );
                    obj.height(  obj.outerHeight(  ) * 
                        obj.parent().width()/obj.outerWidth(  ) - 
                        (obj.outerHeight(  ) - obj.height())  );
                    obj.width( obj.parent().width() - 
                        (obj.outerWidth(  ) - obj.width()));
                }

                // a function to safely log
                function safelog( msg )
                { 
                    if( window.console && debug ) console.log( msg );
                }

            });     //END matched element iterations
        }           //END plugin declaration
    });             //END new jQuery method attachment
})(jQuery);         //END anonymous function wrapper
*/





/*
 * jQuery Color Animations
 * Copyright 2007 John Resig
 * Released under the MIT and GPL licenses.
 */

(function(jQuery){

	// We override the animation for all of these color styles
	jQuery.each(['backgroundColor', 'borderBottomColor', 'borderLeftColor', 'borderRightColor', 'borderTopColor', 'color', 'outlineColor'], function(i,attr){
		jQuery.fx.step[attr] = function(fx){
			if ( fx.state == 0 ) {
				fx.start = getColor( fx.elem, attr );
				fx.end = getRGB( fx.end );
			}

			fx.elem.style[attr] = "rgb(" + [
				Math.max(Math.min( parseInt((fx.pos * (fx.end[0] - fx.start[0])) + fx.start[0]), 255), 0),
				Math.max(Math.min( parseInt((fx.pos * (fx.end[1] - fx.start[1])) + fx.start[1]), 255), 0),
				Math.max(Math.min( parseInt((fx.pos * (fx.end[2] - fx.start[2])) + fx.start[2]), 255), 0)
			].join(",") + ")";
		}
	});

	// Color Conversion functions from highlightFade
	// By Blair Mitchelmore
	// http://jquery.offput.ca/highlightFade/

	// Parse strings looking for color tuples [255,255,255]
	function getRGB(color) {
		var result;

		// Check if we're already dealing with an array of colors
		if ( color && color.constructor == Array && color.length == 3 )
			return color;

		// Look for rgb(num,num,num)
		if (result = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color))
			return [parseInt(result[1]), parseInt(result[2]), parseInt(result[3])];

		// Look for rgb(num%,num%,num%)
		if (result = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(color))
			return [parseFloat(result[1])*2.55, parseFloat(result[2])*2.55, parseFloat(result[3])*2.55];

		// Look for #a0b1c2
		if (result = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(color))
			return [parseInt(result[1],16), parseInt(result[2],16), parseInt(result[3],16)];

		// Look for #fff
		if (result = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(color))
			return [parseInt(result[1]+result[1],16), parseInt(result[2]+result[2],16), parseInt(result[3]+result[3],16)];

		// Otherwise, we're most likely dealing with a named color
		return colors[jQuery.trim(color).toLowerCase()];
	}
	
	function getColor(elem, attr) {
		var color;

		do {
			color = jQuery.curCSS(elem, attr);

			// Keep going until we find an element that has color, or we hit the body
			if ( color != '' && color != 'transparent' || jQuery.nodeName(elem, "body") )
				break; 

			attr = "backgroundColor";
		} while ( elem = elem.parentNode );

		return getRGB(color);
	};
	
})(jQuery);

/*
 * jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
 *
 * Uses the built in easing capabilities added In jQuery 1.1
 * to offer multiple easing options
 *
 * TERMS OF USE - jQuery Easing
 * 
 * Open source under the BSD License. 
 * 
 * Copyright © 2008 George McGinley Smith
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * Redistributions of source code must retain the above copyright notice, this list of 
 * conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this list 
 * of conditions and the following disclaimer in the documentation and/or other materials 
 * provided with the distribution.
 * 
 * Neither the name of the author nor the names of contributors may be used to endorse 
 * or promote products derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 *  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE. 
 *
*/

// t: current time, b: begInnIng value, c: change In value, d: duration
jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend( jQuery.easing,
{
	def: 'easeOutQuad',
	swing: function (x, t, b, c, d) {
		//alert(jQuery.easing.default);
		return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
	},
	easeInQuad: function (x, t, b, c, d) {
		return c*(t/=d)*t + b;
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	},
	easeInOutQuad: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t + b;
		return -c/2 * ((--t)*(t-2) - 1) + b;
	},
	easeInCubic: function (x, t, b, c, d) {
		return c*(t/=d)*t*t + b;
	},
	easeOutCubic: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t + 1) + b;
	},
	easeInOutCubic: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t + b;
		return c/2*((t-=2)*t*t + 2) + b;
	},
	easeInQuart: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t + b;
	},
	easeOutQuart: function (x, t, b, c, d) {
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	},
	easeInOutQuart: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
		return -c/2 * ((t-=2)*t*t*t - 2) + b;
	},
	easeInQuint: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t*t + b;
	},
	easeOutQuint: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t*t*t + 1) + b;
	},
	easeInOutQuint: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
		return c/2*((t-=2)*t*t*t*t + 2) + b;
	},
	easeInSine: function (x, t, b, c, d) {
		return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
	},
	easeOutSine: function (x, t, b, c, d) {
		return c * Math.sin(t/d * (Math.PI/2)) + b;
	},
	easeInOutSine: function (x, t, b, c, d) {
		return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
	},
	easeInExpo: function (x, t, b, c, d) {
		return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
	},
	easeOutExpo: function (x, t, b, c, d) {
		return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
	},
	easeInOutExpo: function (x, t, b, c, d) {
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	},
	easeInCirc: function (x, t, b, c, d) {
		return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
	},
	easeOutCirc: function (x, t, b, c, d) {
		return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
	},
	easeInOutCirc: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
		return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
	},
	easeInElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
	},
	easeOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
	},
	easeInOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
		return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
	},
	easeInBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*(t/=d)*t*((s+1)*t - s) + b;
	},
	easeOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
	},
	easeInOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158; 
		if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
	},
	easeInBounce: function (x, t, b, c, d) {
		return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
	},
	easeOutBounce: function (x, t, b, c, d) {
		if ((t/=d) < (1/2.75)) {
			return c*(7.5625*t*t) + b;
		} else if (t < (2/2.75)) {
			return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
		} else if (t < (2.5/2.75)) {
			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
		} else {
			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
		}
	},
	easeInOutBounce: function (x, t, b, c, d) {
		if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
		return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
	}
});

/*
 *
 * TERMS OF USE - EASING EQUATIONS
 * 
 * Open source under the BSD License. 
 * 
 * Copyright © 2001 Robert Penner
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * Redistributions of source code must retain the above copyright notice, this list of 
 * conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this list 
 * of conditions and the following disclaimer in the documentation and/or other materials 
 * provided with the distribution.
 * 
 * Neither the name of the author nor the names of contributors may be used to endorse 
 * or promote products derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 *  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE. 
 *
 */



	// update image sizes
/*	function updateNewsImageSize(img) {
	    var minWidth = 290;
	    var minHeight = 290;
	    var w = img.width();
	    var h = img.height();
	    var ratio = w / h;
	    if (ratio > 1) {
	        img.css("height", minHeight + "px");
	        img.css("width", (minHeight * ratio) + "px");
	    } else {
	        img.css("width", minWidth + "px");
	        img.css("height", (minWidth / ratio) + "px");
	    }
	}
	
	$(".npimg img").each(function() {
	    var img = $(this);
	    img.bind("load", function() {
         updateNewsImageSize($(this));
     });
     
	    if (img.width() > 290 && img.height() > 290) {
	        updateNewsImageSize(img);
	    }*/
