/*
 * JavaScript Document
 * Author: Pavel Puček <pucek.pavel@gmail.com>
 * Owner: Karel Fukala <info@atelier-eye.cz>
 * Version: 1.0
 * All rights reserved.
 */

$(document).ready(function() {

	// at first goes browser control
	var browserInfo = {'name': '', version : 0.0};
	var supportedVersions = {'msie' : 7.0, 'mozilla' : 1.9, 'opera' : 9.0, 'safari' : 400.0}; // mozilla and webkit (+safari) versions are wierd
	var browserIsSupported = true;

	$.each($.browser, function(i, value) {
		if (value == true) {
			browserInfo.name = i;
		}
	});

	browserInfo.version = parseFloat($.browser.version.substr(0, 3));

	$.each(supportedVersions, function(i, value) {
		if (browserInfo.name == i && browserInfo.version < value) {
			browserIsSupported = false;
		}
	});

	if (!browserIsSupported) {
		alert("Váš prohlížeč je zastaralý a obsah těchto stránek nebude zobrazen správně.\nDoporučejeme vám provést aktualizaci vašeho prohlížeče na jeho poslední verzi.");
	}

	// support for dropdown lists
	$('#navigation > li').bind('mouseenter mouseleave', function(event) {
		var item = $(this);
		var link = item.find('a').eq(0);
		var list = item.find('ul');
		if (event.type == 'mouseenter') {
			link.addClass('hovered');
			if (list.length > 0) { // if list does not exist its length will be zero
				var position = Math.ceil((list.width() - item.width()) / 2); // calculates the offset of list
				list.css('left', '-' + position + 'px');
				list.fadeIn('fast');
			}
		} else {
			link.removeClass('hovered');
			list.hide();
		}
	});

  // makes dropdown items not clickable
  $('#navigation > li a').bind('click', function(event) {
    if ($(this).parent().find('ul').length > 0) {
      event.preventDefault();
    }
  });

  // makes links with 'current' class not clickable
  $('#navigation li a').bind('click', function(event) {
    if ($(this).hasClass('current')) {
      event.preventDefault();
    }
  });

	// clickable headlines
	$('h3 a').bind('click', function(event) {
		var href = $(this).attr('href');
		$(href).toggle();
		event.preventDefault();
	});

	// images hover effect
	$('img').each(function() { $(this).css('opacity', '0.7'); }).bind('mouseenter mouseleave', function(event) {
		var image = $(this);
		if (event.type == 'mouseenter') {
			image.animate({'opacity' : 1.0}, 175);
		} else {
			image.animate({'opacity' : 0.7}, 175);
		}
	});

	// fancybox support, show as one image
	$('div#columnsWrap a.image').fancybox({
		'transitionIn' : 'elastic',
		'transitionOut' : 'elastic',
		'titleShow' : false,
		'autoScale' : true
	});

	// fancybox support, show as slide of images
	$('div#columnsWrap p a.image[rel=group]').fancybox({
		'titlePosition' : 'inside',
		'autoScale' : true,
		'titleFormat' : function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="fancybox-title-inside">Obrázek ' + (currentIndex + 1) + ' / ' + currentArray.length  + '</span>';
		}
	});

});


