
var current=0;

$(window).load(function () {
		setsize();
		setsize();
});

$(window).resize(function() { 
	setsize();
	
	var lenght =1060;
	var howmany=$(".pieceSlide").size();
	if (howmany!=0) {
		$("#wrapper").width(lenght*howmany);
		var inside = $("#inside").width();
		var wrapper = $("#wrapper").width();
		
		$("#wrapper").animate({
			marginLeft: ((inside/2)-(lenght/2)-(current*lenght))+"px"
		}, 0);
	}
});

function setsize() {
	var window_height = $(".pieces").height();
	var window_width  = $(".pieces").width();
	var image_width   = $("#bg_img").width();
	var image_height  = $("#bg_img").height();
	if (window_width > image_width)
	{
		document.getElementById("bg_img").style.width  = "100%";
		document.getElementById("bg_img").style.height = "auto";
		
	}
	if (window_height > image_height)
	{
		document.getElementById("bg_img").style.width  = "auto";
		document.getElementById("bg_img").style.height = "100%";		
	}
	var window_height = $(".pieces").height();
	var window_width  = $(".pieces").width();
	var image_width   = $("#bg_img").width();
	var image_height  = $("#bg_img").height();
	$("#bg_img").animate({
		marginTop: "-"+((image_height-window_height)/2)+"px"
	}, 0);
	$("#bg_img").animate({
		marginLeft: "-"+((image_width-window_width)/2)+"px"
	}, 0);
}

//---------------------------slide---------------------------//   
function slide(firstTime, startIndex) {

	$(document).ready(function(){
		
		current = 0;
		var lenght =1060;
		var howmany=$(".pieceSlide").size();
		current=0;
		if (startIndex=="begin") {
			current=0;
		}
		else if (startIndex=="end") {
			current=howmany;
		}
		else if (startIndex=="middle") {
			current = parseInt(howmany/2);
		}
		else  {
			current = startIndex-1;
		}
		var inside = $("#inside").width();
		$("#wrapper").width((lenght*howmany));
		var wrapper = $("#wrapper").width();
		
		//initialize
		$("#wrapper").animate({
			marginLeft: ((inside/2)-(lenght/2)-(current*lenght))+"px"
		}, 0);
		
		
		if(firstTime==0){
			$("#inside").animate({
				marginBottom: "-="+($("#wrapper").height())+"px"
			}, 0);
		}
		
		$("a#next").click(function(){
			if(current+1 <= howmany-1){
				current = current + 1;
				$("#wrapper").animate({
					marginLeft: "-="+lenght+"px"
				}, 1000);
				
			} else {
				$("#wrapper").animate({	
					marginLeft: "+="+(lenght*current)+"px"
				}, 1000);
				current = 0;
			}
		});

		$("a#prev").click(function(){
		
			//if(current > -1){
			if(current-1 >= 0){
				current = current - 1;
				$("#wrapper").animate({
					marginLeft: "+="+lenght+"px"
				}, 1000);
				
			} else {
				$("#wrapper").animate({	
					marginLeft: "-="+(lenght*(howmany-1))+"px"
				}, 1000);
				current = howmany-1;
			}
		});
		
		$("#menu").mouseenter(function(){ 

			if(firstTime==0){
				firstTime=1;
				$("#inside").animate({
					marginBottom: "+="+($("#wrapper").height())+"px"
				}, 1000);
				
			} 
		});
	});
}

//---------------------------normal---------------------------//
function description(firstTime) 
{
	jQuery(document).ready(function(){
		$(document).mousemove(function(e){
			$('#description').css("top", ((-20+e.pageY-($("#bg").height()-$("#inside").height())))).css("left", e.pageX+20);
		}); 
	});
	
	jQuery(document).ready(function(){
		
		if(firstTime==0){
			$("#inside").animate({
				marginBottom: "-="+($("#wrapper").height())+"px"
			}, 0);
		}
		
		$("#menu").mouseenter(function(){ 

			if(firstTime==0){
				firstTime=1;
				$("#inside").animate({
					marginBottom: "+="+($("#wrapper").height())+"px"
				}, 1000);
				
			} 
		});
	});
}
function show_div(id, text1, text2) 
{ 
	document.getElementById("description").style.visibility='visible';
	document.getElementById("zgoraj").innerHTML ='<div id="naslov_okvir">'+text1+'</div>';
	document.getElementById("sredina").innerHTML ='<div id="vsebina_okvir">'+text2+'</div>';
	//document.getElementById("flasa"+id).src ="img/buteljka_velika.png";
	
	var text="#flasa"+(id);
	var width_slika  = $(text).width();
	var height_slika  = $(text).height();
	document.getElementById("flasa"+id).style.width=(width_slika*1.12)+"px";
	document.getElementById("flasa"+id).style.height=(height_slika*1.12)+"px";
	
	document.getElementById("flasa"+id).style.marginTop ="-20px";

} 

function hide_div(id) 
{ 
	document.getElementById("description").style.visibility='hidden';
	//document.getElementById("flasa"+id).src ="img/buteljka.png";
	
	var text="#flasa"+(id);
	var width_slika  = $(text).width();
	var height_slika  = $(text).height();
	document.getElementById("flasa"+id).style.width="auto";
	document.getElementById("flasa"+id).style.height="320px";
	
	document.getElementById("flasa"+id).style.marginTop ="0px";
} 

function change_backgroung(id, text) 
{ 
	document.getElementById("bg_img").src =text;
	
	/*kulinarika=document.getElementsByName("kulinarikaPicture");
	naslov=document.getElementsByName("naslov");
	vsebina=document.getElementsByName("vsebina");
	
	for (i=0; i<kulinarika.length; i++) {
		if (id-1==i) {
			kulinarika[i].style.visibility='hidden';
			kulinarika[i].style.width ="0px";
			kulinarika[i].style.marginLeft ="-10px";
			naslov[i].style.width ="930px";
			vsebina[i].style.width ="930px";
		}
		else {
			kulinarika[i].style.visibility='visible';
			kulinarika[i].style.width ="280px";
			kulinarika[i].style.marginLeft ="0px";
			naslov[i].style.width ="620px";
			vsebina[i].style.width ="620px";
		}
	}*/
	setsize();
} 

function kulinarika_slika()
{ 
$(window).load(function(){ 
	var width = $("#slika").width();
	var height = $("#slika").height();
	
	kulinarika=document.getElementsByName("kulinarikaPicture");
	
	for (i=0; i<kulinarika.length; i++) {
		var text="#kulinarikaPicture"+(i+1);
		var width_slika  = $(text).width();
		
		if(width>width_slika) {
			kulinarika[i].style.width="100%"
			kulinarika[i].style.height="auto";
			var height_slika  = $(text).height();
			kulinarika[i].style.marginTop =((height/2)-(height_slika/2)).toString()+"px";
			kulinarika[i].style.marginLeft ="0px";
		}
		else {
				kulinarika[i].style.marginTop ="0px";
			kulinarika[i].style.marginLeft =((width/2)-(width_slika/2)).toString()+"px";
		}
	}
});
} 


//---------------------------galery---------------------------//
function gallery(startIndex) {
	$(document).ready(function(){
	
		current = 0;
		//var lenght = $(window).height();
		//var height  = $(window).width();
		var lenght =$("#insideGallery").width(); 
		var height =$("#insideGallery").height();
		var howmany=$(".pieceGallery").size();
		current=0;
		if (startIndex=="begin") {
			current=0;
		}
		else if (startIndex=="end") {
			current=howmany;
		}
		else if (startIndex=="middle") {
			current = parseInt(howmany/2);
		}
		$("#wrapperGallery").width(lenght*howmany);
		var inside = $("#insideGallery").width();
		var wrapper = $("#wrapperGallery").width();
		
		//initialize
		$("#wrapperGallery").animate({
			marginLeft: "+="+((inside/2)-(lenght/2)-(current*lenght))+"px"
		}, 0);
		$(".pieceGallery").width(lenght);
		
		$("#menu").animate({
			bottom: "0px"
		}, 0);
		
		$("a#nextGallery").click(function(){
			if(current+1 <= howmany-1){
				current = current + 1;
				$("#wrapperGallery").animate({
					marginLeft: "-="+lenght+"px"
				}, 1000);
				
			} else {
				$("#wrapperGallery").animate({	
					marginLeft: "+="+(lenght*current)+"px"
				}, 1000);
				current = 0;
			}
		});

		$("a#prevGallery").click(function(){
		
			//if(current > -1){
			if(current-1 >= 0){
				current = current - 1;
				$("#wrapperGallery").animate({
					marginLeft: "+="+lenght+"px"
				}, 1000);
				
			} else {
				$("#wrapperGallery").animate({	
					marginLeft: "-="+(lenght*(howmany-1))+"px"
				}, 1000);
				current = howmany-1;
			}
		});
	
		function showResponse(responseText, statusText)  { 
			// for normal html responses, the first argument to the success callback 
			// is the XMLHttpRequest object's responseText property 
		 
			// if the ajaxForm method was passed an Options Object with the dataType 
			// property set to 'xml' then the first argument to the success callback 
			// is the XMLHttpRequest object's responseXML property 
		 
			// if the ajaxForm method was passed an Options Object with the dataType 
			// property set to 'json' then the first argument to the success callback 
			// is the json data object returned by the server 
		 
		   // alert('status: ' + statusText + '\n\nresponseText: \n' + responseText + 
			 //   '\n\nThe output div should have already been updated with the responseText.'); 
		} 
		        
		$('textarea').focus(function(){
			var content = $(this).text();
			if(content == "Leave a message after the beep! Just make sure to include your name and email if you want a reply."){
				$("textarea").text("");
			}
		
		});
		
		$('textarea').blur(function(){
			if(empty($("textarea").text())){
				$("textarea").text(content);
			}
		
		});
	});
}

