

$(document).ready(function() {
setupZoom();

$('<span>@</span>').replaceAll('.fake');



$('#walk').innerfade({ 
		speed: 500, 
		type: 'sequence',
		timeout: 2000, 
		containerheight: '450px'
	});

$("div.zalozka span.close img, div.zalozka").click(function(){
	
	$("div.zalozka").fadeOut(1000);

})


$("#ateliery li").hover(
  function () {
  $("#ateliery li").find("div.label").fadeOut(200);
  $("#ateliery li").find("div:first").fadeOut(200);
  
  $(".detail").hide(200);
  
    $(this).find("div:first").fadeIn(200);
    $(this).find("div.label").fadeIn(200);
    var currentId = $(this).attr('id') + 'detail';
    $("#" + currentId).show(200);
  }, 
  function () {
  
  
  }
);
    
$('#menu li').click(function() {
  $('#menu li').removeClass("active");
  $('#submenu-maj li').removeClass("active");
  $('#submenu-vysmah li').removeClass("active");
  var menu = $(this).attr("class");
  $(this).addClass("active");
  $(".container").slideUp();
  $('#submenu-maj').slideUp();
  $('#submenu-vysmah').slideUp();
  $("." + menu).slideDown();
});

$('#submenu-maj li').click(function() {
  $('#submenu-maj li').removeClass("active");
  var menu = $(this).attr("class");
  $(this).addClass("active");
  $(".container").slideUp();
  $("." + menu).slideDown();
});

$('#submenu-vysmah li').click(function() {
  $('#submenu-vysmah li').removeClass("active");
  var menu = $(this).attr("class");
  $(this).addClass("active");
  $(".container").slideUp();
  $("." + menu).slideDown();
});

$("#menu li.maj").click(function(){
	$('#submenu-maj').slideDown();
})

$("#menu li.vysmahFoto").click(function(){
	$('#submenu-vysmah').slideDown();
})

$.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?tags=cvernovka&lang=en-us&format=json&jsoncallback=?", function(data){
    $.each(data.items, function(i,item){
	    if(i<=13){ 
    		$("<img/>").attr("src", item.media.m).appendTo("#FlickrImages ul")
    		.wrap("<li><a href='" + item.media.m.replace("_m", "") + "'></a></li>");

    	}
    	setupZoom();
    });
}); 

foto = 0;
do{
foto ++;

$("<img/>").attr("src", "1maj/thumb/fotostena" + foto + ".jpg").appendTo("#majStena")
    		.wrap("<li><a href='" + "1maj/water/fotostena" + foto + ".jpg'></a></li>");

}while(foto < 45)


foto = 0;
do{
foto ++;

$("<img/>").attr("src", "bufet1/thumb/foto" + foto + ".jpg").appendTo("#vysmahFotky")
    		.wrap("<li><a href='" + "bufet1/foto/foto" + foto + ".jpg'></a></li>");

}while(foto < 42)
setupZoom();
    	

$.getJSON("http://api.flickr.com/services/feeds/groups_pool.gne?id=1416441@N21&lang=en-us&format=json&jsoncallback=?", function(data){
    $.each(data.items, function(i,item){
	    if(i<=3){ 
    		$("<img/>").attr("src", item.media.m).appendTo("#MajImages ul")
    		.wrap("<li><a href='" + item.media.m.replace("_m", "") + "'></a></li>");

    	}
    	setupZoom();
    });
})
 
$("div.container").hide();  
if(window.location.hash) {
 
 $("div." + window.location.hash.replace("#", "")).slideDown();
 $('#menu li').removeClass("active");
 $('#menu li.' + window.location.hash.replace("#", "")).addClass("active");
}else{
$("div.container").hide(); 
$("div.maj").slideDown();  
}
});


(function($) {
 
$.fn.innerfade = function(options) {
 
	this.each(function(){ 	
		
		var settings = {
			animationtype: 'fade',
			speed: 'normal',
			timeout: 2000,
			type: 'sequence',
			containerheight: 'auto',
			runningclass: 'innerfade'
		};
		
		if(options)
			$.extend(settings, options);
		
		var elements = $(this).children();
	
		if (elements.length > 1) {
		
			$(this).css('position', 'relative');
	
			$(this).css('height', settings.containerheight);
			$(this).addClass(settings.runningclass);
			
			for ( var i = 0; i < elements.length; i++ ) {
				$(elements[i]).css('z-index', String(elements.length-i)).css('position', 'absolute');
				$(elements[i]).hide();
			};
		
			if ( settings.type == 'sequence' ) {
				setTimeout(function(){
					$.innerfade.next(elements, settings, 1, 0);
				}, settings.timeout);
				$(elements[0]).show();
			} else if ( settings.type == 'random' ) {
				setTimeout(function(){
					do { current = Math.floor ( Math.random ( ) * ( elements.length ) ); } while ( current == 0 )
					$.innerfade.next(elements, settings, current, 0);
				}, settings.timeout);
				$(elements[0]).show();
			}	else {
				alert('type must either be \'sequence\' or \'random\'');
			}
			
		}
		
	});
};
 
 
$.innerfade = function() {}
$.innerfade.next = function (elements, settings, current, last) {
 
	if ( settings.animationtype == 'slide' ) {
		$(elements[last]).slideUp(settings.speed, $(elements[current]).slideDown(settings.speed));
	} else if ( settings.animationtype == 'fade' ) {
		$(elements[last]).fadeOut(settings.speed);
		$(elements[current]).fadeIn(settings.speed);
	} else {
		alert('animationtype must either be \'slide\' or \'fade\'');
	};
	
	if ( settings.type == 'sequence' ) {
		if ( ( current + 1 ) < elements.length ) {
			current = current + 1;
			last = current - 1;
		} else {
			current = 0;
			last = elements.length - 1;
		};
	}	else if ( settings.type == 'random' ) {
		last = current;
		while (	current == last ) {
			current = Math.floor ( Math.random ( ) * ( elements.length ) );
		};
	}	else {
		alert('type must either be \'sequence\' or \'random\'');
	};
	setTimeout((function(){$.innerfade.next(elements, settings, current, last);}), settings.timeout);
};
})(jQuery);
