window.addEvent('domready', function(){
	$('login').setStyle('height','auto');
	var mySlide = new Fx.Slide('login');
	mySlide.hide();

	$('toggleLogin').addEvent('click', function(e){
		e = new Event(e);
		mySlide.toggle(); //show-hide login panel
		e.stop();
	});

	$('closeLogin').addEvent('click', function(e){
		e = new Event(e);
		mySlide.slideOut(); //Hide login panel
		e.stop();
	});
});
window.addEvent('domready', function(){
	var el = $$('#posts li'),
	color = el.getStyle('backgroundColor');

	$$('#posts li').addEvents({
		mouseenter: function(){
			// We set the cursor to pointer so users know they can click this region
			this.setStyle('cursor','pointer');

			// Change background color on mouseover
			this.set('morph', {duration: 300});
			this.morph({
			'background-color': '#FFF2E6',
			'background-image': 'url(/images/arrow.jpg)',
			'background-repeat': 'no-repeat',
			'background-position': [0, 270]
			});
		},
		mouseleave: function(){
			// Morphes back to the original style
			this.morph({
			'background-image': 'none',
			'background-color': color
			});
		}
	});


	//We retrieve the link location (href) and assign it to LI to make the whole region clickable
	var link = $$('#posts li a');
	link.each(function(element) {
		element.getParent().getParent().addEvent('click', function(){
			window.location = element.get('href');
		});
	});
});
function flashObject(targetObject) {
	var myEffects = new Fx.Morph(targetObject, {duration: 2000});

	myEffects.start({
	'opacity': 0
	});
	myEffects.onComplete=function() {
		$(targetObject).setStyle("display","none");
		$(targetObject).setStyle("visibility","visible");
		$(targetObject).setStyle("opacity",1);
	}
}
function slideOutObject(targetObject) {
	var myVerticalSlide = new Fx.Slide(targetObject);
	myVerticalSlide.slideOut();
}


function submitComment() {
	var log = $('log_res');
	log.empty().addClass('ajax-loading');
	$('contnou').set('send', {onComplete: function(response) {
		log.removeClass('ajax-loading');
		if(response=='') {
			var myVerticalSlide = new Fx.Slide('formComentarii');
			myVerticalSlide.slideOut();
			resetForm('contnou');
			$('commOk').style.display="block";
			$('commOk').style.visibility="visible";
			setTimeout('flashObject(\'commOk\')',5000);
			setTimeout('addNewComments();',2000);
		}
		else {
			log.empty();
			log.set('html',response);
		}
	}});
	$('contnou').send();
};

function addNewComments() {
	var idTinuta=$('idTinuta').value;
	var req = new Request.JSON({url:'/submitChestiiTinuta/getComments/'+idTinuta+'/'+ultimulComentariu+'/',
		onSuccess: function(response) {
			nrComentarii=nrComentarii+response.length;
			$('nrcomentarii').set('html',nrComentarii);
			response.each(function(item, index){
				addNewComment(item['id'],item['nume'],item['comentariu'],item['dataIntroducerii']);
				ultimulComentariu=item['id'];
			});
		}
	});
	req.send();
}
function ymessengerCount(numar) {
	var req = new Request.JSON({url:'/cont/social/'+numar+'/'});
	req.send();
}
function addNewComment(id,nume,comentariu,dataIntroducerii) {
	var container=$('commentContainer');
	var newCommentContainer = new Element('div');
	newCommentContainer.set('id','newcommentBox'+id);
	newCommentContainer.set('style','margin-bottom:10px;');

	var newComment= new Element('div');
	newComment.set('class','commentBox');
	newComment.set('html',comentariu+'<div class="commentBoxImg"></div>');
	newComment.inject(newCommentContainer);

	var newCommentDetails= new Element('div');
	newCommentDetails.set('class','commentDetails');
	newCommentDetails.set('html','<b>'+nume+'</b> '+dataIntroducerii);
	newCommentDetails.inject(newCommentContainer);

	newCommentContainer.inject(container,'top');

	var myVerticalSlide = new Fx.Slide('newcommentBox'+id);
	myVerticalSlide.hide();
	myVerticalSlide.slideIn();
}
function voteazaTinuta(idTinuta, vot) {
	var myRequest = new Request({method: 'get', url: '/submitChestiiTinuta/vot/'+idTinuta+'/'+vot});
	myRequest.send();





	if(vot=='imiplace')	var elementId='vot_up';
	else var elementId='vot_down';
	var currentElement=$(elementId);
	var nrVoturi=currentElement.innerHTML.toInt();
	var myEffects = new Fx.Morph(elementId, {duration: 300, transition: Fx.Transitions.Sine.easeOut});
	myEffects.start({
	'opacity': 0.3
	});
	myEffects.onComplete = function() {
		currentElement.addClass('vot_active');
		currentElement.innerHTML=(nrVoturi+1)+" voturi";
		var myEffects2 = new Fx.Morph(elementId, {duration: 300, transition: Fx.Transitions.Sine.easeOut});

		myEffects2.start({
		'opacity':1
		});
	}
	$('vot_up').set('onclick','return false;');
	$('vot_down').set('onclick','return false;');
}
function redirectTimed(url,timp) {
	timp--;
	if(timp==0) window.location=url;
	else {
		$('timer').innerHTML=timp;
		setTimeout('redirectTimed(\''+url+'\','+timp+')',1000);
	}
}
function confirmDelete(delUrl) {
	if (confirm("Sigur stergeti?")) {
		document.location = delUrl;
	}
}
function checkSubmit(e,formname) {
	var keynum;
	var keychar;
	var numcheck;
	if(window.event) // IE
	{
		keynum = e.keyCode;
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
		keynum = e.which;
	}
	if(keynum==13) $(formname).submit();
	return true;
}

