/**
 * Common Javascript library
 *
 * @copyright   Copyright (c) 2010 GRAWEB s.r.o.
 */


function setModal(width, height, linkClass, refresh) {

	refresh = refresh || false;

	newModal = {
		overlayClose: true,
		opacity: 70,
		minHeight: height,
		minWidth: width,
		maxWidth: width,
		maxHeight: height,
		closeClass: linkClass,
		onOpen: function (dialog) {
			dialog.overlay.fadeIn(400);
			dialog.data.fadeIn(0);
			dialog.container.fadeIn(400);
		}
	}

	refreshModal = {
		overlayClose: true,
		opacity: 70,
		minHeight: height,
		minWidth: width,
		maxWidth: width,
		maxHeight: height,
		closeClass: linkClass,
		onOpen: function (dialog) {
			dialog.overlay.fadeIn(0);
			dialog.data.fadeIn(0);
			dialog.container.fadeIn(0);
		}
	}

	return (refresh) ? refreshModal: newModal;
}


$(document).ready(function(){

	$("#popup").css("display", "none");


	Cufon.replace('h1, h2, .perex h3, #photos h3');


	$("#news ul").fadeImages({timeout:2500, fadeDuration:700, initDelay:2500});


	$("#myController").jFlow({
		slides: ".slides",
		width: "100%", 
		height: "100%",
		duration: 400
	});


	var setSlideInterval = function() {
		return setInterval(function() {
			//$('a.jFlowNext').triggerHandler("click");
		}, 2500);
	}


	var slideInterval = setSlideInterval();

	$('a.jFlowNext, a.jFlowPrev').hover( function(){
		clearInterval(slideInterval);
	},
	function() {
		slideInterval = setSlideInterval();
	});


	$(".popimg").click(function(event) {
		event.preventDefault();
		target = $(this).attr('href');
		$.modal('<img src="' + target + '" />', setModal(705, 555));
		_gaq.push(['_trackPageview', target]);
	});


	$("a.ajax").live("click", function (event) {
		event.preventDefault();
		$.get(this.href);
		_gaq.push(['_trackPageview', this.href]);
	});

	
	$('#content').ajaxError(function(e, xhr, settings, exception) {
	    $(this).append('\nTriggered ajaxError handler:' + xhr.statusText);
	});


	$("form.ajax .submit input").live("click", function (event) {
		event.preventDefault();
		$(this).ajaxSubmit(jQuery.nette.successForm);
		return false;
	});


	$('#photos a, #rand-refs a, .refs a, #cms-thumbs a')
	.mouseenter(function(){
		$(this).css("position", "relative");
		$(this).css("top", "0"); // Opera bug fix
		$(this).stop().animate({'top': '-8px'}, {duration: 300, easing: 'easeOutBack'});
	})
	.mouseleave(function(){
		$(this).stop().animate({'top' : '0'}, {duration: 600, easing: 'easeOutBounce'});
	});
});
