/*
	Bonduelle - JavaScripts
	gka@emarketingexperts.pl / www.emarketingexperts.pl
	v1.0.1, 09.08.2007
*/

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

function fback() {
	if (!document.getElementById) return false;
	if (!document.getElementById("back")) return false;
	var a_back = document.getElementById("back");
	a_back.onclick = function() {
		history.back();
		return false;
	}	
}

function fprint() {
	if (!document.getElementById) return false;
	if (!document.getElementById("print")) return false;
	var a_print = document.getElementById("print");
	a_print.onclick = function() {
		window.print();
		return false;
	}
}

function inputLabelFromLabel(input_id,label_id) {
	if (!document.getElementById) return false;
	if (!document.getElementById(input_id)) return false;
	if (!document.getElementById(label_id)) return false;
	var textInput = document.getElementById(input_id);
	var label = document.getElementById(label_id);
	var text = label.innerHTML;
	if (textInput.value == '')
	{
		textInput.value = text;
		textInput.onfocus = function() {
			if (this.value == text) {
				this.value = '';
			}
		}
		textInput.onblur = function() {
			if (this.value == '') {
				this.value = text;
			}
		}
	}
}

function showRecipeText(j) {
	var recipesUl = document.getElementById("recipes_s");
	var recipeDivs = recipesUl.getElementsByTagName("div");
	for (var i=0;i<recipeDivs.length;i++) {
		recipeDivs[i].style.display = "none";
		if (recipeDivs[i].className == j) {
			recipeDivs[i].style.display = "block";
		}
	}
	
}

function showRecipe() {
	if (!document.getElementById) return false;
	if (!document.getElementById("recipes_s")) return false;	
	var recipesUl = document.getElementById("recipes_s");
	var recipeAs = recipesUl.getElementsByTagName("a");
	var recipeDivs = recipesUl.getElementsByTagName("div");
	var j = 0;
	for (var i=0;i<recipeAs.length;i++) {
		if (recipeAs[i].className == "s") {
			recipeAs[i].className = "s s"+j;
			recipeAs[i].onclick = function() {
				showRecipeText(this.className);
				return false;
			}
			j++;
		}
	}
	for (var i=0;i<recipeDivs.length;i++) {
		if (recipeDivs[i].className == "s") {
			recipeDivs[i].className = "s s"+i;
			if (i==0) recipeDivs[i].style.display = "block";
		}
	}
}

addLoadEvent(function(){
	inputLabelFromLabel("search","search_l");
	inputLabelFromLabel("newsletter","newsletter_l");
	inputLabelFromLabel("recipe_f","recipe_l");
});

addLoadEvent(fprint);
addLoadEvent(fback);
addLoadEvent(showRecipe);


function initFaq() {
	$("#faq p").css("display","none");	
	$("#faq h3 a").each( function(i) { 
		$(this).click( function() {
			$("#faq p").eq(i).animate( {
				height: 'toggle', opacity: 'toggle'
			}, "fast");
			$(this).toggleClass("s");
			return false;
		})
	})
	
	//$("#faq_formularz table").css("display","none");	
	$("#faq_formularz .formularzOpis").click( function() {
		$("#faq_formularz table").animate( {
			height: 'toggle', opacity: 'toggle'
		}, "fast");
		//$(this).toggleClass("s");
		return false;
	})
}

function fbBox(){
	$('#fb-box-button').toggle(function(){
		$('#fb-box').animate({
			right: 0
		});
	},
	function(){
		$('#fb-box').animate({
			right: -250
		});
	});
} 

function initialize() {
	initFaq();
	fbBox();
}

$(document).ready(initialize);

