var popup_is_opened = 0;

function popupOpen()
{
	popup_is_opened = 1;
}

function popupClosed()
{
	popup_is_opened = 0;
}

function addEvent(elm, evType, fn, useCapture)
{
	if (elm.addEventListener)
	{
		elm.addEventListener(evType, fn, useCapture);
		return true;
	}
	else if (elm.attachEvent)
	{
		var r = elm.attachEvent('on' + evType, fn);
		return r;
	}
	else
	{
		elm['on' + evType] = fn;
	}
}

function sendVoteTop20 (element,entity_id,mark)
{
	var url = baseURL + 'index.php';
	var parameters = '&module=top20&action=vote&entity_type_id=17&entity_id='+entity_id+'&mark='+mark+'&ajx=1';
	updDiv = 'score_'+entity_id;
	new Ajax.Request(url, 
	{
		method:'get',
		parameters:parameters,
		onSuccess: function (transport)
		{
			var objResponse = transport.responseText.evalJSON();
			
			try{
				if(objResponse['msg'] == 'login')
				{
					loginUser(element, 'top');
				}
				else if(objResponse['msg'])
				{
					new Effect.Highlight('stars_'+entity_id, { restorecolor: '#ddaaaa' });
					$('stars_'+entity_id).innerHTML = objResponse['msg'];
					Effect.Pulsate('stars_'+entity_id, { pulses: 1, duration: 1 });
				}else
				{					
					new Effect.Highlight('score_'+entity_id, { restorecolor: '#ffff99' });
					$('score_'+entity_id).innerHTML = objResponse['score'];
					Effect.Pulsate('score_'+entity_id, { pulses: 1, duration: 1 });
				}
			}catch(e)
			{
				alert(e);
			}

		}
	
	});
	
	return false;
}


function sendVote(entity_id,entity_type_id,mark,module,action)
{
	if(!module)
	{
		module='gallery';
	}
	
	if(!action)
	{
		action='vote';
	}
	
	var url='/index.php';
	var parameters = '&module='+module+'&action='+action+'&entity_type_id='+entity_type_id+'&entity_id='+entity_id+'&mark='+mark;
	
	new Ajax.Request(url, 
	{
	method:'get',
	parameters:parameters,
	onSuccess:responseVote2
	
	});
}

function responseVote2(response)
{
	var objResponse = response.responseText.evalJSON();
	if(objResponse['message'])
	{
		alert(objResponse['message']);
	}
	else
	{
		$('item_average').innerHTML = objResponse['new_value'];
	}
}


function sendVoteBW(entity_id,entity_type_id,mark)
{
	var url='/index.php';
	var parameters = '&module=articles&action=vote&entity_type_id='+entity_type_id+'&entity_id='+entity_id+'&mark='+mark;
	
	new Ajax.Request(url, 
	{
	method:'get',
	parameters:parameters,
	onSuccess:responseVoteBW
	
	});
}

function responseVoteBW(response)
{
	var objResponse = response.responseText.evalJSON();
	try{
	if(objResponse['message'])
	{
		alert(objResponse['message']);
	}
	else
	{
		$('positive_vote_result_'+objResponse['entity_type_id']+'_'+objResponse['entity_id']).innerHTML = objResponse['new_value'];
		$('negative_vote_result_'+objResponse['entity_type_id']+'_'+objResponse['entity_id']).innerHTML = 100-objResponse['new_value'];
	}
	}catch(e)
	{
		alert(e);
	}
}

function reply(messageId)
{
	$('parent_id').value=messageId;
}



function prevPhoto(currentItem,galleryItems,galleryId)
{
	if(currentItem-1<0)
	{
		newCurrentItem = 0;
	}
	else
	{
		newCurrentItem = currentItem-1;
	}
	
	if(newCurrentItem==0)
	{
		$('prevPhoto_'+galleryId).className="disabled";
	}
	else
	{
		$('prevPhoto_'+galleryId).className="";
		if(newCurrentItem!=galleryItems.length)
		{
			$('nextPhoto_'+galleryId).className="";
		}
	}
	
	var photoPos = (newCurrentItem+1) + ' / ' + galleryItems.length;
	$('photoPos_'+galleryId).innerHTML = photoPos;
	
	var tmp = galleryItems[newCurrentItem];
	
	$('photoFrame_'+galleryId).src=tmp.link;
	$('photoTitle_'+galleryId).innerHTML=tmp.name;
	$('photoTitle_'+galleryId).href=tmp.href;
	$('photoDescription_'+galleryId).innerHTML=tmp.description;
	
	
	return newCurrentItem;
}

function nextPhoto(currentItem,galleryItems,galleryId)
{
	//alert(galleryItems.length + '|' +currentItem);
	
	if((currentItem+1)>=galleryItems.length)
	{
		newCurrentItem = currentItem;
	}
	else
	{
		newCurrentItem = currentItem+1;
	}
	
	if(newCurrentItem+1>=galleryItems.length)
	{
		$('nextPhoto_'+galleryId).className="disabled";
	}
	else
	{
		$('nextPhoto_'+galleryId).className="";
		if(newCurrentItem!=0)
		{
			$('prevPhoto_'+galleryId).className="";
		}
	}
	
	var photoPosContent = (newCurrentItem+1) + ' / ' + galleryItems.length;
	$('photoPos_'+galleryId).innerHTML = photoPosContent;
	
	var tmp = galleryItems[newCurrentItem];
	
	$('photoFrame_'+galleryId).src=tmp.link;
	$('photoTitle_'+galleryId).innerHTML=tmp.name;
	$('photoTitle_'+galleryId).href=tmp.href;
	$('photoDescription_'+galleryId).innerHTML=tmp.description;
	
	return newCurrentItem;
}

function addAllToPlaylist(locations, creators, titles, indexes, extensions)
{
	
}

// adauga un track la playlist
function addToPlaylist(location, creator, title, index, extension, artist_id)
{
	var url = baseURL + 'index.php';
	var params = 'module=music&action=writeTempPlaylist&url='+location+'&creator='+unescape(creator)+'&title='+unescape(title) + '&extension=' + extension + '&artist_id=' + artist_id;
	
	new Ajax.Request
	(
		url,
		{
			method:'get',
			parameters:params,
			onComplete:getTempPlaylist
						
		}
	)
	return false;
}

// reseteaza ordinea trackurilor cand se modifica playlistul
function reinitPlayer()
{
	initPlayer();
	isPlaying(actual_track);
	if(removed_while_playing == 1 || (opener && opener.removed_while_playing == 1))
	{
		if(opener && opener.removed_while_playing == 1)
		{
			opener.removed_while_playing = 0;
			actual_track = opener.actual_popup_track;
		}
		
		if(actual_track == tracks && repeat == "off")
		{
			bw();
			next();
		}
		else
		{
			next();
		}
	}
	if (navigator.appName == "Microsoft Internet Explorer" && window.attachEvent)
	{
		enableAlphaImages();
	}
}

// sterge toate trackurile dintr-un playlist
function clearTempPlayist()
{
	var url = baseURL + 'index.php';
	var params = 'module=music&action=clearTempPlaylist';
	var playlistDiv = 'playlistDiv';
	
	new Ajax.Updater
	(
		playlistDiv, url,
		{
			method:'get',
			parameters:params,
			onComplete: clearPopupPlaylist
													
		}
	)
	return false;
}

function clearPopupPlaylist()
{
	$$('.added').invoke('update','');
	refreshPlaylist();
}


// sterge un track din playlist
function removeTempMedia(id, position)
{
	if(position == actual_popup_track)
	{
		removed_while_playing = 1;
	}
	
	if(position <= actual_popup_track && actual_popup_track > 0)
	{
		actual_popup_track --;
	}
	
	url = baseURL + 'index.php';
	params = 'module=music&action=removeTempMedia&id='+id;
	//playlistDiv = 'playlistDiv';
	new Ajax.Request
	(
		 url,
		{
			method:'get',
			parameters:params,
			onComplete:getTempPlaylist
												
		}
	)
	return false;
}

function updateEventMonth(startDate, monthName)
{
    /* sterge clasa de pe linkul de luna veche */
    var lunile_anului = $('lunile_anului').childElements();
    lunile_anului.each(function(luna)
    {
        luna_link = luna.childElements();
        if(luna_link[0].hasClassName("aleasa"))
        {
            luna_link[0].removeClassName("aleasa");
        }
    });
    
    $("luna_"+monthName).addClassName("aleasa"); // adauga clasa de selectat la linkul lunii selectate
    currentStartDate = startDate;
	var params = 'module=events&action=calendarMonth&ajax=1&data_start='+startDate;
	new Ajax.Updater('month_content', baseURL+'/index.php',
		{
			method:'get',
			parameters:params
		}
	)
    
    $('listing_box').empty();
    var params = 'module=events&action=listingMonth&ajax=1&data_start='+startDate+'&lang_id=1';
    new Ajax.Updater('listing_box', baseURL+'index.php',
        {
            method: 'get',
            parameters: params,
            onSuccess: function(transport) 
            {
                Effect.SlideDown('listing_box', { duration: 2.0 });
            }
 
        }    
    );
	
	return false;
}

function updateEventDay(day)
{
    $('listing_box').empty();
    
    current_day = currentStartDate.truncate(2,'');
    ds = currentStartDate.sub(current_day, day);
     
    $('listing_box').empty();   
    var params = 'module=events&action=listingMonth&ajax=1&one_day='+ds+'&lang_id=1';
    new Ajax.Updater('listing_box', baseURL+'index.php',
        {
            method: 'get',
            parameters: params,
            onSuccess: function(transport) 
            {
                Effect.SlideDown('listing_box', { duration: 2.0 });
            }
 
        }    
    );
    
    return false;
}


function copyDates(from,to){
	var d = from.value;
	var temp = d.split(' ');
	var h,m,s; //de fapt sund d-m-y....
	if(temp.length>1){
		var a = temp[0].split('-');
		h = doInteger(a[2]);
		m = doInteger(a[1]);
		s = doInteger(a[0]);
		var rez = h + '-' + m + '-' + s + ' ' + temp[1];
		if(h<=0 && m <=0 && s<=0) to.value = '';
		to.value = rez;
	}else{
		var a = d.split('-');
		h = doInteger(a[2]);
		m = doInteger(a[1]);
		s = doInteger(a[0]);
		var rez = h + '-' + m + '-' + s;
		if(h<=0 && m <=0 && s<=0) to.value = '';
		to.value = rez;
	}
	//alert(a);
	//alert(rez);
	
}


function doInteger(a){
	if(typeof(a) == 'undefined') return 0;
	var b = parseInt(a);
	if(b=='NaN') return 0;
	if(trim(a)=='') return 0;
	return a;
	
}

function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") return inputString;
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
	
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length - 1, retValue.length);
	
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length - 1);
      ch = retValue.substring(retValue.length - 1, retValue.length);
   }
	
	// Note that there are two spaces in the string - look for multiple spaces within the string
   while (retValue.indexOf("  ") != -1) {
		// Again, there are two spaces in each of the strings
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ") + 1, retValue.length);
   }
   return retValue; // Return the trimmed string back to the user
}

function loginUser(element, position)
{
	if($('login_popup'))
	{
		if(position == 'top')
		{
			$('login_popup').className = 'header_login';
			$('login_popup').style.padding = '25px 32px 61px 5px';
			$('login_popup').style.background = "url('" + baseURL + "external/templates/default/images/login_bg2.gif')";
			$('login_popup').style.top = (getPos(element).topOff) + 'px';
			$('login_popup').style.left = getPos(element).leftOff + 'px';
		}
		else if(position == 'right')
		{
			$('login_popup').className = '';
			$('login_popup').style.padding = '5px 12px 61px 25px';
			$('login_popup').style.background = "url('" + baseURL + "external/templates/default/images/login_bg3.gif')";
			$('login_popup').style.top = (getPos(element).topOff - 40) + 'px';
			$('login_popup').style.left = (getPos(element).leftOff + element.offsetWidth) + 'px';
		}
		else
		{
			$('login_popup').className = '';
			$('login_popup').style.padding = '5px 32px 61px 5px';
			$('login_popup').style.background = "url('" + baseURL + "external/templates/default/images/login_bg.gif')";
			$('login_popup').style.top = (getPos(element).topOff - 40) + 'px';
			$('login_popup').style.left = (getPos(element).leftOff - 207) + 'px';
		}
		Effect.Appear('login_popup', {duration: 0.5});
		return false;
	}
}

function loginUserTop20(element)
{
	if($('login_popupTop20'))
	{
		$('login_popupTop20').className = 'header_login_top20';
		$('login_popupTop20').style.padding = '25px 32px 5px 5px';
		$('login_popupTop20').style.background = "url('" + baseURL + "external/templates/default/images/login_bg_top20.gif')";
		$('login_popupTop20').style.top = (getPos(element).topOff) + 'px';
		$('login_popupTop20').style.left = getPos(element).leftOff + 'px';

		Effect.Appear('login_popupTop20');
		return false;
	}
}

function registerNewsletter(element)
{
	$('newsletter_popup').className = 'header_login';
	$('newsletter_popup').style.top = (getPos(element).topOff) + 'px';
	$('newsletter_popup').style.left = getPos(element).leftOff + 'px';
	Effect.Appear('newsletter_popup', {duration: 0.5});
}

function enterFanclub(element)
{
	if($('subscribe_fanclub'))
	{
		$('subscribe_fanclub').style.top = (getPos(element).topOff - 40) + 'px';
		$('subscribe_fanclub').style.left = (getPos(element).leftOff - 340) + 'px';
		Effect.Appear('subscribe_fanclub', {duration: 0.5});
		return false;
	}
}

function acceptFanclub()
{
	Effect.Fade('subscribe_fanclub', {duration: 0.5});
	if($('login_popup'))
	{
		loginUser($('a_subscribe_fanclub'));
	}
	else
	{
		top.location = $('a_subscribe_fanclub').href;
	}
}

function getPos(obj, reposition) 
{
//	var leftOff = topOff = 0;
//	if (obj.offsetParent) 
//	{
//		do 
//		{
//			leftOff += obj.offsetLeft;
//			topOff += obj.offsetTop;
//		} while (obj = obj.offsetParent);
//	}

	off = Element.viewportOffset(obj);
	offseturi = document.viewport.getScrollOffsets();

	return {leftOff : off[0], topOff : off[1]+offseturi[1]};
}

function showAll(id, parent, link, items)
{
	var the_ul = $(id).getElementsByTagName('ul')[0];
	var img = link.getElementsByTagName('img')[0];
	if(id != 'fav_comments')
	{
		var more = the_ul.getElementsByTagName('li').length > items;
	}
	else
	{
		var more = the_ul.offsetHeight > 103;
	}
	if(more)
	{
		if(link.title == 'Restrange')
		{
			$(parent).style.height = '215px';
			if(id != 'galerie')
			{
				$(id).style.height = '73px';
			}
			else
			{
				$(id).style.height = '120px';
			}
			link.title = img.alt;
			img.src = baseURL + 'external/templates/default/images/down.gif';
		}
		else
		{
			$(parent).style.height = 'auto';
			$(id).style.height = 'auto';
			link.title = 'Restrange';
			img.src = baseURL + 'external/templates/default/images/up.gif';
		}
	}
	else
	{
		new Effect.Highlight(the_ul);
	}
	
	if(id == 'friends_list' && messageBoxIsOpen())
	{
		$(parent).style.height = 'auto';
	}
}

function messageBoxIsOpen()
{
	var div_messages = $('messages_box').getElementsByTagName('div');
	var is_open = 0;
	for(var i=0;i<div_messages.length;i++)
	{
		if(div_messages[i].style.display != 'none')
		{
			is_open = 1;
		}
	}
	return is_open;
}

function closeAllMessageBoxes(id)
{
	var div_messages = $('messages_box').getElementsByTagName('div');
	for(var i=0;i<div_messages.length;i++)
	{
		if(div_messages[i].title != id)
		{
			div_messages[i].style.display = 'none';
		}
	}
}

function openMessageBox(id)
{
	if(messageBoxIsOpen() || $('friends_list').style.height == 'auto')
	{
		$('friends').style.height = 'auto';
	}
	else
	{
		$('friends').style.height = '215px';
	}
}

var Carousel = function(id, item_width , total_items, items_visible, position, prev, next, srcs)
{
	this.div=id;
	this.item_width = item_width;
	this.total_items = total_items;
	this.slides_left = total_items - items_visible;
	this.total_slides = this.slides_left;
	this.items_visible = items_visible;
	this.nextTb = next;
	this.prevTb = prev;
	this.srcs = srcs;
	if(position)
	{
		this.position = position;
		this.actual_slide = position + 1;
		this.slides_left -= position;
	}
	else
	{
		this.actual_slide = 1;
	}
};

Carousel.prototype = {
	moveNext: function(moveBy)
	{
		if(this.slides_left > 0)
		{
			if(moveBy)
			{
				if(this.slides_left < moveBy)
				{
					moveBy = this.slides_left;
				}
				this.actual_slide += moveBy;
				this.slides_left -= moveBy;
				new Effect.Move(this.div, {x: -this.item_width * (this.actual_slide - 1), mode: 'absolute', duration: 0.4});
			}
			else
			{
				if( this.nextTb && this.actual_slide+10 >= this.nextTb && this.nextTb<this.total_items) {
					$('carousel1Img_' + this.nextTb ).src = this.srcs[this.nextTb];
					this.nextTb++;
				}
				
				new Effect.Move(this.div, {x: -this.item_width * this.actual_slide, mode: 'absolute', duration: 0.4});
				this.actual_slide++;
				this.slides_left--;
			}
		}
	},
	
	movePrev: function(moveBy)
	{
		if(this.slides_left < this.total_slides)
		{
			if(moveBy)
			{
				if(this.total_slides % moveBy != 0 && this.slides_left == 0)
				{
					moveBy = this.total_slides % moveBy;
				}
				this.actual_slide -= moveBy;
				this.slides_left += moveBy;
				new Effect.Move(this.div, {x: -this.item_width * (this.actual_slide - 1), mode: 'absolute', duration: 0.4});
			}
			else
			{
				if( (this.prevTb || this.prevTb === 0) && this.actual_slide-3 <= this.prevTb && this.prevTb>=0) {
					$('carousel1Img_' + this.prevTb ).src = this.srcs[this.prevTb];
					this.prevTb--;
				}
				
				new Effect.Move(this.div, {x: -this.item_width * (this.actual_slide - 2), mode: 'absolute', duration: 0.4});
				this.actual_slide--;
				this.slides_left++;
			}
		} 
	},
	
	updateProgress: function(moveBy)
	{
		var x = Math.ceil(this.actual_slide / moveBy);
		if(this.slides_left == 0 && this.actual_slide % moveBy != 1)
		{
			x++;
		}
		var y = Math.ceil(this.total_items / 3);
		$('span_page').innerHTML = x + ' din ' + y;
	}
}

function resizeCommBox(type)
{
	var is_open = true;
	if(type == 'message')
	{
		$('addWallMessage').style.display = 'none';
		if($('sendMessage').style.display == 'none')
		{
			is_open = false;
		}
	}
	else
	{
		$('sendMessage').style.display = 'none';
		if($('addWallMessage').style.display == 'none')
		{
			is_open = false;
		}
	}
	var div = $('usr_actions');
	var height = div.style.height;
	if(!height)
	{
		height = '215px';
	}
	if(height == '215px' || is_open == false)
	{
		div.style.height = 'auto';
	}
	else
	{
		div.style.height = '215px';
	}
}

function sendRegisterNewsletter_OLD()
{
	$('abonare').innerHTML = 'Te rugam, asteapta...';
	$('abonare').style.display = 'block';
	function alertNewsletter()
	{
		alert('pula');
		$('abonare').style.display = 'none';
		if($('abonare').innerHTML.indexOf('Esti inregistrat') == -1)
		{
			alert($('abonare').innerHTML);
		}
		else
		{
			if(confirm($('abonare').innerHTML))
			{
				new Ajax.Updater('abonare', baseURL + 'index.php?module=newsletter&action=subscribe', {method: 'post', parameters:{email: $('email_n').value}, onComplete: alertNewsletter});
			}
		}
		
		if($('abonare').innerHTML == 'Felicitari! Te-ai inscris la newsletter.')
		{
			Effect.Fade('newsletter_popup', {duration: 0.5});
		}
	}
	new Ajax.Updater('abonare', baseURL + 'index.php?module=newsletter&action=subscribe', {method: 'post', parameters:{email: $('email_n').value}, onComplete: alertNewsletter});
}

function sendRegisterNewsletter()
{
	$('abonare').innerHTML = 'Te rugam, asteapta...';
	$('abonare').style.display = 'block';
	
	new Ajax.Updater('abonare', baseURL + 'index.php?module=newsletter&action=subscribe', 
		{
			method: 'post', 
			parameters:{email: $('email_n').value}, 
			onComplete: alertNewsletter()
		}
	);
}

	function alertNewsletter()
	{
		$('abonare').style.display = 'none';

		Effect.Fade('newsletter_popup', {duration: 0.5});
		
		alert($('abonare').innerHTML);
		
	}
	
function resizeEmbed()
{
	var myObject = $('embedCenter').getElementsByTagName('object')[0];
	var myEmbed = $('embedCenter').getElementsByTagName('embed')[0];
	var myIframe = $('embedCenter').getElementsByTagName('iframe')[0];
	if(myObject)
	{
		if(myObject.width > 445)
		{
			var ratio = myObject.height / myObject.width;
			myObject.style.width = '445px';
			myObject.style.height = (445 * ratio) + 'px';
		}
	}
	if(myEmbed)
	{
		if(myEmbed.width > 445)
		{
			var ratio = myEmbed.height / myEmbed.width;
			myEmbed.style.width = '445px';
			myEmbed.style.height = (445 * ratio) + 'px';
		}
	}
	if(myIframe)
	{
		if(myIframe.width > 445)
		{
			var ratio = myIframe.height / myIframe.width;
			myIframe.style.width = '445px';
			myIframe.style.height = (445 * ratio) + 'px';
		}
	}
}


function breadCrumbs() {
	if ($$("div.right_200").length > 0) {
		$("bread").style.width = 746+"px";
	} else if ($$("div.right_300").length > 0) {
		$("bread").style.width = 623+"px";
	} else if ($$("div.right").length > 0) {
		$("bread").style.width = 628+"px";
	} else if ($$("div.right_0").length > 0) {
		$("bread").style.width = 949+"px";
	}
}

var CarouselGalerie9 = function(id, item_width , total_items, items_visible, position, prev, next)
{
	this.div=id;
	this.item_width = item_width;
	this.total_items = total_items;
	this.slides_left = total_items - items_visible;
	this.total_slides = this.slides_left;
	this.items_visible = items_visible;
	this.nextTb = next;
	this.prevTb = prev;
	if(position)
	{
		this.position = position;
		this.actual_slide = position + 1;
		this.slides_left -= position;
	}
	else
	{
		this.actual_slide = 1;
	}
};

CarouselGalerie9.prototype = {
	moveNext: function(moveBy)
	{
		if(this.slides_left > 0)
		{
			if(moveBy)
			{
				if(this.slides_left < moveBy)
				{
					moveBy = this.slides_left;
				}
				this.actual_slide += moveBy;
				this.slides_left -= moveBy;
				new Effect.Move(this.div, {x: -this.item_width * (this.actual_slide - 1), mode: 'absolute', duration: 0.4});
			}
			else
			{
				new Effect.Move(this.div, {x: -this.item_width * this.actual_slide, mode: 'absolute', duration: 0.4});
				this.actual_slide++;
				this.slides_left--;
			}
			
		
			if(this.slides_left == 0 && this.nextTb) {
				var url = baseURL + 'index.php?module=gallery2&action=getThumb';
				new Ajax.Request(url, 
				{
					method:'post',
					parameters: { tid: this.nextTb, ajx: 1},
					onSuccess: function (transport)
					{
						appendThumb(transport)
					}
				});
			}
		}
	},
	
	movePrev: function(moveBy)
	{
		
		
		if(this.slides_left < this.total_slides)
		{
			if(moveBy)
			{
				if(this.total_slides % moveBy != 0 && this.slides_left == 0)
				{
					moveBy = this.total_slides % moveBy;
				}
				this.actual_slide -= moveBy;
				this.slides_left += moveBy;
				new Effect.Move(this.div, {x: -this.item_width * (this.actual_slide - 1), mode: 'absolute', duration: 0.4});
			}
			else
			{
				new Effect.Move(this.div, {x: -this.item_width * (this.actual_slide - 2), mode: 'absolute', duration: 0.4});
				this.actual_slide--;
				this.slides_left++;
			}
			
			if(this.slides_left == this.total_slides && this.prevTb){
				var url = baseURL + 'index.php?module=gallery2&action=getThumb';
				new Ajax.Request(url, 
				{
					method:'post',
					parameters: { tid: this.prevTb, ajx: 1},
					onSuccess: function (transport)
					{
						shiftThumb(transport)
					}
				});
			}
		} 
		
	},
	
	updateProgress: function(moveBy)
	{
		var x = Math.ceil(this.actual_slide / moveBy);
		if(this.slides_left == 0 && this.actual_slide % moveBy != 1)
		{
			x++;
		}
		var y = Math.ceil(this.total_items / 3);
		$('span_page').innerHTML = x + ' din ' + y;
	}
}

function appendThumb(transport){
	if (transport.responseText.length){
		var objResponse = transport.responseText.evalJSON();

		carrier = eval(objResponse.carrier);
		var container = $(carrier.div);

		var div9 = document.createElement("div");
	   	div9.innerHTML = objResponse.content;
	   	div9.className = objResponse.clasa;
	   	container.appendChild(div9);

		carrier.total_items++;
		container.style.width = carrier.item_width*carrier.total_items + 'px';
		if(objResponse.nextid || objResponse.nextid==false){
			carrier.nextTb = objResponse.nextid;
		}
		carrier.slides_left++;
		carrier.total_slides++;
	}
}

function shiftThumb(transport)
{
	if (transport.responseText.length){
		var objResponse = transport.responseText.evalJSON();
		
		carrier = eval(objResponse.carrier);
		var container = $(carrier.div);
		
		var div9 = document.createElement("div");
	   	div9.innerHTML = objResponse.content;
	   	div9.className = objResponse.clasa;
	   	container.insertBefore(div9,container.childNodes[0]);
   	
	   	carrier.total_items++;
		carrier.total_slides++;
		carrier.actual_slide++;
		if (objResponse.previd || objResponse.previd==false){
			carrier.prevTb = objResponse.previd;
		}
		
		container.style.left = '-' + carrier.item_width + 'px';
		container.style.width = carrier.item_width*carrier.total_items + 'px';
		
		}
}
					
function addToCos(item, deliveryType, silent){
	var url = baseURL + 'index.php?module=gallery2&action=addToCos';
	new Ajax.Request(url, 
	{
		method:'post',
		parameters: { pid: item, tip: deliveryType, ajx: 1 },
		onSuccess: function (transport)
		{
			if (transport.responseText.length){
				var objResponse = transport.responseText.evalJSON();
				if (objResponse.status==1){
					appendThumb(transport);
					$('nrPozeCos').innerHTML++;
				}
				if( !silent ){
					alert(objResponse.message);
				} else {
					if(objResponse.status != 1 && objResponse.status != -2 ) {
						alert(objResponse.message)
					} else {
						GB_showCenter('Download Poster', silent);
					}
				}
/*				if ($cosItem['dispatch'] == 1) {
				$src = mmlinkExt($thumbId,100);
				$output = array(
							'status' => 1,
							'message' => 'OK',
							'content'=>'<div class="thumb-foto carousel_item"><a href="'.AMVC_WEB_PATH.'index.php?module=gallery2&action=view&galleryid='.$cosItem['album_id'].'&amp;itemid='.$cosItem['amvc_item_id'].'&amp;lang_id='.$req->get('lang_id').'" class="left"><img src="'.$src.'" style="margin:0px;padding:0px;height:54px;border: 2px solid #FFFFFF;" /></a><div class="clearAll"></div><a href="#" class="left padd" >Adauga</a></div>'
						);
			} elseif ( $cosItem['dispatch'] == -2 ) {
				$output = array(
							'status' => -2,
							'message' => 'Ai adaugat deja poza in cosul tau',
							'content'=>''
						);
			} elseif ( $cosItem['dispatch'] == -4 ) {
				$output = array(
							'status' => -4,
							'message' => 'Poza nu este cu vanzare',
							'content'=>''
						);
			} elseif ( $cosItem['dispatch'] == 0 ) {
				$output = array(
							'status' => 0,
							'message' => 'Nu poti adauga poza in cosul tau (nu ai drepturi)',
							'content'=>''
						);
			} elseif ( $cosItem['dispatch'] == -1 ) {
				$output = array(
							'status' => -1,
							'message' => 'Poza nu a fost adaugata in cosul tau',
							'content'=>''
						);
			} elseif ( $cosItem['dispatch'] == -3 ) {
				$output = array(
							'status' => -3,
							'message' => 'Cosul tau este plin',
							'content'=>''
						);
			}
*/
			}
		}
	});
}

function removeFromCos(pd_id, lnk){
	var url = baseURL + 'index.php?module=gallery2&action=removeFromCos';
	var copil = lnk.parentNode;
	new Ajax.Request(url, 
	{
		method:'post',
		parameters: { pd_id: pd_id, ajx: 1 },
		onSuccess: function (transport)
		{
			if (transport.responseText.length){
				var objResponse = transport.responseText.evalJSON();
				if (objResponse.status==1){
					copil.remove();
					$('nrPozeCos').innerHTML--;
					
					carrier = eval(objResponse.carrier);
					var container = $(carrier.div);
			
					carrier.total_items--;
					container.style.width = carrier.item_width*carrier.total_items + 'px';
					carrier.slides_left--;
					carrier.total_slides--;
				}
				alert(objResponse.message);
				
/*				
			if ($response['dispatch'] == 1) {
				$output = array(
							'status' => 1,
							'message' => 'Poza a fost stersa din cosul tau',
						);
			} elseif ( $response['dispatch'] == -1 ) {
				$output = array(
							'status' => -1,
							'message' => 'Poza nu a fost stearsa din cosul tau',
						);
			} elseif ( $response['dispatch'] == 0 ) {
				$output = array(
							'status' => 0,
							'message' => 'Nu ai dreptul sa stergi poze deoarece nu esti logat',
						);
			} elseif ( $response['dispatch'] == -2 ) {
				$output = array(
							'status' => 2,
							'message' => 'Poza nu exista in cosul tau',
						);
			}
*/
//starile de mai sus sunt starele posibile de raspuns la stergere
//la status 1 trebuie scos divul cu poza care tocmai a fost stersa si redimensionat divul (width carousel cos -CarouselGalerie9.item_width
			}
		}
	});
}

function downloadPicture(picId){
	var url = baseURL + 'index.php?module=gallery2&action=downloadPicture';
	new Ajax.Request(url, 
	{
		method:'post',
		parameters: { item: picId, ajx: 1},
		onSuccess: function (transport)
		{
			var objResponse = transport.responseText.evalJSON();
			if(objResponse.status == 1){
				document.location = baseURL + 'index.php?module=gallery2&action=downloadPicture&item=' + picId;
			} else {
				alert(objResponse.message);
			}
		}
	});
}

function confirmBuy(msg){
	if(!msg){
		msg = 'Descarca poster in format original pe calculatorul tau. 1 credit.';
	}
	if(confirm(msg)){
		return true;
	} else {
		return false;
	}
}

function showPacks(){
	if($('packsList').style.display == 'block'){
		$('packsList').style.display='none';
	} else {
		$('packsList').style.display='block';
	}
	$('telComanda').style.display='none';
}

function requestPhone(packId){
	comanda = $('telComanda_' + packId);
	
	if (comanda.style.display == 'block') {
		comanda.style.display = 'none';
	} else if ( comanda.style.display == 'none' ) {
		arr = $$('div.phoneRequest');
		
		for (i=0; i<arr.length; i++) {
			arr[i].style.display = 'none';
		}
		comanda.style.display = 'block';
	}
	
	$('phoneRequest_' + packId).action = baseURL + 'index.php?module=gallery2&action=registerPay&pack=' + packId + '&send=1';
	
	return false;
}

function isArray(obj) {
	if (typeof obj[0] != 'undefined') 
		return true;
	else
		return false;
}

function putSearch() {
	$('cont_search').innerHTML = $('hidden_search').innerHTML;
	$('hidden_search').innerHTML = "";
	searchType(s_type);
}

function putLeft() {
	$('cont_left').innerHTML = $('hidden_left').innerHTML;
}

function verifyEmail(form){
	var url = document.location;
	var params = { search: $F('n_email'), field: 'n_email', ajxF: 1, chaptcha: $F('n_captcha')};
		new Ajax.Request(url, 
		{
			method:'POST',
			parameters:params,
			onSuccess: function (rasp){
				if(rasp.responseText){
					$('nw_statusMessages').innerHTML = eval(rasp.responseText);
				} else {
					form.submit();
				}
			}
		});
}

function sendEditEmail(form, link){
	var url = link.href;
	$(form).action = url;
	$(form).submit();
}

function redirect(url){
	window.location = baseURL + url;
}


function initFB() {
	FB_RequireFeatures(["XFBML"], function(){
		FB.init('ce4ce7ea05a761c77dcf3349f95674a0', baseURL + 'xd_receiver.htm',
                { permsToRequestOnConnect : "email"});
	});
}

function fb_connect(){
	FB.ensureInit(
		function(){
			FB.Connect.requireSession( function(){
					var message = 'Hello world of Facebook!';

					FB.Connect.streamPublish(message);
				}
			);
		}
	);
}

Event.observe(window, 'load', breadCrumbs)
