initposX=new Array;
initposY=new Array;
directionX=new Array(0, -1.2,  1.7, -1.3,    2, -0.3, -0.1,  0.7,  1.5,    1);
directionY=new Array(0,  0.5, -0.6, -0.3,  0.4, -0.9,  0.9,  0.2,    1, -1.2);
newsTexts=new Array(0,
	"<br />Marti, 17 ianuarie ora 20:30 Salsa Encanto 2 deschide o noua grupa de incepatori la Liceul Ovidius Constanta. In plina desfasurarea a campaniei <span class='impsmall'>Danseaza pentru tine!</span> iti propunem sa accepti invitatia noastra!<br />",
	"<br />Primul curs este <span class='impsmall'>gratuit</span>. Te asteptam sa vezi despre ce este vorba!");
newsCount=1;
newsHover=0;
slideshowHover=0;
animCount=0;
slide=1;
slide0Active=1;
discoX=0;

function slideshow()
	{
	if (!slideshowHover)
		{
		if (slide==10) slide=0;
		newslide="assets/images/bigphotoindex"+slide+".jpg";
		if (slide0Active)
			{
			$("#slide1").attr("src",newslide);
			$("#slide0").fadeOut(1000);
			$("#slide1").fadeIn(1000);
			slide0Active=0;
			}
		else
			{
			$("#slide0").attr("src",newslide);
			$("#slide1").fadeOut(1000);
			$("#slide0").fadeIn(1000);
			slide0Active=1;
			}
		slide++;
		}
	}

function autoChangeNews()
	{
	if (!newsHover) 
		{
		toNextNews();
		}
	}

function toNextNews()
	{
	if (newsCount==newsTexts.length-1) newsCount=1;
	else newsCount++;
	animCount=1;
	$("#newsanimation").attr("src","assets/images/newsframe0.png").stop(true,true).show();
	nextIntervalID=setInterval('animateNextNews()',25);
	$("#news").fadeOut(200,function()
		{
		$("#news").html(newsTexts[newsCount]);
		$("#count").html(newsCount);
		$("#news").show();
		});
	}

function animateNextNews()
	{
	if (animCount<17)
		{
		newsrc="assets/images/newsframe"+animCount+".png";
		$("#newsanimation").attr("src",newsrc);
		animCount++;
		}
	else
		{
		$("#newsanimation").stop(true,true).hide();
		clearInterval(nextIntervalID);
		}
	}
	
function toPrevNews()
	{
	if (newsCount==1) newsCount=newsTexts.length-1;
	else newsCount--;
	animCount=15;
	$("#newsanimation").attr("src","assets/images/newsframe16.png").stop(true,true).show();
	prevIntervalID=setInterval('animatePrevNews()',25);
	$("#news").fadeOut(200,function()
		{
		$("#news").html(newsTexts[newsCount]);
		$("#count").html(newsCount);
		setTimeout("$('#news').show()",300);
		});
	}
	
function animatePrevNews()
	{
	if (animCount>-1)
		{
		newsrc="assets/images/newsframe"+animCount+".png";
		$("#newsanimation").attr("src",newsrc);
		animCount--;
		}
	else
		{
		$("#newsanimation").stop(true,true).hide();
		clearInterval(prevIntervalID);
		}
	}
	
function animateDiscoBall()
	{
	discoX+=100;
	newpos="0px -"+discoX+"px";
	$("#discoballanimation").css({"background-position":newpos});
	if (x==600) x=0;
	}
	
function addSparkle(k)
	{
	randTrig=Math.random()*50;
	randRadius=Math.random()*50;
	$("#sparkle"+k).css({"top":483+randRadius*Math.sin(randTrig), "left":238+randRadius*Math.cos(randTrig)}).fadeIn(300,function()
		{
		$(this).fadeOut(240);
		});		
	}

//////////////	
$(document).ready(function()
	{
	$("#discoballanimation").fadeTo(0,0.8);
	$("#totalnews").html(newsTexts.length-1);
	$("#news").html(newsTexts[1]);
	slideChangeTimer=setInterval("slideshow()",6000);
	setInterval('animateDiscoBall()',40);
	setInterval('addSparkle(0)',500);
	setInterval('addSparkle(1)',510);
	setInterval('addSparkle(2)',520);
	setInterval('addSparkle(3)',530);
	setInterval('addSparkle(4)',540);
	setInterval('addSparkle(5)',550);
	setInterval('addSparkle(6)',560);
	setInterval('addSparkle(7)',570);
	setInterval('addSparkle(8)',580);
	setInterval('addSparkle(9)',590);	
	$("#prevnews, #nextnews, #prevslide, #nextslide").fadeTo(100,0.2);
	for (i=1; i<=9; i++)
		{
		initposX[i]=Number($("#photo"+i).css("left").replace(/px/,""));
	    initposY[i]=Number($("#photo"+i).css("top").replace(/px/,""));
		}
	$("#photoarea").mousemove(function(event)
		{
		if (event.layerX)	
			{
			posX=event.layerX;
			posY=event.layerY;
			}
		else
			{
			posX=event.offsetX;
			posY=event.offsetY;
			}
		radius=Math.round(Math.sqrt(Math.pow((posX-250),2)+Math.pow((posY-250),2)));
		if (radius<=249)
			{
			for (i=1; i<=9; i++)
				{
				newX=initposX[i]+(Math.abs(radius-250)*directionX[i])+"px";
				newY=initposY[i]+(Math.abs(radius-250)*directionY[i])+"px";
				$("#photo"+i).css({"left":newX,"top":newY});
				}
			}
		});
	$("#tophotogal").hover(function(){slideshowHover=1},function(){slideshowHover=0});
	$("#newsnote, #news, #prevnews, #nextnews").hover(function()
		{newsHover=1},
		function(){newsHover=0});
	autoChangeTimer=setInterval('autoChangeNews()',7000);
	$("#prevnews, #nextnews, #prevslide, #nextslide").hover(function()
		{
		$(this).stop(true,true).fadeTo(300,1);
		},function()
		{
		$(this).stop(true,true).fadeTo(300,0.3);
		});
	$("#prevnews, #nextnews").click(function()
		{
		clearInterval(autoChangeTimer);
		autoChangeTimer=setInterval('autoChangeNews()',5000);
		newsHover=1;
		if ($(this).attr("id")=="nextnews")	toNextNews();
		else toPrevNews();
		return false;
		});
	$("#navparty").hover(function()
		{
		expand(150,500);
		$("#textparty").fadeIn(1000);
		},function()
		{
		contract(150,500);
		$("#textparty").stop(true,true).hide();
		});
	});
