$().ready(function(){
	
	
	//HEAD
	$('.head-box').click(function(){
        if ($(this).hasClass('down')) {
			$('.head-drop', this).slideUp('100')
			$(this).removeClass('down');
    	} else {
			if ($('.head-box').hasClass('down')) {
				$('.head-drop').slideUp('100')
				$('.head-box').removeClass('down');
			};
        	$('.head-drop', this).slideDown('100');
			$(this).addClass('down');
		}
	});
	
	//FOLIO
	
	var folioNumber = $('#folio-count').attr('rel');
	
	$('#strip').css({width:(600 * folioNumber) +"px"});
	
	
	
	$('.arrows').hover(function() {
		$(this).css({"filter":"alpha(opacity=40)","opacity":"0.4", "cursor": "pointer"});
	}, function() {
		$(this).css({"filter":"alpha(opacity=100)","opacity":"1"});
	});
	
	var animating = 0;
	var foliono = 1;
	
	$('#right').click(function(){
		if (!animating) {
			animating = 1;
			if (foliono < folioNumber) {
				$('#strip').animate({
					left: "-=565"
				}, 500, function() {
					animating = 0;
					foliono ++;
				});
			} else {
				$('#strip').animate({
					left: "36"
				}, 500, function() {
					animating = 0;
					foliono = 1;
				});
			};
		};
	});
	
	$('#left').click(function(){
		if (!animating) {
			animating = 1;
			if (foliono != 1) {
				$('#strip').animate({
					left: "+=565"
				}, 500, function() {
					animating = 0;
					foliono --;
				});
			} else {
				$('#strip').animate({
					left: - ((565 * (folioNumber - 1)) - 36)
				}, 500, function() {
					animating = 0;
					foliono = folioNumber;
				});
			};
		};
	});
	
	$(window).jkey('right', function(){
		if (!animating) {
			animating = 1;
			if (foliono < folioNumber) {
				$('#strip').animate({
					left: "-=565"
				}, 500, function() {
					animating = 0;
					foliono ++;
				});
			} else {
				$('#strip').animate({
					left: "36"
				}, 500, function() {
					animating = 0;
					foliono = 1;
				});
			};
		};
	});
	
	
	$(window).jkey('left', function(){
		if (!animating) {
			animating = 1;
			if (foliono != 1) {
				$('#strip').animate({
					left: "+=565"
				}, 500, function() {
					animating = 0;
					foliono --;
				});
			} else {
				$('#strip').animate({
					left: - ((565 * (folioNumber - 1)) - 36)
				}, 500, function() {
					animating = 0;
					foliono = folioNumber;
				});
			};
		};
	});
	
	var slider = [];
	
	for (var i = 1; i <= folioNumber; i++) {
	
		var currentGallery = "#gallery"+[i];
		var currentGalleryLi = currentGallery+" li";
		var gallerySize = $(currentGalleryLi).length;
		
		if (gallerySize > 1) {
		
			$(currentGallery).bxSlider({
				mode: 'fade',
				controls: true,
				nextText: '',
				auto: false,
				pager: true
			});
		}
		
	}
	
	$('.folio-item iframe, .folio-item object, .folio-item embed').each(function () {
		var w = $(this).attr('width');
		var h = $(this).attr('height');
		$(this).attr('width','547');
		$(this).attr('height',(h/w)*'547');
	});

});
