function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

//Load images
var imagesToLoad = [
	{
		picSrc: "images/contentmenu/imageleft_1.jpg"
	},
	{
		picSrc: "images/contentmenu/imageleft_2.jpg"
	},
	{
		picSrc: "images/contentmenu/imageleft_3.jpg"
	},
	{
		picSrc: "images/contentmenu/viktborImage1.jpg"
	},
	{
		picSrc: "images/contentmenu/viktborImage2.jpg"
	},
	{
		picSrc: "images/contentmenu/viktborImage3.jpg"
	},
	{
		picSrc: "images/contentmenu/viktborImage4.jpg"
	}
];

var iter = 0;

jQuery.preloadImages = function()
{
	for( var i = 0 ; i < imagesToLoad.length ; i++)
	{
		jQuery("<img>").attr("src", imagesToLoad[i].picSrc);
	}
}

//$.preloadImages();
$(document).ready(function() {
		
	//Link image replacement
	//Masodik kepek elkeszitese
	$(".image-replace-link").each(function(){
		var oldLink=$(this).attr('src');
		var separate = oldLink.indexOf('.');
		var newLink=oldLink.substring(0,separate) +'b'+ oldLink.substring(separate);
		$(this).attr('myattrsellink',newLink);
		//Kep letoltese
		jQuery("<img>").attr("src", newLink);
	})
	
	//Aktualis menupont
	$('.selected-link').each(function(){
		$(this).attr('src',$(this).attr('myattrsellink'));
	})
	
	$(".image-replace-link").mouseover(function(){
		var newLink = $(this).attr('myattrsellink');
		var oldLink = $(this).attr('src');
		$(this).attr('src',newLink);
		$(this).attr('myattrsellink',oldLink);
	})

	$(".image-replace-link").mouseout(function(){
		var oldLink = $(this).attr('myattrsellink');
		var newLink = $(this).attr('src');
		$(this).attr('src',oldLink);
		$(this).attr('myattrsellink',newLink);
	})
	
	//Css image replace
	$(".cssimage-replace-link").each(function(){
		//Eredeti kep lekerdezese es eltuntetese
		var imageSrc = $(this).children('img').attr('src');
		//Kep letoltese
		jQuery("<img>").attr("src", imageSrc);
		
		var imageWidth = $(this).children('img').width();
		//$(this).children('img').remove();
		//Kep beallitasa hatternek
		$(this).css("background-image", "url("+imageSrc+")");
		$(this).css("width", imageWidth);
		var oldLink=imageSrc;
		var separate = oldLink.indexOf('.');
		var newLink=oldLink.substring(0,separate) +'b'+ oldLink.substring(separate);
		$(this).attr("myattrsellink",newLink);
		$(this).attr("myattroriglink",oldLink);
		//Kep letoltese
		jQuery("<img>").attr("src", newLink);
	})
	
	//Aktualis menupont
	$('.selected-csslink').each(function(){
		var newLink = $(this).attr('myattrsellink');
		$(this).attr('myattroriglink',newLink);
		$(this).css("background-image","url("+newLink+")");
	})
	
	$(".cssimage-replace-link").mouseover(function(){
		var newLink = $(this).attr('myattrsellink');
		$(this).css("background-image","url("+newLink+")");
	})

	$(".cssimage-replace-link").mouseout(function(){
		var oldLink = $(this).attr('myattroriglink');
		$(this).css("background-image","url("+oldLink+")");
	})
	
	//Text color link replacent
	$(".text-colorlink").each(function(){
		$(this).attr("myattrsellink","#E8DC86");
		$(this).attr("myattroriglink","white");
	})
	
	$('.selected-textlink').each(function(){
		var newLink = $(this).attr('myattrsellink');
		$(this).attr('myattroriglink',newLink);
		$(this).css("color",newLink);
	})
	
	$(".text-colorlink").mouseover(function(){
		var newLink = $(this).attr('myattrsellink');
		$(this).css("color",newLink);
	})

	$(".text-colorlink").mouseout(function(){
		var oldLink = $(this).attr('myattroriglink');
		$(this).css("color",oldLink);
	})
	
	//Etterem inner menu navigation
	$(".etterem-menu-cim").click(function(){
		//Identify required item
		var id = $(this).attr("id");
		var separate = id.indexOf('-');
		var sn = id.substring(separate);
		//Hide other items
		$(".etterem-menu-lista").each(function(){
			$(this).hide();
		});
		//Show selected item
		var showCont = 'etterem-menu'+sn;
		$('#'+showCont).show();
		
		//Color links
		$('.etterem-menu-cim').each(function(){
			$(this).css('color','white');
			$(this).css('font-weight','normal');
		});
		$(this).css('color','#E8DC86');
		$(this).css('font-weight','bold');
	})
	
	//Ajanlatkeres
	// $('#ajanlatkeres-link').click(function(){
		// $(this).attr('href','mailto(info@tengerdi.hu)');
		// return false
	// });
});


