//---------------------------------------------------------------------------------------------
//
//	MISC
//
//---------------------------------------------------------------------------------------------

(function(){


	$.fn.advancedClasses = function(config){

		/**
		 * Advanced classes
		 */
		function AdvancesClasses(settings){
			var self = this;

			// Apply settings
			self.config = $.extend({
				browser: true,
				table: true,
				external: true,
				pointerEvents: true
			}, settings);

			function init()
			{
				if (self.config.browser)
				{
					html();
				}
				if (self.config.table)
				{
					table();
				}
				if (self.config.external)
				{
			  	external();
				}
				if (self.config.pointerEvents)
				{
			  	pointerEvents();
				}
			}

			function pointerEvents()
			{
			  if(
			  	$.browser.mozilla && parseFloat($.browser.version) > 3.5 ||
			  	$.browser.webkit
			  	){
			  		$('html').addClass('pointer-events');
		  	}
			}

			function table()
			{
			  $('tr:odd').addClass('odd');
			  $('tr:even').addClass('even');
			  $('th:first-child').addClass('first');
			  $('th:last-child').addClass('last');
			  $('td:first-child').addClass('first');
			  $('td:last-child').addClass('last');
			}

			function html()
			{
		    for (var bname in $.browser)
				{
		        if (bname == 'version')
		        {
		        	var ver = parseInt($.browser[bname]);
						}
						else
						{
		        	var bodyclass = bname;
		        }
		    }
		    $('html').addClass('js-active');
		    $('html').addClass(bodyclass);
		    $('html').addClass(bodyclass+'-'+ver);
			}

			function external()
			{
			  $('#content a[href^="http"]:not([href*=\''+window.location.host+'\'])').filter(function(){ return !$(this).find('img').length; }).addClass('external');
			}

			init();

			return self;
		}

		new AdvancesClasses(config);

	};

	/**
	 *
	 * Equalizer plugin
	 *
	 */
	$.fn.equalize = function(rwdl, trueHeight){
		/**
		 * Equalizer class
		 * @param {Object} elements
		 * @param {Object} rwdl
		 */
		function HeightsEqualizer(elements, rwdl, trueHeight){
			var self = this;
			self.elements = elements;
			self.rwdl = typeof rwdl != 'undefined' ? rwdl : false;

			self.equalize = function(){
				var max = 0;
				$(self.elements).each(function(){
					if ($(this).css('min-height', '0').height('auto').height() > max)
					{
						max = $(this).height();
					}
				});
				if ( (typeof trueHeight != 'undefined' && trueHeight) || $.browser.msie && parseInt($.browser.version) < 7)
				{
					$(self.elements).each(function(){
						var cmax = max - ( $(this).css('padding-top') + $(this).css('padding-bottom') );
						$(this).height(cmax + 'px');
					});
				}
				else
				{
					$(self.elements).each(function(){
						var cmax = max - ( $(this).css('padding-top') + $(this).css('padding-bottom') );
						$(this).css('min-height', max + 'px');
					});
				}
			};

			self.equalize();

			if (self.rwdl)
			{
				self.timer = window.setInterval(function(){
					try
					{
						self.equalize();
					}
					catch (e)
					{
					}
				}, 50);
				$(window).load(function(){
					window.clearInterval(self.timer);
				});
			}
		};

		/*
		 * Instantiante
		 */
		new HeightsEqualizer($(this), rwdl, trueHeight);
	};


	/**
	 *
	 * Tabs plugin
	 *
	 */
	$.fn.tabs = function(fit, openfirst, toggleCallback){
		/**
		 * Common tabs
		 * @param {Object} selector
		 * @param {Object} fit
		 * @param {Object} openfirst
		 */
		function Tabs(wrap, fit, openfirst, toggleCallback){
			var self = this;

			self.wrap = wrap;
			self.tabs = self.wrap.find('li');
			self.items = self.wrap.parent().parent().find('.tabItems').children('.item');

			self.tabs.first().addClass('first');
			self.tabs.last().addClass('last');

			/**
			 * Bind events
			 */
			self.bind = function(){
				self.tabs.click(function(){
					self.items.hide();
					self.items.eq($(this).index()).show();
					self.tabs.removeClass('selected');
					$(this).addClass('selected');
					if(typeof toggleCallback == 'function')
					{
					  toggleCallback();
					}
					return false;
				});
			};

			/**
			 * Get all tabs width
			 */
			self.tabsWidth = function(){
				var width = 0;
				self.tabs.each(function(){
					width += $(this).outerWidth();
				});
				return width;
			};

			/**
			 * Fit tabs to width
			 */
			self.fit = function(){
				var wrapWidth = self.wrap.innerWidth();
				var tabsWidth = self.tabsWidth();
				if (wrapWidth < tabsWidth)
				{
					while (wrapWidth < tabsWidth)
					{
						self.tabs.each(function(){
							$(this).width($(this).width() - 1);
						});
						tabsWidth = self.tabsWidth();
					}
					var diff = wrapWidth - tabsWidth;
					self.tabs.last().width(self.tabs.last().width() + diff);
				}
				else if (wrapWidth > tabsWidth)
				{
					while (wrapWidth > tabsWidth)
					{
						self.tabs.each(function(){
							$(this).width($(this).width() + 1);
						});
						tabsWidth = self.tabsWidth();
					}
					var diff = wrapWidth - tabsWidth;
					self.tabs.last().width(self.tabs.last().width() + diff);
				}
			};

			if (fit)
			{
				self.fit();
			}

			self.bind();

			if (openfirst)
			{
				self.tabs.first().trigger('click');
			}

			return self;
		}

		/*
		 * Instantiante
		 */
		$.tabsInstances = [];
		$(this).each(function(i){
			$.tabsInstances[i] = new Tabs($(this), fit, openfirst, toggleCallback);
		});
	};

	/**
	 * Antialiasing fonts
	 *
	 * @param {Object} config
	 */
	$.fn.antialias = function(config){

		Cufon.replace($(this), config);
		$(this).addClass('antialiased');

	};

})(jQuery);



//---------------------------------------------------------------------------------------------
//
//	MODULES
//
//---------------------------------------------------------------------------------------------

(function(){

	/**
	 * Create carousel
	 */
	$.fn.carousel = function(settings){

		function Carousel(wrapper, settings){
			var self = this;

			// Apply settings
			self.config = $.extend({
				duration: 500,
				controls: true,
				parallax: '',
				controlsWrapper: '',
				parallaxOverlapRatio: 0,//0.2,
				pager: true,
				offset: 980,
				minWidth: 1010,
				parallaxEnabled: false,
				parallaxStep: 300,
				autoSlide: 7000,
				onAfterInit: function(){},
				onBeforeSlide: function(){},
				onAfterSlide: function(){}
			}, settings);

			self.wrapper = wrapper;
			self.slider = self.wrapper.children('.items');
			self.items = self.slider.find('.item');
			self.controlsWrapper = $(self.config.controlsWrapper);

			self.index = 0;
			self.immediate = true;
			self.stepsLength = self.items.length;

			// Get proportions
			self.itemWidth = self.items.first().outerWidth() + parseInt(self.items.first().css('margin-left')) + parseInt(self.items.first().css('margin-right'));

			// Set css
			self.slider.css({ 'width': ((self.stepsLength+1) * 3 * self.itemWidth) });
			self.items.css({ 'float': 'left' });

			// Close items
			self.items.clone().addClass('cloned').addClass('clonedBefore').prependTo(self.slider);
			self.items.clone().addClass('cloned').addClass('clonedAfter').appendTo(self.slider);

			// Create parallax content
			if(self.config.parallaxEnabled){
				var parcontent = '<span class="slides cleaned">';
				for(var i=0; i<self.stepsLength; i++)
				{
					parcontent += '<span class="slide slide'+i+'"></span>';
				}
				parcontent += '</span>';
				self.parallax = $(self.config.parallax).html(parcontent);
				self.parallaxSlideWrap = self.parallax.children('.slides');
				self.parallaxSlides = self.parallaxSlideWrap.children('.slide');
				self.parallaxSlides.clone().addClass('cloned').addClass('clonedBefore').prependTo(self.parallaxSlideWrap);
				self.parallaxSlides.clone().addClass('cloned').addClass('clonedAfter').appendTo(self.parallaxSlideWrap);
				self.parallaxSlides = self.parallaxSlideWrap.children('.slide');
				self.parallaxSlideWidth = self.parallaxSlides.first().width();
			}

			// Create pager
			if (self.config.pager && self.stepsLength>1)
			{
				var pager = '<p class="pager"><span class="insideA"><span class="insideB"><span class="insideC">';
				for (var i = 0; i < self.stepsLength; i++)
				{
					pager += '<a href="#"><span>' + (i + 1) + '</span></a>';
				}
				pager += '</span></span></span></p>';
				$(pager).appendTo(self.controlsWrapper);
				self.pager = self.controlsWrapper.children('.pager');
				self.pagerItems = self.pager.find('a');
				self.pagerItems.first().addClass('selected');

				var isc = self.pager.find('.insideC');
				var iscw = isc.width();
				if(iscw%2==0)
				{
					isc.width(iscw+1);
				}

				// Bind pager
				self.pagerItems.click(function() {
					self._initAutoslide();
					//hasher.setHash($(this).index() + 1);
					self.slide($(this).index());
					return false;
				});
			}

			// Overlays
			self.controlsWrapper.append('<div class="overWrap"><div class="over"><span class="overA"></span><span class="overB"></span><span class="overC"></span><span class="overD"></span></div></div>');

			// Create controls
			if (self.config.controls && self.stepsLength>1)
			{
				self.controlsWrapper.append('<div class="controlsWrap"><p class="controls carousel"><a href="#" class="control prev disabled"></a><a href="#" class="control next"></a></p></div>');
				self.controlsWrapper.append('<div id="itemHover"></div>');
				$('#itemHover').unbind('click');
				$('#itemHover').click(function (e) {
					var obj = self.slider.children().eq(self.current);
					var url = obj.children("span.url").html();
					if (url != "" && url != undefined) $(window.location).attr('href', url); //window.location.href = url;  
				});
				
				self.controlPrev = self.controlsWrapper.children('.controlsWrap').find('.prev');
				self.controlNext = self.controlsWrapper.children('.controlsWrap').find('.next');

				self.controlPrev.click(function() {
					self._initAutoslide();
					//hasher.setHash(self.index);
					self.slide(self.index - 1);
					return false;
				});
				self.controlNext.click(function() {
					self._initAutoslide();
					//hasher.setHash(self.index+2);
					self.slide(self.index + 1);
					return false;
				});
			}

			/**
			 * Hightlight page in pager and enable/disable prev and next
			 * @param {Object} index
			 */
			self.update = function(index){
				// Update pages
				if(self.pagerItems && self.pagerItems.length)
				{
					self.pagerItems.removeClass('selected').eq(index).addClass('selected');
				}
				// Update prev and next
				if(self.controlPrev && self.controlPrev.length && self.controlNext && self.controlNext.length)
				{
					if(index==0)
					{
						self.controlPrev.addClass('disabled');
					}
					else
					{
						self.controlPrev.removeClass('disabled');
					}
					if(index>=self.stepsLength-1)
					{
						self.controlNext.addClass('disabled');
					}
					else
					{
						self.controlNext.removeClass('disabled');
					}
				}
				self.index = index;
			};


			/**
			 * Resize parallax
			 */
			self._resizeParallax = function(){
				if(!self.config.parallaxEnabled){
					return false;
				}
				/*
				if(self.parallaxSlides.first().width() < $(window).width())
				{
					self.parallaxSlides.width($(window).width());
				}
				*/
			};

			/**
			 * Reposition parallax
			 */
			self._repositionParallax = function(index){
				if(!self.config.parallaxEnabled){
					return false;
				}
				var parleft = (index * self.config.parallaxStep * -1) - self.stepsLength * self.parallaxSlideWidth;
				if ($(window).width() > self.config.minWidth)
				{
					parleft += ($(window).width() - self.parallaxSlideWidth) / 2;
				}
				else
				{
					parleft += (self.config.minWidth - self.parallaxSlideWidth) / 2;
				}
				self.parallaxSlideWrap.css('margin-left', parleft);
				self.prevParlleft = parleft;
			};

			/**
			 * Slide page
			 * @param {Integer} index
			 */
			self.slide = function(index, immediate){
				// Slide over last item - fast switch to begin and slide again
				if(!immediate && index >= self.stepsLength)
				{
					//console.log('Go to begin', index, 'of', self.stepsLength, 'immediate', immediate);
					self.slide(-1, true);
					self.slide(0);
					return false;
				}

				// Slide over last item - fast switch to begin and slide again
				if(!immediate && index < 0)
				{
					//console.log('Go to end', index, 'of', self.stepsLength, 'immediate', immediate);
					self.slide(self.stepsLength, true);
					self.slide(self.stepsLength-1);
					return false;
				}

				var direction = index - self.current;

				// Callback
				if(!immediate && typeof self.config.onBeforeSlide == 'function')
				{
					self.config.onBeforeSlide(self, direction);
				}

				//console.log('slide to', index, 'of', self.stepsLength, 'immediate', immediate);

				// Tune duration
				var duration = self.config.duration;
				if (immediate==true)
				{
					duration = 0;
				}

				var left = (index + self.stepsLength) * self.itemWidth * -1;
				//var parleft = (index * self.config.parallaxStep * -1) - self.stepsLength * self.parallaxSlideWidth;

				if ($(window).width() > self.config.minWidth)
				{
					left += (($(window).width() - self.config.offset) / 2);
					//parleft += ($(window).width() - self.parallaxSlideWidth) / 2;
				}
				else
				{
					left += ((self.config.minWidth - self.config.offset) / 2);
					//parleft += (self.config.minWidth - self.parallaxSlideWidth) / 2;
				}

				// Animate parralax
				if(self.config.parallaxEnabled && !immediate)
				{
					var parleft = parseInt(self.parallaxSlideWrap.css('margin-left'));
					if(direction > 0) {
						parleft -= self.config.parallaxStep;
					}
					else {
						parleft += self.config.parallaxStep;
					}
					// From end to center
					if( -parleft >= 3 * self.stepsLength * self.parallaxSlideWidth)
					{
						parleft = self.prevParlleft;
					}
					// From begin to center
					else if( parleft >= 0 )
					{
						parleft = self.prevParlleft;
					}
					self.parallaxSlideWrap.animate({
							'margin-left': parleft
					}, duration);
				}

				// Animate slides
				self.slider.animate({
						'margin-left': left
					}, duration).queue(function(){

					// Callback
					if(!immediate && typeof self.config.onAfterSlide == 'function')
					{
						self.config.onAfterSlide(self);
					}

					$(this).dequeue();
				});

				self.current = index;
				self.update(index);
			};

			/**
			 * Init autoslide process
			 */
			self._initAutoslide = function(){
				if (self.autoslideTimer){
					clearInterval(self.autoslideTimer);
				}
				if(self.config.autoSlide > 0){
					self.autoslideTimer = setInterval(function(){
						/* clear animation queue */
						self.slider.stop(true,true);
						if(self.config.parallaxEnabled){
							self.parallaxSlideWrap.stop(true,true);
						}
						/**/
						self.slide(self.index + 1);
					}, self.config.autoSlide);
				}
			}

			/* pause animation when tab is inactive */
			$(window).blur(function(){
				clearInterval(self.autoslideTimer);
			});
			$(window).focus(function(){
				self._initAutoslide();
			});
			/**/

			self._initAutoslide();

			// Pause autoslide when hovered
			/*$("#itemHover").hover(function() {
				clearInterval(self.autoslideTimer);
			}, function() {
				self._initAutoslide();
			});*/
			
			$(window).resize(function(){
				self.slide(self.index, true);
				self._resizeParallax();
			});

			self.slide(0, true);
			self.update(0);
			self._resizeParallax();

			self._repositionParallax(0);

			// Callback
			if(typeof self.config.onAfterInit == 'function')
			{
				self.config.onAfterInit(self);
			}

			return self;
		}

		if(!$(this).length){
			return false;
		}
		return new Carousel($(this), settings);
	};

})(jQuery);


//--------------------------------------------------------------------------

$(document).ready(function() {

	// Init advaced classes
	$().advancedClasses();

	// Move diary wrapper into pageC
	var homeCarousel = $('#homeCarousel');
	if(homeCarousel.length)
	{
		$('#pageOverC').show();
		$('#pageOverD').show();
		homeCarousel.prependTo( $('#pageD') );
		homeCarousel.after('<div id="pageEclone"><div class="centered"></div></div>');
		var pageEclone = $('#pageEclone .centered');
		$('#logo,#menu,#topLinks').appendTo(pageEclone);
	}

	var parallaxSlideWrap;

	// Init carousel
	$('#homeCarousel .inner').carousel({
		duration: 500,
		parallax: '#pageOverC',
		controlsWrapper: '#pageD',
		onAfterInit: function(carousel) {
		},
		onBeforeSlide: function(carousel, dir){
		},
		onAfterSlide: function(carousel) {			
		}
	});

	// Move diary wrapper into pageC
	//$('#diaryWrapper').prependTo( $('#pageD') );

	// Replacing fonts
	$('.antialias').antialias();

	// Equalizing heights
	if( $('.columnsA .col.eqRow0').length ) $('.columnsA .col.eqRow0').equalize();
	if( $('.columnsA .col.eqRow1').length ) $('.columnsA .col.eqRow1').equalize();
	if( $('.columnsA .col.eqRow2').length ) $('.columnsA .col.eqRow2').equalize();
	if( $('.columnsA .col.eqRow3').length ) $('.columnsA .col.eqRow3').equalize();
	if( $('.columnsA .col.eqRow4').length ) $('.columnsA .col.eqRow4').equalize();

	popup = {
	    open: function(src, x, y) {
	        popup.close();

	        $('#pageA').append('<div class="popup popupVideo">' +

	        '<div class="popupA"><div class="popupB"><div class="popupC"><div class="popupD"><div class="popupE"><div class="popupF">' +
	        '<div class="popupInner">' +
	        '<a href="#x" class="close" onclick="return popup.close();"><span class="forBlind">X</span></a>' +

	        '<!--[if !IE]> -->' +
	        '<object class="flashPlayerObject" type="application/x-shockwave-flash" data="' + src + '" width="530" height="327" id="flashPlayerObject">' +
	        '<!-- <![endif]-->' +
	        '<!--[if IE]>' +
	        '<object id="flashPlayerObject" class="flashPlayerObject" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="530" height="327" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0">' +
	        '<param name="movie" value="' + src + '" />' +
	        '<!--><!-- -->' +
	        '<param name="loop" value="true" />' +
	        '<param name="menu" value="false" />' +
	        '<param name="wmode" value="transparent" />' +
	        '<param name="allowscriptaccess" value="always" />' +
	        '<param name="allowfullscreen" value="true" />' +
	        '<div class="flashAlternative">' +

	        '</div>' +
	        '</object>' +
	        '<!-- <![endif]-->' +

	        '</div>' +
	        '</div></div></div></div></div></div>' +
	        '</div>');

	        $('div.popupVideo').css('left', x);
	        $('div.popupVideo').css('top', y);
	    },
	    close: function() {
	        $('#pageA').children('.popup').remove();
	        return false;
	    }
	}

	GVid = function (obj, src) {
		var x = $(document).width()/2 - 235;
		var y = $(obj).offset().top - 5;

		popup.close();
        	popup.open(src, x - 40, y - 15);

		return false;
	};

	GVid1 = function (obj, src) {
		var x = $(obj).offset().left;
		var y = $(obj).offset().top;

		popup.close();
        	popup.open(src, x - 270, y - 250);

		return false;
	};

	GGal = function (obj) {
  		popup.close();
		hs.expand(obj);

		return false;
  	}

	$('.gallery').each(function() {
		var obj = $(this).find('.inner > .items > .item');
		if( obj.length > 0 ) {
			var prev = $(this).children('a.prev');
			var next = $(this).children('a.next');

			var offset = 0;
			var exclude = 0;
			var cycle = true;
			if($(this).hasClass('galleryB')) {
				offset = -14;
				exclude = 4;
				cycle = false;
			}

			var selectedIndex = $(this).find('.inner > .items > .selected').index();
			var startIndex = (selectedIndex) ? selectedIndex : 0;
			startIndex = (startIndex < 0) ? 0 : startIndex;

			$(this).children('.inner').serialScroll({
				items:'li',
				prev: prev,
				next: next,
				offset: offset,
				start: startIndex,
				duration:1100,
				force:true,
				stop:true,
				lock:false,
				cycle:cycle,
				easing:'easeOutQuart',
				jump: false,
				exclude: exclude
			});
		}
	});

	if( $('.actionsOthersList .action').length > 0 ) {
		var selectedIndex = $('.actionsOthersList .selected').index();
		var startIndex = (selectedIndex) ? selectedIndex : 0;
		startIndex = (startIndex < 0) ? 0 : startIndex;

		$('.actionsOthersList .inner').serialScroll({
			items:'div.action',
			prev:'.pager a.prev',
			next:'.pager a.next',
			offset: 0,
			start: startIndex,
			duration:1100,
			force:true,
			stop:true,
			lock:false,
			cycle:false,
			easing:'easeOutQuart',
			jump: false,
			exclude: 2
		});
	}

	if( $('.leftNewsList .article').length > 0 ) {
		var selectedIndex = $('.leftNewsList .selected').index();
		var startIndex = (selectedIndex) ? selectedIndex : 0;
		startIndex = (startIndex < 0) ? 0 : startIndex;

		$('.leftNewsList .inner').serialScroll({
			items:'div.article',
			prev:'.leftNewsList .upNDown a.up',
			next:'.leftNewsList .upNDown a.down',
			axis: 'y',
			offset: 0,
			start: startIndex,
			duration:1100,
			force:true,
			stop:true,
			lock:false,
			cycle:false,
			easing:'easeOutQuart',
			jump: false,
			exclude: 1
		});
	}

	if( $('.rightNewsList .article').length > 0 ) {
		var selectedIndex = $('.rightNewsList .selected').index();
		var startIndex = (selectedIndex) ? selectedIndex : 0;
		startIndex = (startIndex < 0) ? 0 : startIndex;

		$('.rightNewsList .inner').serialScroll({
			items:'div.article',
			prev:'.rightNewsList .upNDown a.up',
			next:'.rightNewsList .upNDown a.down',
			axis: 'y',
			offset: 0,
			start: startIndex,
			duration:1100,
			force:true,
			stop:true,
			lock:false,
			cycle:false,
			easing:'easeOutQuart',
			jump: false,
			exclude: 5
		});
	}

	if( $('.chaptersList .chapter').length > 0 ) {
		var selectedIndex = $('.chaptersList .selected').index();
		var startIndex = (selectedIndex) ? selectedIndex : 0;
		startIndex = (startIndex < 0) ? 0 : startIndex;

		$('.chaptersList .inner').serialScroll({
			items:'div.chapter',
			prev:'.chaptersList .pager a.prev',
			next:'.chaptersList .pager a.next',
			axis: 'y',
			offset: 0,
			start: startIndex,
			duration:1100,
			force:true,
			stop:true,
			lock:false,
			cycle:false,
			easing:'easeOutQuart',
			jump: false,
			exclude: 4
		});
	}
});

jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
	return -c * ((t=t/d-1)*t*t*t - 1) + b;
};

jQuery.easing.easeOutExpo = function (x, t, b, c, d) {
	return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
}

;(function(c){var a=c.scrollTo=function(f,e,d){c(window).scrollTo(f,e,d)};a.defaults={axis:"xy",duration:parseFloat(c.fn.jquery)>=1.3?0:1};a.window=function(d){return c(window)._scrollable()};c.fn._scrollable=function(){return this.map(function(){var e=this,d=!e.nodeName||c.inArray(e.nodeName.toLowerCase(),["iframe","#document","html","body"])!=-1;if(!d){return e}var f=(e.contentWindow||e).document||e.ownerDocument||e;return c.browser.safari||f.compatMode=="BackCompat"?f.body:f.documentElement})};c.fn.scrollTo=function(f,e,d){if(typeof e=="object"){d=e;e=0}if(typeof d=="function"){d={onAfter:d}}if(f=="max"){f=9000000000}d=c.extend({},a.defaults,d);e=e||d.speed||d.duration;d.queue=d.queue&&d.axis.length>1;if(d.queue){e/=2}d.offset=b(d.offset);d.over=b(d.over);return this._scrollable().each(function(){var l=this,j=c(l),k=f,i,g={},m=j.is("html,body");switch(typeof k){case"number":case"string":if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(k)){k=b(k);break}k=c(k,this);case"object":if(k.is||k.style){i=(k=c(k)).offset()}}c.each(d.axis.split(""),function(q,r){var s=r=="x"?"Left":"Top",u=s.toLowerCase(),p="scroll"+s,o=l[p],n=a.max(l,r);if(i){g[p]=i[u]+(m?0:o-j.offset()[u]);if(d.margin){g[p]-=parseInt(k.css("margin"+s))||0;g[p]-=parseInt(k.css("border"+s+"Width"))||0}g[p]+=d.offset[u]||0;if(d.over[u]){g[p]+=k[r=="x"?"width":"height"]()*d.over[u]}}else{var t=k[u];g[p]=t.slice&&t.slice(-1)=="%"?parseFloat(t)/100*n:t}if(/^\d+$/.test(g[p])){g[p]=g[p]<=0?0:Math.min(g[p],n)}if(!q&&d.queue){if(o!=g[p]){h(d.onAfterFirst)}delete g[p]}});h(d.onAfter);function h(n){j.animate(g,e,d.easing,n&&function(){n.call(this,f,d)})}}).end()};a.max=function(j,i){var h=i=="x"?"Width":"Height",e="scroll"+h;if(!c(j).is("html,body")){return j[e]-c(j)[h.toLowerCase()]()}var g="client"+h,f=j.ownerDocument.documentElement,d=j.ownerDocument.body;return Math.max(f[e],d[e])-Math.min(f[g],d[g])};function b(d){return typeof d=="object"?d:{top:d,left:d}}})(jQuery);
;(function(a){var b=a.serialScroll=function(c){return a(window).serialScroll(c)};b.defaults={duration:1e3,axis:"x",event:"click",start:0,step:1,lock:!0,cycle:!0,constant:!0};a.fn.serialScroll=function(c){return this.each(function(){var t=a.extend({},b.defaults,c),s=t.event,i=t.step,r=t.lazy,e=t.target?this:document,u=a(t.target||this,e),p=u[0],m=t.items,h=t.start,g=t.interval,k=t.navigation,l;if(!r){m=d()}if(t.force){f({},h)}a(t.prev||[],e).bind(s,-i,q);a(t.next||[],e).bind(s,i,q);if(!p.ssbound){u.bind("prev.serialScroll",-i,q).bind("next.serialScroll",i,q).bind("goto.serialScroll",f)}if(g){u.bind("start.serialScroll",function(v){if(!g){o();g=!0;n()}}).bind("stop.serialScroll",function(){o();g=!1})}u.bind("notify.serialScroll",function(x,w){var v=j(w);if(v>-1){h=v}});p.ssbound=!0;if(t.jump){(r?u:d()).bind(s,function(v){f(v,j(v.target))})}if(k){k=a(k,e).bind(s,function(v){v.data=Math.round(d().length/k.length)*k.index(this);f(v,this)})}function q(v){v.data+=h;f(v,this)}function f(B,z){if(!isNaN(z)){B.data=z;z=p}var C=B.data,v,D=B.type,A=t.exclude?d().slice(0,-t.exclude):d(),y=A.length,w=A[C],x=t.duration;if(D){B.preventDefault()}if(g){o();l=setTimeout(n,t.interval)}if(!w){v=C<0?0:y-1;if(h!=v){C=v}else{if(!t.cycle){return}else{C=y-v-1}}w=A[C]}if(!w||t.lock&&u.is(":animated")||D&&t.onBefore&&t.onBefore(B,w,u,d(),C)===!1){return}if(t.stop){u.queue("fx",[]).stop()}if(t.constant){x=Math.abs(x/i*(h-C))}u.scrollTo(w,x,t).trigger("notify.serialScroll",[C])}function n(){u.trigger("next.serialScroll")}function o(){clearTimeout(l)}function d(){return a(m,p)}function j(w){if(!isNaN(w)){return w}var x=d(),v;while((v=x.index(w))==-1&&w!=p){w=w.parentNode}return v}})}})(jQuery);

function setEpizode (obj) {
	var obj1 = thisMovie("mainSwf");
	var out = true;

	if (obj1) {
		var url = $(obj).attr("href");
		var alias = "";

		if (url.match('#')) {
			alias = url.split('#')[1];
		};
		thisMovie("mainSwf").js_setEpizode(alias);
		out = false;
	}
	return out;
}

function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName]
    }
    else {
        return document[movieName]
    }
}
