/* Author: Sándor Kocsis */
jQuery(function($){				
	$.supersized({
		autoplay: 0,
		slide_interval: 3000, // Length between transitions
		transition: 1, // 0-None, 1-Fade, 2-Slide Top, 3-Slide Right, 4-Slide Bottom, 5-Slide Left, 6-Carousel Right, 7-Carousel Left
		transition_speed: 700, // Speed of transition							
		slide_links: 'false', // Individual links for each slide (Options: false, 'num', 'name', 'blank')
		slides: slides
	});
});

$.extend({
	changeLayout: function(element, clickedElement) {
		var _activeContent = $('.active-content'),
			_activeInnerBox = _activeContent.find('.innerbox'),
			_activeInnerLead = _activeContent.find('.innerlead'),
			_clickedInnerBox = $(clickedElement).find('.innerbox'),
			_clickedInnerContent = clickedElement.find('.innercontent'),
			_globalEasing = 'swing'
		
		function fasz() {
			$(clickedElement).addClass('active-content');
			$(element).isotope('updateSortData', clickedElement).isotope({}, function(){
				_clickedInnerBox.animate({
					height: _clickedInnerContent.height()
				}, {
					duration: 500,
					easing: _globalEasing,
					step: function(now, fx){
						$('.isobox:not(.active-content)').css({
							top: '+=' + Math.round(Number(now - _clickedInnerBox.height()))
						})
					}
				});
			});
			clickedElement.animate({
				width: 579
			}, {
				duration: 500,
				easing: _globalEasing,
				complete: function(){
					$(element).isotope();
					if ($('html, body').scrollTop() > 150) {
						$('html, body').animate({
							scrollTop: 0
						}, 500);
					}
				}
			});
		}
			
		if (_activeContent.length != 0) {
			_activeContent.data().isotopeSortData.activeContent = false;
			_activeInnerBox.animate({
				height: _activeInnerLead.height()
			}, 500, _globalEasing);
			_activeContent.animate({
				width: 187
			}, 500, _globalEasing, function(){
				fasz();
			}).removeClass('active-content');
		} else {
			fasz();
		}
	}
});

$(document).ready(function(){
	var innerbox = document.getElementsByClassName('innerbox'),
		len = innerbox.length,
		innerlead;
	for (var i = 0; i < len; i++) {
		innerlead = innerbox[i].childNodes[1].childNodes[1];
		if (innerlead) {
			innerbox[i].style.height = innerlead.offsetHeight + 'px';
		}
	}
	/* document.getElementsByClassName('content')[0].style.display = 'none'; */
	
	$('.isobox.content-enabled').click(function(){
		var $this = $(this);
		if ($this.hasClass('active-content') == false) {
			$.changeLayout('.content', $this);
		}
		return false;
	});
	
	/* gallery toggle */
	$('.toggle-gallery').click(function(){
		$('.content').fadeOut();
		$('.gallery-nav, .gallery-message').fadeIn();
		setTimeout(function(){
			$('.gallery-message').fadeOut();
		}, 2000);
		return false;
	});
	
	/* content toggle */
	$('.logo').click(function(){
		$('.content').fadeIn();
		$('.gallery-nav').fadeOut();
		return false;
	});
});

$(window).load(function(){
	$('.content').animate({
		opacity: 1
	});
	$('.content').isotope({
		itemSelector : '.isobox',
		masonry : {
          columnWidth : 196
        },
		getSortData: {
			activeContent: function($elem) {
				return $elem.hasClass('active-content');
			}
		},
		sortBy: 'activeContent',
		sortAscending : false,
		animationEngine : 'jquery',
		animationOptions: {
			duration: 500,
			easing: 'swing',
			queue: true
		}
	});
});
