var carouselNum = 4;

jQuery.fn.sfHover = function() {
	jQuery(this).hover(
		function() { jQuery(this).addClass("sfHover"); },
		function() { jQuery(this).removeClass("sfHover"); }
	)
	return this
}

window.onload = function(){
	
	$("#myGallery").find("img").each(function(i) {
		$(this).css("display", "block");
		$(this).rotateLeft(2);
	});
	
	
	$('#myGallery').cycle({ 
		fx: 'fade',
		speed:  0,
		next:   '#nextSlide',
		prev:   '#prevSlide',
		pager: '#navig'
	});
		/*
		 $("#registrate").click(function(event){
		   event.preventDefault();
		   $(this).hide("slow");
		 });
		 */
}

$(document).ready(function()
{
	$('#nav li').sfHover();
	$("li:has(ul)").hover(function()
	{
		$(this).children("ul").css("display", "none");
		//$(this).children("ul").css("display", "block");
		var nodeSize = $(this).width();
		$(this).children("ul").width(nodeSize);
		$(this).children("ul").children("li").width(nodeSize-8);
		$(this).children("ul").slideDown("normal");
	},
	function()
	{
		$(this).children("ul").css("display", "none");
		$(this).children("ul").slideUp("fast");
	});
	
	
})

function currentCarousel(){
	for (var i=0; i<carouselNum; i++)
	{
		if($('#carousel'+i).css('display')=='block')
		{
			return i;
		}
	}
}

function prevCarousel()
{
	var currentC = currentCarousel();
	if (currentC>0)
	{
		setCurrentCarousel(currentC,currentC-1);
	}
	else
		setCurrentCarousel(currentC,carouselNum-1);
}

function nextCarousel()
{
	var currentC = currentCarousel();
	if (currentC<carouselNum-1)
	{
		setCurrentCarousel(currentC,currentC+1);
	}
	else
		setCurrentCarousel(currentC,0);
}

function setCurrentCarousel(clast,curr)
{
	$('#carousel'+clast).css('display','none');
	$('#carousel'+curr).css('display','block');
	$('#fotoSlideTitle'+clast).css('background-color','#f97db9');
	$('#fotoSlideTitle'+curr).css('background-color','#e51575');
}

function showCarousel(thiscar){
	var currentC = currentCarousel();
	if (currentC!=thiscar)
	{
		setCurrentCarousel(currentC,thiscar);
	}
}