$(document).ready(function()
{
	 //Header, select my dog dropdown
	 $('.my_dogs_select').hover(
		function()
		{			
			$(".my_dogs_selection").show();
		},
		function()
		{			
			$(".my_dogs_selection").hide();		
		}
	);					

	//Click to change view
	$('.gifts .links a').click(
		function(event)
		{
			$('.gifts .gifts_results').hide();
			$('.gifts .links a').removeClass('active');
			$(this).addClass('active');
			$('.gifts .gifts_results').hide();
			var show=$(this).attr("show");			
			$('.gifts .'+show).show();
			switch (show)
			{
			case 'gifts_family':
			  $('.gifts .atrinkti').hide();
			  break
			case 'gifts_friends':
			  $('.gifts .atrinkti').hide();
			  $('.gifts #atrinkti1').show();
			  break
			case 'gifts_all':
			  $('.gifts .atrinkti').hide();
			  $('.gifts #atrinkti2').show();
			  break
			}
			event.preventDefault();
		}		
	);
	
	//Move infotooltip with mouse movements
	$(".gifts_items a").mousemove(mouse_move_title);
	
	//Gallery with fancybox lightbox
	if ($().fancybox != undefined && typeof($().fancybox) == 'function')
        $(".gallery a").fancybox();
	
	
	//Zurnalas Suo, vote for article
	 $('.vote_block .vote').hover(
		function()
		{
			var text=$(this).attr("title");
			$(".vote_block .vote_comment").html(text);
			$(".vote_block .vote_comment").removeClass('na');
		},
		function()
		{
			$(".vote_block .vote_comment").addClass('na');
		}
	);
	
	//Zurnalas Suo, vote for article
	$('.vote').click(
		function(event)
		{			
			var params=$(this).attr("ref");						
			var url="src/pages/vote_for_article.php";	
			$.get(url,
			{ 
				params: params
			},
			function(rating){				
				if (rating) {
					var rating=rating-0;
					if (rating>0) var rating='+'+rating;					
					$(".vote_block .rating span").html(rating);					
				}
			});						
			$(".vote_block .vote_tools a").remove();			
			event.preventDefault();			
		}
	);
	
	 //Blogai voting over
	 $('.vote_block .vote2').hover(
		function()
		{
			var text=$(this).attr("title");
			$(".vote_block .vote_comment").html(text);
			$(".vote_block .vote_comment").removeClass('na');
		},
		function()
		{
			$(".vote_block .vote_comment").addClass('na');
		}
	);
	
	
	//Blogai voting
	$('.vote2').click(
		function(event)
		{			
			var params=$(this).attr("ref");						
			var url="src/pages/vote_for_blog.php";	
			$.get(url,
			{ 
				params: params
			},
			function(rating){				
				if (rating) {
					var rating=rating-0;
					if (rating>0) var rating='+'+rating;					
					$(".vote_block .rating span").html(rating);					
				}
			});						
			$(".vote_block .vote_tools a").remove();			
			event.preventDefault();			
		}
	);
	
});

function mouse_move_title(event) {	
	$(".info_block",this).css('top', event.pageY + 1);
	$(".info_block",this).css('left', event.pageX + 1)
}

function mouse_move_title2(event) {	
	$(".info_block",this).css('margin-top', event.pageY + 1);
	$(".info_block",this).css('margin-left', event.pageX + 1)
}

function selectGift(gift) {
	$('.gifts .gifts_items a img').removeClass('active');
	$('img',gift).addClass('active');
	var gift_id=$(gift).attr("gift_id");
	$('.gift_value').attr({value : gift_id});			
	return ret_false();
}

function showToolTip(image) {	
	$('.info_block',image).show();	
}

function showToolTip2(image) {	
	//$(image).mousemove(mouse_move_title2);
	$('.info_block',image).show();	
}

function hideToolTip(image) {
	$('.info_block',image).hide();
}

//Dog mouseover
function dogOver(dog) {	
	var parent1=$(dog).parent();
	$('.info_block',parent1).show();
	$(".gifts_results .item").mousemove(mouse_move_title);
}	

//Dog mouseout
function dogOut(dog) {	
	var parent1=$(dog).parent();
	$('.info_block',parent1).hide();
}	
		
//Dog click
function dogClick(dog) {	
	$('.gifts .item .photo').removeClass('photo_active');	
	$(dog).addClass('photo_active');
	var dog_id=$(dog).attr("dog_id");
	$('.dog_value').attr({value : dog_id});	
	$('.dog_'+dog_id).addClass('photo_active');
	$.get("src/pages/add_session.php", { name: "selected_dog_id", value: dog_id });	
	return ret_false();
}

//Change breed	
function breed1Change() {	
	var dog_name=$('.dog_name1').attr("value");
	var breed=$('.breed1').val();			
	var url=$(".uri_current").attr("value")+',giftdogs.1,onlyfriends.1';			
	$(".gifts_friends").html('<div class="c"><img src="'+$.bone.image_path+'/indicator.gif"/></div>');
	$(".gifts_friends").load(url,
		{
			breed: breed,
			dog_name: dog_name
		}
	);	
}

//Change name
var search_timeout=undefined;
function dogname1Change() {	
	if(search_timeout!= undefined)  clearTimeout(search_timeout);                     
    search_timeout = setTimeout(function()
    { 
		var dog_name=$('.dog_name1').attr("value");		
		var breed=$('.breed1').val();			
		var url=$(".uri_current").attr("value")+',giftdogs.1,onlyfriends.1';				
		$(".gifts_friends").html('<div class="c"><img src="'+$.bone.image_path+'/indicator.gif"/></div>');
		$(".gifts_friends").load(url,
			{
				breed: breed,
				dog_name: dog_name
			}
		);	
	}, 700);	
}


//Change breed
function breed2Change() {	
	var dog_name=$('.dog_name2').attr("value");
	var breed=$('.breed2').val();			
	var url=$(".uri_current").attr("value")+',giftdogs.1';
	$(".gifts_all").html('<div class="c"><img src="'+$.bone.image_path+'/indicator.gif"/></div>');
	$(".gifts_all").load(url,
		{
			breed: breed,
			dog_name: dog_name
		}
	);	
}

//Change name
var search_timeout=undefined;	
function dogname2Change() {	
	if(search_timeout!= undefined)  clearTimeout(search_timeout);                     
    search_timeout = setTimeout(function()
    { 
		var dog_name=$('.dog_name2').attr("value");		
		var breed=$('.breed2').val();			
		var url=$(".uri_current").attr("value")+",giftdogs.1";
		$(".gifts_all").html('<div class="c"><img src="'+$.bone.image_path+'/indicator.gif"/></div>');
		$(".gifts_all").load(url,
			{
				breed: breed,
				dog_name: dog_name
			}
		);
	},700);
}

//Change page
function changePage(object) {	
	var url=$(object).attr("href");
	var parent1=$(object).parent();
	var parent2=parent1.parent();
	
	var block_name=$(parent2).attr("block_name");
	if (block_name=='friends') {	
		var dog_name=$('.dog_name1').attr("value");
		var breed=$('.breed1').val();
	}
	if (block_name=='all') {	
		var dog_name=$('.dog_name2').attr("value");
		var breed=$('.breed2').val();
	}
	$(parent2).html('<div class="c"><img src="'+$.bone.image_path+'/indicator.gif"/></div>');
	$(parent2).load(url,
		{
			breed: breed,
			dog_name: dog_name
		}
	);
	return ret_false();
}

//Submit gift selection form
function submitGift() {	
	var gift_value=$(".gift_value").attr("value");
	var dog_value=$(".dog_value").attr("value");
	var sender=$(".sender_select").val();
	var url=$(".uri_current").attr("value")+',sendsms.1';	
	if (gift_value && dog_value && sender && sender!='Tavo vardas') {
		$(".select_gift").hide();
		$(".sendsms").show().html('<div class="c"><img src="'+$.bone.image_path+'/indicator.gif"/></div>').load(url,
			{
				gift: gift_value,
				dog: dog_value,
				sender: sender
			}
		);
		$('html').scrollTop(0);
	} else {
		if (!gift_value) alert('Pasirinkite dovanėlę kurią dovanosite');
		else if (!dog_value) alert('Pasirinkite kam dovanosite dovanėlę');
		else if (!sender || sender=='Tavo vardas') alert('Įveskite arba pasirinkite nuo ko dovanosite dovanėlę');
	}
	return ret_false();
}


//Submit gift selection form
function returnToGifts() {	
	$(".select_gift").show();
	$(".sendsms").hide();		
	return ret_false();
}

//SMS response
function responseSMS(id) {	
	var url="src/pages/responsesms.php";	
	$.get(url,
	{ 
		id: id
	},
	function(data){		
		if (data.indexOf('sms_received')>0) {
			$(".select_gift").hide();			
			$(".sendsms").hide();
			$('.responsesms').html(data);
			$('html').scrollTop(0);
			smsdone=1;
		} else {
			 if (!isdefined('smsdone')) {
				setTimeout("responseSMS("+id+")", 5000);	
			}
		}
	});	
}



function isdefined( variable) {
    return (typeof(window[variable]) == "undefined")?  false: true;
}


/***************************** FUNCTIONS FOR POPUP ***************************************/


function padovanokPopup(dog_id) {	
	$("#gift_popup").show();
	var url=$(".gifts_uri").attr("value")+',selectgift.1,dog_id.'+dog_id;	
	$("#gift_popup .select_gift").show().html('<div class="c"><img src="'+$.bone.image_path+'/indicator.gif"/></div>');
	$.get(url, function(data){		
		document.getElementById('select_gift').innerHTML = data;		
		//$('#select_gift').html(data);
	});		
	return ret_false();
}

//Submit gift selection form
function submitGift2() {	
	var gift_value=$(".gift_value").attr("value");
	var dog_value=$(".dog_value").attr("value");
	var sender=$(".sender_select").val();
	var url=$(".gifts_uri").attr("value")+',sendsms.1';	
	if (gift_value && dog_value && sender && sender!='Tavo vardas') {
		$(".select_gift").hide();
		$(".sendsms").show().html('<div class="c"><img src="'+$.bone.image_path+'/indicator.gif"/></div>').load(url,
			{
				gift: gift_value,
				dog: dog_value,
				sender: sender
			}
		);
		$('html').scrollTop(0);
	} else {
		if (!gift_value) alert('Pasirinkite dovanėlę kurią dovanosite');		
		else if (!sender || sender=='Tavo vardas') alert('Įveskite arba pasirinkite nuo ko dovanosite dovanėlę');
	}
	return ret_false();
}

//Close Popup
function closePopup() {
	var response_html=$(".responsesms").html();	
	if (response_html.length>1) { location.reload(); }
	
	$("#gift_popup").hide();
	$(".select_gift").html('');
	$(".sendsms").html('');
	$(".responsesms").html('');	
}

//Close Popup
function closePopup2(popup) {	
	var popup_parent=$(popup).parent();
	$(popup_parent).hide();	
}


function ret_false() {	
	try
	 {
	  // VISTA IE 7
	  window.event.returnValue = false;
	 } catch (error)
	 {
	  // ALL OTHER (MOZILLA, OPERA, SAFARI, IE 6 & 7 ON XP)
	  return false;
	 }	
}


function addToFavorites() {
  /* puslapio adresas */
  var urlAddress = "http://www.bone.lt"; 
  /* puslapio aprašymas */
  var pageName = "Bone.lt"; 
  
  if (document.all) {
    window.external.AddFavorite(urlAddress,pageName)
  }
  else {
    alert("Norėdami įtraukti šį puslapį į adresyną naudokitės komanda: Ctrl+D"); 
  } 
}



function NewWindow(mypage, myname, w, h) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars=no ,resizable=no'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { 
		win.window.focus();
	}
}

function NewImageWindow(mypage, myimage, myname) {
  function getWidthAndHeight() {
    alert("'" + this.name + "' is " + this.width + " by " + this.height + " pixels in size.");
    return true;
  }
  function loadFailure() {
    alert("'" + this.name + "' failed to load.");
    return true;
  }  

function openWindow() {
    var winl = (screen.availWidth - this.width) / 2;
    var wint = (screen.availHeight - this.height) / 2;
    winprops = 'height='+this.height+',width='+this.width+',top='+wint+',left='+winl+',scrollbars=no,resizable=no'    
    win = window.open(mypage, '', winprops);
    if (parseInt(navigator.appVersion) >= 4) {win.window.focus();}
    return true;
  }

  var myImage = new Image();
  myImage.name = myimage;
  myImage.onload = openWindow;
  myImage.onerror = loadFailure;
  myImage.src = myimage;
}


// Miscellaneous useful functions

function showRow(row_id)
{
	el = document.getElementById(row_id);	
	if (el)
	{
		try
		{
			// Mozilla, Opera, Safari
			document.getElementById(row_id).style.display = 'table-row';
		}
		catch ( error )
		{
			// IE
			document.getElementById(row_id).style.display = 'inline';
		}
	}
}

function hideRow(row_id)
{
	el = document.getElementById(row_id);	
	if (el)
		document.getElementById(row_id).style.display = 'none';
}

// Return false, specially for windows vista ie 7
function retFalse()
{
	try
	{
		// VISTA IE 7
		window.event.returnValue = false;
	} catch (error)
	{
		// ALL OTHER (MOZILLA, OPERA, SAFARI, IE 6 & 7 ON XP)
		return false;
	}
}



/*Tomo briedai eventu popup'ui....turbut....*/

var selected_id = null;
var dom = document.getElementById;

function swapIt(id, newclass) {
	if(dom) {
		if(selected_id != id) {
			el = document.getElementById(id);
			el.className = newclass;
			el.style.cursor = (document.all) ? "hand" : "pointer";
		}
	}
}

function down (id, oldclass, newclass){
	if(dom) {
		if(selected_id != null) {
			document.getElementById(selected_id).className = oldclass;
		}
		el.className = newclass;
		selected_id = id;
	}
}


function swapIt(id, newclass) {
	if (dom) {
		if(selected_id != id) {
			el = document.getElementById(id);
			el.className = newclass;
			el.style.cursor = "hand";
			el.style.cursor = "pointer";
		}
	}
}

function down (id,oldclass,newclass){
	if (dom) {
		if(selected_id != null) {
			document.getElementById(selected_id).className = oldclass;
		}
	el.className = newclass;
	selected_id = id;
	}
}







function showHideWhyNo(){
	var value=$('input[name=internet_buy]:checked').val();	
	if (value==1) $(".why_no").hide();
	if (value==0) $(".why_no").show();
}

function showHideDryBlock(){	
	if ($('input[name=dry]').is(':checked'))
	{
	  $(".dry_block").show();
	} else {
		$(".dry_block").hide();
	}	
}

function showHideWetBlock(){	
	if ($('input[name=wet]').is(':checked'))
	{
	  $(".wet_block").show();
	} else {
		$(".wet_block").hide();
	}	
}

function LoadFoodProducts(manufacturer,type){	
	$('.manufacturer'+type+'_loading').html('<img src="'+$.bone.image_path+'/indicator.gif"/>');
	$('.product'+type+'_block').hide();
	var manufacturer=$(manufacturer).val();	
	if (manufacturer && type) {		
		$.get("src/pages/loadProducts.php", {"manufacturer": manufacturer, "type" : type}, function(data){
			if(data.length >0) {				
				$('.product'+type+'_block').show();
				$('.product'+type).html(data);
				$('.manufacturer'+type+'_loading').html('');
				$('.product'+type+'_selection').show();
			} else {
				$('.product'+type+'_block').show();							
				$('.product'+type+'_selection').hide();
				$('.manufacturer'+type+'_loading').html('');
			}
		});
	} else{
		$('.product'+type+'_block').hide();
		$('.product'+type).html('');
		$('.manufacturer'+type+'_loading').html('');
	}
	$('.weight'+type+'_block').hide();	
}


function LoadFoodWeights(product,type){	
	$('.product'+type+'_loading').html('<img src="'+$.bone.image_path+'/indicator.gif"/>');
	$('.weight'+type+'_block').hide();
	var product=$(product).val();	
	if (product) {		
		$.get("src/pages/loadWeights.php", {"product": product}, function(data){
			if(data.length >0) {				
				$('.weight'+type+'_block').show();
				$('.weight'+type).html(data);
				$('.product'+type+'_loading').html('');
			} else {
				if (type==1) {
					$('.weight'+type+'_block').show();
					$('.weight'+type).hide('');
					$('.weight'+type+'_other').show('');
				}				
				$('.product'+type+'_loading').html('');
			}
		});
	} else{
		$('.weight'+type+'_block').hide();
		$('.weight'+type).html('');
		$('.product'+type+'_loading').html('');
	}
}

function validateSurveyForm(){
			
	if (!$('input[name=dry]').is(':checked') && !$('input[name=wet]').is(':checked')) {
		alert('Pasirinkite kokiu maistu šeriate savo augintinį');		
		return ret_false();
	} 
	
	if ($('input[name=dry]').is(':checked')) {
		if (!$(".manufacturer1").val() && !$('input[name=manufacturer1_other]').val()) 
		{
			alert('Pasirinkite arba įrašykite sauso maisto gamintoją');		
			return ret_false();
		}
	}
	
	if ($('input[name=dry]').is(':checked') && $(".manufacturer1").val()) {
		if (!$(".product1").val() && !$('input[name=product1_other]').val()) 
		{
			alert('Pasirinkite arba įrašykite sauso maisto produktą');		
			return ret_false();
		}
	} 
	
	if ($('input[name=wet]').is(':checked')) {
		if (!$(".manufacturer2").val() && !$('input[name=manufacturer2_other]').val()) {
			alert('Pasirinkite arba įrašykite drėgno maisto gamintoją');		
			return ret_false();
		}
	} 
	
	if ($('input[name=wet]').is(':checked') && $(".manufacturer2").val()) {
		if (!$(".product2").val() && !$('input[name=product2_other]').val()) 
		{
			alert('Pasirinkite arba įrašykite drėgno maisto produktą');		
			return ret_false();
		}
	} 
	
	if (!$('input[name=internet_buy]').is(':checked')) {		
		alert('Pasirinkite ar pirktumėte prekes internetinėje parduotuvėje?');
		return ret_false();
	}	 			
}

function navigateNews(direction,stop){
	var size=$(".extra_news .text").size();	
	if (!isdefined('current')) current=1;	
	if (direction=='forward') current=current+1;
	if (direction=='back') current=current-1;
	if (current==0) current=size;
	if (current>size) current=1;	
	$(".extra_news .text").hide();
	$(".extra_news .image").hide();
	$(".extra_news .rotate_item_"+current).show();	
	if (stop==1) clearTimeout(navigateNewstimeout);	
	return ret_false();
}

function autoNavigateNews(){
	function rotate()
    { 
		navigateNews('forward',0);
		navigateNewstimeout=setTimeout(rotate,6000);
	}
	navigateNewstimeout=setTimeout(rotate,6000);
}


function navigateBlogs(direction,stop){		
	var size=$(".rotating_blogs .item").size();	
	if (!isdefined('navigateBlogsCurrent')) navigateBlogsCurrent=1;	
	if (direction=='forward') navigateBlogsCurrent=navigateBlogsCurrent+1;
	if (direction=='back') navigateBlogsCurrent=navigateBlogsCurrent-1;		
	
	if (navigateBlogsCurrent==0) navigateBlogsCurrent=size;
	if (navigateBlogsCurrent>size) navigateBlogsCurrent=1;	
	
	if (navigateBlogsCurrent==1) $(".rotating_blogs .previous").html('<img src="'+$.bone.image_path+'/previous_arrow2.gif"/>'); else $(".rotating_blogs .previous").html('<img src="'+$.bone.image_path+'/previous_arrow.gif"/>');
	if (navigateBlogsCurrent==size) {
		$(".rotating_blogs .next").html('<img src="'+$.bone.image_path+'/next_arrow2.gif"/>');		
	}	
	else $(".rotating_blogs .next").html('<img src="'+$.bone.image_path+'/next_arrow.gif"/>');	
	$(".rotating_blogs .item").hide();
	$(".rotating_blogs .item").hide();
	$(".rotating_blogs .rotate_item_"+navigateBlogsCurrent).show();	
	if (stop==1) clearTimeout(navigateBlogstimeout);	
	return ret_false();
}

function autoNavigateBlogs(){	
	function rotate()
    {		
		navigateBlogs('forward',0);
		navigateBlogstimeout=setTimeout(rotate,6000);
	}
	navigateBlogstimeout=setTimeout(rotate,6000);
}




function Check_search_form() 
{		
	if (document.search_form.q.value==""){
		document.search_form.q.focus();
		return ret_false();
	}
}


$.extend(
{
    insertAtCaret : function(area, myValue)
    {
        $(area).each(function()
        {
            //IE support
            if (document.selection)
            {
                this.focus();

                //in effect we are creating a text range with zero
                //length at the cursor location and replacing it
                //with myValue
                sel = document.selection.createRange();
                sel.text = myValue;
            }

            //Mozilla/Firefox/Netscape 7+ support
            else if (this.selectionStart || this.selectionStart == '0')
            {

                //Here we get the start and end points of the
                //selection. Then we create substrings up to the
                //start of the selection and from the end point
                //of the selection to the end of the field value.
                //Then we concatenate the first substring, myValue,
                //and the second substring to get the new value.
                var startPos = this.selectionStart;
                var endPos = this.selectionEnd;
                this.value = this.value.substring(0, startPos)+ myValue+ this.value.substring(endPos, this.value.length);
                this.selectionStart = startPos + myValue.length;
                this.selectionEnd	= this.selectionStart;
            }
            else
            {
                this.value += myValue;
            }
        });
    }
});


var imageUploaderWorking = false;

//Function performs form submit in iframe and uploads image for preview
function uploadImage() {
    if (imageUploaderWorking == false) {
        imageUploaderWorking = true;        
		$('.upload_status').html('<img src="'+$.bone.image_path+'/indicator.gif"/>');
        $('#uploadForm').attr({target : 'upload_picture_iframe'});
        $('#uploadForm').attr({action : document.location+',ajax.1,action.uploadImage'});
        $('#uploadForm').submit();
        $('#uploadForm').removeAttr('target');
        $('#uploadForm').removeAttr('action');
    }
    return ret_false();
}

/*
 * Remove an image, specified by index, from a list of uploaded images.
 */
function removeImage(index)
{
    if (imageUploaderWorking == false)
    {
        imageUploaderWorking = true;
        
        if ($('.preview_photo' + index + '_added').length > 0 && $('.preview_photo' + index + '_added').val() == 1)
        {
            $('.preview_photo' + index).attr('src', '');
            $('.preview_photo' + index + '_edit_src').attr('src', '');
            $('.preview_photo' + index + '_added').val(0);
            
            $("input[type='hidden'][name='remove_photo']").val(index);
            $('#uploadForm').attr({target : 'upload_picture_iframe'});
            $('#uploadForm').attr({action : document.location+',ajax.1,action.removeImage'});
            $('#uploadForm').submit();
            $('#uploadForm').removeAttr('target');
            $('#uploadForm').removeAttr('action');
            
            for (var i = index; i <= $.bone.photo_upload.max_photos; i++)
            {
                var next = i;
                next++;
                
                if (i < $.bone.photo_upload.max_photos && $('.preview_photo' + next + '_added').val() == 1)
                {
                    $('.preview_photo' + i).attr('src', $('.preview_photo' + next).attr('src'));
                    $('.preview_photo' + i).show();
                    $('.preview_photo' + i + '_added').val(1);
                    $('.preview_photo_remove' + i).show();
                    $('.preview_photo' + i + '_edit_src').val($('.preview_photo' + next + '_edit_src').val());
                    $('.preview_photo' + i + '_new').val($('.preview_photo' + next + '_new').val());
                }
                else
                {
                    $('.preview_photo' + i).attr('src', '');
                    $('.preview_photo' + i).hide();
                    $('.preview_photo' + i + '_added').val(0);
                    $('.preview_photo_remove' + i).hide();
                    $('.preview_photo' + i + '_new').val(0);
                }
            }
            
            updateCurrentPhoto();
            //IEStopProgressBar();
        }
        
        imageUploaderWorking = false;
    }
    
    return ret_false();
}

//Update status of previous function in HTML
function updateImagePreview(status,image) {
	$('.upload_status').html('');
	if (status==1) {
		if ($("input[type='hidden'][name='current_photo']").length > 0) {
            var current_photo = $("input[type='hidden'][name='current_photo']").val();
            $('.preview_photo' + current_photo).attr('src', image);
            $('.preview_photo' + current_photo).show();
            $('.preview_photo' + current_photo + '_added').val(1);
            $('.preview_photo' + current_photo + '_edit_src').val(image);
            $('.preview_photo_remove' + current_photo).show();
            $('.preview_photo' + current_photo + '_new').val(1);
            updateCurrentPhoto();
        }
        else
            $('.preview_photo').html('<img src="'+image+'">');
        
		$('.upload_status').html('');
		
		//For fotogallery
		if ($("#commentplace").length>0) $("#commentplace").removeClass('na');
		if ($("#uploadplace").length>0) $("#uploadplace").addClass('na');
		
	}
	if (status==2) {
		$('.upload_status').html($.bone.lang.bad_photo);
	}
    
    imageUploaderWorking = false;
}

function updateCurrentPhoto()
{
    for (var i = 1; i <= $.bone.photo_upload.max_photos; i++)
    {
        if ($('.preview_photo' + i + '_added').val() != 1)
        {
            $("input[type='hidden'][name='current_photo']").val(i);
            $('.current_photo_label').html($.bone.lang.photo+' ' + i + ' '+$.bone.lang.from+' ' + $.bone.photo_upload.max_photos + ':');
            $(".file_photo_div").show();
            
            return;
        }
    }
    
    $("input[type='hidden'][name='current_photo']").val($.bone.photo_upload.max_photos);
    $('.current_photo_label').html($.bone.lang.photo+' ' + $.bone.photo_upload.max_photos + ' '+$.bone.lang.from+' ' + $.bone.photo_upload.max_photos + ':');
    $(".file_photo_div").hide();
}


function remove_comment(url)
{
	jConfirm('Ar tikrai norite pašalinti komentarą?', 'Patvirtinimas', function(confirmed) {
		if (confirmed)
		{
			document.location = url;
		}
	});
	
	return retFalse();
}

