
function showObj(objname){
	document.getElementById(objname).style.display="block";
	return;
}

function hideObj(objname){
	document.getElementById(objname).style.display="none";
	return;
}


function showPic(picture,link){
		document.getElementById("picture").src=picture;
		document.getElementById("link").href=link;
	}

function showPicOnPlace(picture,link,place){
		showObj(place);
		document.getElementById(place).src=picture;
		document.getElementById(place).href=link;
	}


var ifCN = 'focused';
function focusableInput() {
	for(var i=0, j=arguments.length; i<j; i++) {
		var obj = document.getElementById(arguments[i]);
		obj.onfocus = inputFocus;
		obj.onblur = inputBlur;
	}
}
function inputFocus() {
	if (this.value == this.defaultValue) this.value = '';
	if (this.className.length > 0) this.className += ' ' + ifCN;
	else this.className = ifCN;
}
function inputBlur() {
	if (this.value == '') this.value = this.defaultValue;
	var reCN = this.className.match(new RegExp(' ?' + ifCN + ' ?'));
	if (reCN) this.className = this.className.replace(reCN, '');
}


function registerFocus(objId) {
	var theLinks = document.getElementById(objId).getElementsByTagName('a');
	for (var i=0; i<theLinks.length; i++) {
		theLinks[i].onclick = function() {
			var linkHref;
			if (linkHref = this.getAttribute('href').match(uriRE)) {
				document.getElementById(linkHref[1]).scrollIntoView();
				document.getElementById(linkHref[1]).focus();
				return false;
			}
		}
	}
}

function showPromo(promo){
clearTimeout(wait);

if(!promo){
	var i = 1+ Math.round((totalpromos-1) * Math.random());
	promo=i;
	promoname="promo"+i;
	promonavname="promonav"+promo;
} else {
	promoname="promo"+promo;
	promonavname="promonav"+promo;
}
currentpromoname='promo'+currentpromo;
document.getElementById(currentpromoname).style.left=-500+'px';
if(totalpromos > 1){
	currentpromonavname='promonav'+currentpromo;
	document.getElementById(currentpromonavname).className="";
}
document.getElementById(promoname).style.left=0+'px';
if(totalpromos > 1) { document.getElementById(promonavname).className='selected'; }

currentpromo=promo;
wait=setTimeout("nextPromo()",5000);
}

currentpromoname="promo1";
currentpromonavname="promonav1";
currentpromo=1;
totalpromos=1;
wait=0;


function nextPromo(){
if(currentpromo < totalpromos) {
		showPromo(currentpromo+1);
} else {
		showPromo(1);
}
}

slideshow=0;
wait2=0;
nexturl="";

function toggleSlideshow(){
	if(slideshow == 1){
//			alert("stop show");
			clearTimeout(wait);
			document.getElementById("slideInfo").style.display="none";
			slideshow=0;
	} else {
//			alert("start show");
			slideshow=1;
			wait=setTimeout("nextSlideshow()",5000);
			document.getElementById("slideInfo").style.display="block";
	}
}


function nextSlideshow(){
clearTimeout(wait);
clearTimeout(wait2);
nexturl=nexturl.replace(/&amp;/g,"&");
//alert("nextPic:"+nexturl);
location.href=nexturl;
}


var savedClass='';

function doRollOver(objectname){
	savedClass=document.getElementById(objectname).className;
	document.getElementById(objectname).className= document.getElementById(objectname).className + ' rollOver';
	return;
}
function doRollOut(objectname){
	document.getElementById(objectname).className=savedClass;
	return;
}




var items=1;

function AddItem() {

  var div=document.getElementById("ingrediente");

  var button=document.getElementById("add");

  if (items<=25)
  {

	  items++;

	  var newitem="<label for=\"\">Ingredient " + items + ": </label>";

	  newitem+="<input type=\"text\" name=\"ingredient" + items;

	  newitem+="\" id=\"ingredient" + items;
	  newitem+="\" class=\"ingrediente\" /> <label for=\"\">Cantitate</label> <input type=\"text\" name=\"cantitate" + items;

	  newitem+="\" id=\"cantitate" + items;
	  newitem+="\" class=\"cantitate\" /><br />";

	  var newnode=document.createElement("p");

	  newnode.innerHTML=newitem;

	  div.insertBefore(newnode,button);

  }

  else {
	
	button.disabled= true;
  }

}


function ingrediente() {
	var ingrediente= document.getElementById('retete_ingrediente');
	var ingredienteFolosite= document.getElementById('retete_ingredientefolosite');
	
	var ing = new Array(items);
	for (var i=1;i<=items;i++)
	{
		 var current_ingredient= document.getElementById('ingredient'+i);
		 var current_cantitate= document.getElementById('cantitate'+i);
		 if (current_ingredient && current_cantitate)
		 {
			 ing[i-1] = current_ingredient.value + '#' + current_cantitate.value;
			 ingredienteFolosite.value += current_ingredient.value + ',';
		 }
	}
	ingrediente.value = ing.join('|');
}


function AddEditItem(theStr) {
	var div=document.getElementById("ingrediente");
	var button=document.getElementById("add");
	var infoArr = theStr.split('#');
	if (items <= 25) {
		items++;
		var newitem="<label for=\"\">Ingredient " + items + ": </label>";
		newitem+="<input type=\"text\" name=\"ingredient" + items;
		newitem+="\" id=\"ingredient" + items;
		newitem+="\" value=\""+infoArr[0]+"\" class=\"ingrediente\"  /> <label for=\"\">Cantitate</label> <input type=\"text\" name=\"cantitate" + items;
		newitem+="\" id=\"cantitate" + items;
		newitem+="\" value=\""+infoArr[1]+"\" class=\"cantitate\" /><br />";
		var newnode=document.createElement("p");
		newnode.innerHTML=newitem;
		div.insertBefore(newnode,button);
	}
	else {
		button.disabled= true;
	}
}

function InitEdit() {
	var  ingArr = document.getElementById('retete_ingrediente').value.split('|');
	for(var i = 0; i < ingArr.length; i++) {
		if(i == 0) {
			var tmp = ingArr[i].split('#');
			document.getElementById('ingredient1').value = tmp[0];
			document.getElementById('cantitate1').value = tmp[1];
		}
		else {
			AddEditItem(ingArr[i]);
		}
	}
}

/*
function showTabs(nr){

	for (var i=1;i<=3;i++)
	{
		document.getElementById('step'+i).style.display='none';
		if (i == nr)
		{
			document.getElementById('step'+nr).style.display='block';
		}
	}

}
*/



window.onload = function (){
	var G = document.getElementById('galleryNav');
	if (G)
	{
		x = document.getElementById('imgFile').offsetHeight;
		document.getElementById('galleryNav').style.height = x - 35 + 'px';
	}
};

jQuery.exists = function(selector) {return (jQuery(selector).length > 0);}
$(document).ready(function(){

	
	
standardSocialWidgets();	

/*
jQuery('div.social > span.controller').bind('click',function(){
	if(jQuery(this).parent().hasClass('expanded') ==true){
		jQuery('#SocialWidgetsPlace').slideUp("slow",function(){
			jQuery('#SocialWidgetsPlace').parent().removeClass('expanded');
		});
	}
	else{
		jQuery('#SocialWidgetsPlace').slideDown("slow",function(){
			jQuery('#SocialWidgetsPlace').parent().addClass('expanded');
		});
	}
})
*/


var emailCTRL = $('#widgets div#Email span.controller');
var emailRES = $('<div class="res"></div>').appendTo(emailCTRL.parent());
var emailRES_isLoaded = false;
emailCTRL.live('click',function(){
	if(emailRES_isLoaded==false){
		emailRES.load(
			rp_a,
			function(responseText, textStatus, xhr){
				emailCTRL.live('click',function(){
					emailRES.dialog({
						modal:true,
						title:'Recomanda unei prietene',
						width:700
					})
				});
				
				
				
				if($.exists('form#recommendForm') == true){
					recForm = $('form#recommendForm');
					recForm.submit(function(){return false;})
					$('form#recommendForm input:submit').click(function(){
						$.post(
							rp_a+recForm.attr('action'),
							recForm.serialize(),
							function(data){
								recForm.parent().html(data);
							}
						);						
						return false;
					})
				}	
			})
			.dialog({
				modal:true,
				title:'Recomanda unei prietene',
				width:700
			});
		emailRES_isLoaded = true;
	}
	else {
		emailRES.dialog('open');

	}
	return false;	
});

})



function standardSocialWidgets() {
//var Place = document.getElementById("SocialWidgetsPlace");
//if(!Place) return;
var title = document.title;
var titleE = encodeURIComponent(title);
var url = location.href;
var urlE = encodeURIComponent(url);
     
/* Social widgets : you can re order it or remove some, but watch for comma */
/* HTML : is html to be appended to div, Vars are widget JS variables, Js : widget remote JS to load */
var widgets = [
	{
		'name':'Buzz'
		,'js':'http://www.google.com/buzz/api/button.js'
		,'xhtml':'<a href="http://www.google.com/buzz/post" class="google-buzz-button" title="Google Buzz" data-message="'+title+'" data-url="'+url+'" data-locale="ro" data-button-style="normal-count"></a>'
	}

	
];

container = $('#widgetContainer');

jQuery.each(widgets,function(idx,item){
	
var instance = $('<div></div>').addClass('widget').attr('id',$(item).attr('name'));
//if(idx==0){instance.addClass('first')}	
//if(idx==widgets.length-1){instance.addClass('last')}
if(item.clss){instance.addClass(item.clss)}
if(item.xhtml){instance.html(item.xhtml)}
instance.appendTo(container).insertAfter('#Facebook');
//if(item.script){instance.after(jQuery('<script></script>').attr('type','text/javascript').attr('src',item.script))}

if(item.vars){
	for(k in item.vars){window[k]=item.vars[k];}
}

if(item.js){$('<script>').attr('type','text/javascript').attr('src',item.js).appendTo('head');}

$('#Comment').insertAfter('#Email');
$('#Print').insertAfter('#Email');
if($('ul#functions li').length == 0){$('ul#functions').hide()}

})




/*
	for(var i=0; i<widgets.length; i++) {
		var clss = 'SocialWidget';
		if(i==0) clss = 'FirstSocialWidget';
		else if(i==widgets.length-1) clss = 'LastSocialWidget';
		
		// Append HTML
		Place.innerHTML=Place.innerHTML +
		'<div class="'+widgets[i].name+'Widget '+clss+'">'+ widgets[i].html +'</div>';
		
		// Set optional Vars
		if(widgets[i].vars) for(k in widgets[i].vars) window[k]=widgets[i].vars[k];
		
		// load optional Js file and attach to head
		if(widgets[i].js) {
			var head = document.getElementsByTagName("head")[0];
			var js = document.createElement("script");
			js.src = widgets[i].js;
			head.appendChild(js);
			}
		}
		
*/
		
}