$(document).ready(function() {
	if ($("body.BodyIntro").length)
	{
		//var windowWidth = $(window).width();
		//var logo1_left = parseInt(((windowWidth-48)/2)-26);
		//$("#LogoGreniuk").css('left', logo1_left+'px').css('bottom', '-'+$('#LogoGreniuk').height()+'px');
		
		//var logo1_left = 70;
		//$("#LogoGreniuk").css('left', logo1_left+'px').css('bottom', '-'+$('#LogoGreniuk').height()+'px');
		
		//var logo2_left = parseInt(((windowWidth-48)/2)+26);
		//$("#LogoWarchol").css('left', logo2_left+'px').css('top', '-'+$('#LogoWarchol').height()+'px');

		//var logo2_left = 121;
		//$("#LogoWarchol").css('left', logo2_left+'px').css('top', '-'+$('#LogoWarchol').height()+'px');

		//setTimeout("animation()",300);
	}
	$('#BoxPageRight ul.UlMenuTop li:first').addClass('first');
	$('#BoxMenuLeft ul.UlMenuLeft li:first').addClass('first');
	if ($('#BoxIntro').length)
	{
		var windowHeight = $(window).height();
		var boxPageHeight = parseInt($('#BoxIntro').innerHeight()+60);
		if (windowHeight > boxPageHeight)
		{
			var bodyPadding = (windowHeight-boxPageHeight)/2;
			//$('body').css('padding-top', bodyPadding+'px');
			//$('body').css('height', boxPageHeight+'px');
			//$('body').css('height', (windowHeight-bodyPadding)+'px');
			$('div.BoxIntro').css('padding-top', bodyPadding+'px').css('padding-bottom', bodyPadding+'px');
			$('div.BoxIntro').css('height', boxPageHeight+'px');
			//$('body').css('height', (windowHeight-bodyPadding)+'px');
		}
		setTimeout("animation()",300);
	}

	if ($('#BoxText').length)
	{
		$('#BoxText').jScrollPane();
	}
	if ($('.MenuLeftUl').length)
	{
		$('.MenuLeftUl').jScrollPane();
	}
	if ($('#BoxPics').length)
	{
		$('#BoxPics').cycle({
			fx: 'fade'
		});
	}
	if ($('#BoxSectionFotos').length)
	{
		$('#BoxSectionFotos').cycle({
			fx: 'fade'
		});
	}
	if ($('.BoxPersonFotos').length)
	{
		$('.BoxPersonFotos').cycle({
			fx: 'fade'
		});
	}
	if ($('.BoxSectionButtonImg').length)
	{
		$('.BoxSectionButtonImg').cycle({
			fx: 'fade'
		});
	}
	if ($('#BoxPage').length)
	{
		var windowHeight = $(window).height();
		var boxPageHeight = $('#BoxPage').innerHeight();
		if (windowHeight > boxPageHeight)
		{
			var bodyPadding = (windowHeight-boxPageHeight)/2;
			$('body').css('padding-top', bodyPadding+'px');
			$('body').css('height', boxPageHeight+'px');
		}
	}
	if ($.browser.msie) {
		$('div.BoxContentGallery div.BoxText').css('margin-left', '-10px');
		$('div.BoxContentGallery div.BoxText h1').css('margin-left', '10px');
	}
	if ($('#BoxGallery').length)
	{
		$('#BoxGallery div.BoxFotos div.BoxFotoUnit:first').show();
		$('div.BoxGalleryMin div.BoxGalleryMin1:first').addClass('active');
	}
	if ($('#BoxSectionMenu').length) {
		var section_menu_width = $('#BoxSectionMenu').innerWidth();
		var count_a = $('#BoxSectionMenu span').length;
		$('#BoxSectionMenu span').css('width', section_menu_width/count_a+'px');
	}
	$('div.BoxGalleryMin2').click(function() {
		if (!$(this).parent().hasClass('active'))
		{
			var this_id = $(this).attr('id');
			$('div.BoxGalleryMin div.BoxGalleryMin1').removeClass('active').css('opacity', '0.7');
			$(this).parent().addClass('active').css('opacity', '1');
			$('#BoxGallery div.BoxFotos div.BoxFotoUnit').fadeOut('slow');
			$('#BoxGallery div.BoxFotos div.BoxFotoUnit[rel="'+this_id+'"]').fadeIn('slow');
		}
	});
	$('.BoxSectionButton').each(function(i) {
		var box_height = $(this).children().height();
		var a_height = $(this).children().children().height();
		$(this).children().children('a').css('height', a_height+'px');
		$(this).children().children('a').css('padding-top', (parseInt((box_height-a_height)-10))+'px');
		$(this).children().children('a').css('padding-bottom', (parseInt(10))+'px');
		//$(this).children().children().css('padding-top', (parseInt((box_height-a_height)/2))+'px');
		//$(this).children().children().css('padding-bottom', (parseInt((box_height-a_height)/2)+1)+'px');
	});
	$('.BoxSectionButton div.BoxSectionButtonImg a').hover(
		function() {
			$(this).parent().css('border', '2px solid #D10000');
			$(this).parent().parent().css('padding-left', '13px').css('padding-top', '13px').css('width', '167px').css('height', '167px');
		},
		function() {
			$(this).parent().css('border', 'none');
			$(this).parent().parent().css('padding-left', '15px').css('padding-top', '15px').css('width', '165px').css('height', '165px');
		}
	);
	$('.MenuLeftUl').css('width', '160px').css('padding-right', '0');

	$('.jScrollPaneContainer div.BoxGalleryMin1:not(.active)').css('opacity', '0.7');

	$('div.BoxGalleryMin2').hover(
		function() {
			$(this).parent().css('opacity', '1');
		},
		function() {
			if (!$(this).parent().hasClass('active'))
			{
				$(this).parent().css('opacity', '0.7');
			}
		}
	);
	$('div.BoxFotoArrayLeft').hover(
		function() {
			if ($(this).parent().parent().prev().length) {
				$(this).addClass('hover');
			}
		},
		function() {
			$(this).removeClass('hover');
		}
	);
	$('div.BoxFotoArrayRight').hover(
		function() {
			if ($(this).parent().parent().next().length) {
				$(this).addClass('hover');
			}
		},
		function() {
			$(this).removeClass('hover');
		}
	);
	$('div.BoxFotoArrayLeft').click(function() {
		var prev_id = $(this).parent().parent().prev().attr('rel');
		$('div.BoxGalleryMin2#'+prev_id).click();
	});
	$('div.BoxFotoArrayRight').click(function() {
		var next_id = $(this).parent().parent().next().attr('rel');
		$('div.BoxGalleryMin2#'+next_id).click();
	});
	if ($(".FotoToBig").length)
	{
		$(".FotoToBig").lightbox({
			fitToScreen: true
		});
	}

	var move = -15;
	var zoom = 1.2;

	$('.BoxLogo').hover(function() {
		width = $('.BoxLogo').width() * zoom;
		height = $('.BoxLogo').height() * zoom;
		$(this).find('img').stop(false,true).animate({'width':width, 'height':height, 'top':'-18px', 'left':'-8px'}, {duration:200});
	},
	function() {
		$(this).find('img').stop(false,true).animate({'width':$('.BoxLogo').width(), 'height':$('.BoxLogo').height(), 'top':'0', 'left':'0'}, {duration:100});	
	});
	if ($("div.BoxMarquee1").length)
	{
		$jScroller.add("div.BoxMarquee1", "div.BoxMarquee2", "left", 8, true);
		$jScroller.start();
	}

});


function animation(){
	if ($('div.BoxIntro').height() > $(window).height())
	{
		var windowHeight = $('div.BoxIntro').height();
	} else {
		var windowHeight = $(window).height();
	}
	var windowWidth = $(window).width();
	var logo1_top = parseInt(((windowHeight-228)/2)-50);
	//var logo2_bottom = parseInt(((windowHeight)/2));
	var logo2_bottom = parseInt(((windowHeight-228)/2)+50);
	//var logo2_bottom = parseInt(((windowHeight-228)/2)+40);
	//var logo2_bottom  = parseInt(windowHeight-logo1_top);
	
	var logo1_left = parseInt(((windowWidth-48)/2)-24);
	//$("#LogoGreniuk").animate({bottom: logo2_bottom+'px', left: logo1_left+'px' }, {queue:false, duration:3000, easing:'easeOutBounce'});	
	$("#LogoGreniuk").animate({bottom: logo2_bottom+'px' }, {queue:false, duration:3000, easing:'easeOutBounce'});	
	var logo2_left = parseInt(((windowWidth-48)/2)+26);
	//$("#LogoWarchol").animate({top: logo1_top+'px', left: logo2_left+'px' }, {queue:false, duration:3000, easing:'easeOutBounce'});
	$("#LogoWarchol").animate({top: logo1_top+'px'}, {queue:false, duration:3000, easing:'easeOutBounce'});
	
	$("#IntroBorderCenter").animate({height:"220px"}, 3000, '', 
		function() {
			$("#IntroProjekt").animate({opacity: '1'}, 1000, '', function() {
				$("#IntroSwitchLang").animate({opacity: '1'}, 1000);
			});
		}
	);
}