jQuery (
	function ($) {
		var $content	= $('#content');
		
		if (!$content.hasClass ('home')) {
			/* Follow page, align boxes on the right */
			
			var $aside		= $content.children ('aside'),
				$article	= $content.children ('article');
			
			var diff	= $aside.outerHeight () - $article.outerHeight ();

			if (diff > 0) {
				$article.css ('min-height', $aside.outerHeight () - 60);
			}

		}
(function(){
	if (!$content.hasClass('home'))	return;
	
	
	/*
	 *		The slideshow
	 */
	
	$('#slideshow .layer1, #slideshow .layer2, #slideshow .layer3, #slideshow .layer4')
	.bind('anim-in',function(evt,speed){
		var $this = $(this);
		var into = $this.data('animto').split('|');
		$this.animate({left: parseInt(into[0]), top: parseInt(into[1])},speed != undefined ? speed : parseInt($this.data('animspeed')),function(){
			$this.trigger('anim-out');
		});
	}).bind('anim-out',function(evt,speed){
		var $this = $(this);
		var into = $this.data('animfrom').split('|');
		$this.animate({left: parseInt(into[0]), top: parseInt(into[1])},speed != undefined  ? speed : parseInt($this.data('animspeed')),function(){
			$this.trigger('anim-in');
		});
	});
	$('#slideshow .layer5')
	.bind('anim-in',function(evt,callback){
		var $this = $(this);

		$this.siblings ('.layer5').trigger ('anim-out');
		var into = $this.data('animto').split('|');
		$this.stop().animate({left: parseInt(into[0]), top: parseInt(into[1])}, parseInt($this.data('animspeed')),callback);
	}).bind('anim-out',function(evt,callback){
		var $this = $(this);

		var into = $this.data('animfrom').split('|');
		$this.stop().animate({left: parseInt(into[0]), top: parseInt(into[1])}, parseInt($this.data('animspeed')),callback);
	});
	$('#slideshow .layer1, #slideshow .layer2, #slideshow .layer3, #slideshow .layer4, #slideshow .layer5').trigger('anim-in',0);
	
	$('#slideshow').bind('anim',function(evt,idx){
		$('#slideshow').find('.slogan1, .slogan2, .slogan3').not('.slogan'+idx).trigger('anim-out',function(){
			$('#slideshow .slogan'+idx).trigger('anim-in');
		});
		$('#slideshow').find('.anim1, .anim2, .anim3').not('.anim'+idx).fadeOut(1500);
		$('#slideshow .anim'+idx).fadeIn(1500);
	});
	
	/*
	 *	The slideshow
	 */
	$('#slideshow').bind('promo',function(evt,idx){
		var $this = $(this);
		var $next = $this.find('li.promo'+idx);
		$next.addClass('active').siblings().removeClass('active');
		$this.trigger('anim',[idx]);
		clearTimeout($this.data('slideshow.timer'));
		$this.data('slideshow.timer',setTimeout(function(){
			$this.trigger('promo-next');
		},5000));
	}).bind('promo-next',function(evt){
		var $promos = $('#slideshow .promos li');
		var $next = $promos.filter('.active').next().length ? $promos.filter('.active').next() : $promos.first();
		$('#slideshow').trigger('promo',[$next.attr('rel')]);
	}).trigger('promo-next').find('.promos li').bind('click',function(){
		$('#slideshow').trigger('promo',[$(this).attr('rel')]);
	}).hover(function(){
		$(this).addClass('hover');
	},function(){
		$(this).removeClass('hover');
	});
	
	
	
})();


/*
(function(){
	return;
		if ($content.hasClass ('home')) {
			// Home
			
			var $slideshow	= $('#slideshow'),
				$animations	= $slideshow.find ('> .animations > div'),
				$promos		= $slideshow.find ('> .promos li');

			
			$promos.first ().addClass ('active');
			
			function loopy () {
				var $animation	= $animations.filter ('.active'),
					$promo		= $promos.filter ('.active'),
					$nextAnim	= $animation.next ().length ? $animation.next () : $animations.first (),
					$nextPromo	= $promo.next ().length ? $promo.next () : $promos.first ();
				
				$slideshow.data ('timeout.slideshow', setTimeout (
						function () {
							$animation.removeClass ('active');
							$nextAnim.addClass ('active');
							
							$promo.removeClass ('active');
							$nextPromo.addClass ('active');
							
							loopy ();
						}
					, 3000)
				);
			}
			
			$slideshow.children ('.promos').bind ('mouseenter mouseleave',
				function (e) {
					if (e.type === 'mouseleave' && $slideshow.data ('timeout.slideshow') === null) {
						loopy ();
						
					}
					
					if (e.type === 'mouseenter') {
						clearTimeout ($slideshow.data ('timeout.slideshow'));
						$slideshow.data ('timeout.slideshow', null);
						
						$promos.filter ('.active').removeClass ('active');
						
					}
				}
			);
			
			$promos.bind ('mouseenter mouseleave',
				function (e) {
					
					var $this	= $(this);
					
					if (e.type === 'mouseenter') {
						$promos.removeClass ('active');
						$this.addClass ('active hover');
						
						$animations.removeClass ('active').eq ($this.index ()).addClass ('active');
					}
					
					if (e.type === 'mouseleave') {
						$this.removeClass ('hover');
						$this.addClass ('active');
					}
				}
			);
			
			
			loopy ();
		}
})();
/**/
		
		var $form	= $('#content article form');
		
		$('input,textarea').placeholder ();


		if ($form.length) {
			var radio	= [site_link + 'templates/site/assets/img/contact/radio.png', site_link + 'templates/site/assets/img/contact/radio-active.png'];
			
			$('input:radio').each (
				function () {
					var $this	= $(this),
						o		= $this.offset ();
					
					var $img	= $('<img class="radio-image" src="' + radio[this.checked ? 1 : 0] + ' " />');
					
					$img.insertAfter ($this);
					$this.hide ();
					$img.data ('radio.img', $this)
				}
			)
			
			$('.radio-image').live ('click',
				function () {
					var $img	= $(this),
						$radio	= $img.data ('radio.img');
	
	
					$radio.siblings ('input:radio').removeAttr ('checked');
					$radio.attr ('checked', true);
					
					$img.attr ('src', radio[1]).siblings ('.radio-image').attr ('src', radio[0]);
				}
			);
		}
		
		/* print baby */
		if ($('html').hasClass ('print')) {
			setTimeout (
				function () {
					window.print ();
				}, 1000
			);
		}
	}
);
