(function($) {
		  
$(document).ready(function(){
		$.overstates();
		$("#resultBox").size()
			{
			$(".resultBox").width(document.width);
			setTimeout('$(".resultBox").slideUp()',3000);
			}
		$("a[rel^='lightbox']").fancybox();			
		$("#preloadBox").css("width",$("body").width());
		$("#plb").css("height",$(window).height());
		$.preloader();
});

$.pic = function(nr)
{
$('.produsPic').addClass("hidden");
$(".produsPic:eq("+nr+")").removeClass("hidden");
}

$.preloader = function()
{
	var imagesLoad = true;
	$("body img").each(function(){
		if ($(this).attr("complete")==false&&$(this).attr('src')!==undefined&&$(this).attr('src')!="")
		{
			imagesLoad = false;
		}
	});
	if (imagesLoad==false)
	{
		setTimeout("$.preloader()",100);
	}
	else
	{
		
		$("#preloadBox").remove();
		$("#hidden").remove();
		
	}
}

//ar ervenyessegenek leellenorzese
$.validPrice = function(e,str)
{
		var keynum = e.which; 
		var dotPos = str.indexOf('.');
		if ((keynum>=48 && keynum<=57) || (keynum>=96 && keynum<=105) || keynum==8 || ( (keynum==110 || keynum==190) && dotPos<0) || keynum==37 || keynum==39 || keynum==46 || keynum==116) return true;
		else return false;
}

$.datum = function()
{
var d = new Date();
return d.getMilliseconds();
}

$.adauga = function()
{
	$(".prodDetalii").append('<tr><td><input type="text" name="codprodus[]"/></td><td><input type="text" name="option[]"/></td><td><input type="text" name="pret[]" onkeydown="return $.validPrice(event,$(this).val());"/></td><td><img src="style/minus.gif" alt="sterge" title="sterge" style="cursor:pointer;" onclick="$(this).closest(\'tr\').remove();"/></td></tr>');
}

$.dis = function()
{
	if ($("#nume_f").attr("disabled") === true) $("#nume_f").removeAttr("disabled");
		else 
			{
			$("#nume_f").val("");	
			$("#nume_f").attr("disabled","true");
			}
}

$.overstates = function()
{
		/*left menu*/
		$(".menu_item_left").mouseover(function(){
			if ($(this).attr("id")!="activ")
				{
					$("#activ").css("background","url("+SITE_ROOT+"/images/menu_item_left.jpg) no-repeat");
					$(this).css("background","url("+SITE_ROOT+"images/menu_item_left_o.jpg) no-repeat");
				}	
		})
		
		$(".menu_item_left").mouseout(function(){
			if ($(this).attr("id")!="activ")
				{
					$("#activ").css("background","url("+SITE_ROOT+"images/menu_item_left_o.jpg) no-repeat");
					$(this).css("background","url("+SITE_ROOT+"images/menu_item_left.jpg) no-repeat");
				}	
		});		
		
		$(".menu_item_left").click(function(){
			$(".submenu").addClass("hidden");
			$(this).next().removeClass("hidden");
			$(".menu_item_left").removeAttr("id");
			if ($(this).hasClass('promotii')) $(this).attr("id","pactiv");
				else $(this).attr("id","activ");
		});			
		
		/*submenu*/
		$(".submenu_content ul li").mouseover(function(){
			if ($(this).attr("id")!="lactiv")
				{
					$("#lactiv").css("background","url("+SITE_ROOT+"images/li_bg.jpg) no-repeat 18px 6px #fff");
					$("#lactiv a").css("color","#194b64");
				}	
		})
		
		$(".submenu_content ul li").mouseout(function(){
			if ($(this).attr("id")!="lactiv")
				{
					$("#lactiv").css("background","url("+SITE_ROOT+"images/li_bg_o.jpg) no-repeat 18px 6px #f29535");
					$("#lactiv a").css("color","#fff");
				}	
		});	
		
		/*bottom menu*/
		$(".bottom_menu").mouseover(function(){
			if ($(this).attr("id")!="bactiv")
				{
					$("#bactiv").css("text-decoration","none");
				}	
		})
		
		$(".bottom_menu").mouseout(function(){
			if ($(this).attr("id")!="lactiv")
				{
					$("#bactiv").css("text-decoration","underline");
				}	
		});	
		
	/*menu*/
	$(".menu a").mouseover(function(){
	if ($(this).attr("id")!="mactiv_despre"){$("#mactiv_despre").css("background","url("+SITE_ROOT+"images/menu_despre_noi.jpg) no-repeat");}
	if ($(this).attr("id")!="mactiv_produse"){$("#mactiv_produse").css("background","url("+SITE_ROOT+"images/menu_produs.jpg) no-repeat");}	
	if ($(this).attr("id")!="mactiv_referinte"){$("#mactiv_referinte").css("background","url("+SITE_ROOT+"images/menu_refer.jpg) no-repeat");}
	if ($(this).attr("id")!="mactiv_contact"){$("#mactiv_contact").css("background","url("+SITE_ROOT+"images/menu_cont.jpg) no-repeat");}
	})
	
	$(".menu a").mouseout(function(){
		if ($(this).attr("id")!="mactiv_despre"){$("#mactiv_despre").css("background","url("+SITE_ROOT+"images/despre_noi_o.jpg) no-repeat");}
		if ($(this).attr("id")!="mactiv_produse"){$("#mactiv_produse").css("background","url("+SITE_ROOT+"images/produs_o.jpg) no-repeat");}
		if ($(this).attr("id")!="mactiv_referinte"){$("#mactiv_referinte").css("background","url("+SITE_ROOT+"images/refer_o.jpg) no-repeat");}
		if ($(this).attr("id")!="mactiv_contact"){$("#mactiv_contact").css("background","url("+SITE_ROOT+"images/cont_o.jpg) no-repeat");}		
	});		
		
}

$.initializeMap = function()
{
	
		var latlng = new google.maps.LatLng(47.057555,21.940159);
		var myOptions = {
		  zoom: 15,
		  center: latlng,
		  mapTypeId: google.maps.MapTypeId.ROADMAP,
		  mapTypeControl: false
		};	
		var map = new google.maps.Map(document.getElementById("google_map"), myOptions);
		
		/*var companyLogo = new google.maps.MarkerImage('contact/images/map-marker.png',
			new google.maps.Size(90,60),
			new google.maps.Point(0,0),
			new google.maps.Point(30,60)
		);
		var companyShadow = new google.maps.MarkerImage('contact/images/map-shadow.png',
			new google.maps.Size(106,37),
			new google.maps.Point(0,0),
			new google.maps.Point(27,35)
		);*/
		
		var companyMarker = new google.maps.Marker({
		  position: latlng,
		  map: map,
		  title:"S.C. SZTUFI SERV S.R.L"
		  /*icon: companyLogo,
		  shadow: companyShadow*/
		});
	
}


$.valt = function(button,id)
{
	$(".produse_detalii_table_content").addClass("hidden");
	$("#"+id).removeClass("hidden");
	$(".produse_detalii_table_button").removeClass("pactiv");
	$(button).addClass("pactiv");
}

$.ajaxLoad = function(divId,url,param)
{
	var TI = new Date();
	if (!$("#"+divId).length)
	{
		$("body").append('<div id="'+divId+'"></div>');
	}
	$.ajax({
		type: "POST",
		url: url,
		data: param,
		contentType: "application/x-www-form-urlencoded;charset=ISO-UTF-8",
		success: function(msg){
			$('#'+divId).html(msg+'<span style="display: none;">'+TI.getTime()+'</span>');
		}
	});
}


 $.makeWindowed = function(p_div)
 {
	var is_ie6 =
	   document.all && 
	   (navigator.userAgent.toLowerCase().indexOf("msie 6.") != -1);
	if (is_ie6)
	{
	   var html =
		  "<iframe style=\"position: absolute; display: block; " +
		  "z-index: -1; width: 100%; height: 100%; top: 0; left: 0;" +
		  "filter: mask(); background-color: #ffffff; \"></iframe>";
	  $(p_div).html(html);
	   // force refresh of div
	   var olddisplay = $(p_div).css("display");
	   $(p_div).css("display",'none');
	   $(p_div).css("display",olddisplay);
	};
 }

$.shadow = function(divId,divId2){
	if ($("#shadow"+divId).size())
	{
		$("#shadow"+divId).remove();
	}
	$("body").append("<div id='shadow"+divId+"'></div>");
	$("#shadow"+divId).css("background-color","#000000");
	$("#shadow"+divId).css("opacity",0);
	$("#shadow"+divId).css("position","absolute");
	$("#shadow"+divId).css("width",$("body").width());
	$("#shadow"+divId).css("height",$(document).height());
	$("#shadow"+divId).css("top",0);
	$("#shadow"+divId).css("left",0);
	$("#shadow"+divId).css("z-index",2);
	$("#shadow"+divId).click(function(){
		$.closePopup(divId);	
		if (divId2!='undefined')
		{
			$.closePopup(divId2);
		}
	});
	$("#shadow"+divId).fadeTo(200,0.5);
	$.makeWindowed("#shadow"+divId);
};


$.closePopup = function(divId)
{
	$("#"+divId).fadeOut(200,function(){
		$("#"+divId).remove();
		$("#shadow"+divId).animate({
			opacity: 0
		},200,function(){
			$("#shadow"+divId).remove();
		});
	});
	
}


$.ajaxLoadPopup = function(divId,url,param)
{
	var TI = new Date();
	if ($("#"+divId).length)
	{
		$("#"+divId).remove();
	}
	$.shadow(divId);
	$("body").append('<div id="'+divId+'"></div>');
	$("#"+divId).css("top",0);
	$("#"+divId).css("left",0);
	$("#"+divId).css("margin",0);
	$("#"+divId).css("padding",0);
	$("#"+divId).css("position","absolute");
	$("#"+divId).css("z-index",3);
	$.ajax({
		type: "POST",
		url: url,
		data: param,
		success: function(msg){
			$("#"+divId).fadeTo(0,0);
			$("#"+divId).html(msg+'<span style="display: none;">'+TI.getTime()+'</span>');
			$("#"+divId).css("top",($(window).height()-$("#"+divId).height())/2+$(window).scrollTop());
			$("#"+divId).css("left",($("body").width()-$("#"+divId).width())/2);
			$("#"+divId).fadeTo(300,1);
			$("#closePopup").click(function(){
				$.closePopup(divId);
				return false;
			});
		}
	});
}
$.centerDiv = function(divId)
{
	$("#"+divId).css("position","absolute");
	$("#"+divId).css("top",0);
	$("#"+divId).css("left",0);
	$("#"+divId).css("margin",0);
	$("#"+divId).css("padding",0);
	$("#"+divId).css("z-index",3);
	$("#"+divId).css("top",($(window).height()-$("#"+divId).height())/2+$(window).scrollTop());
	$("#"+divId).css("left",($("body").width()-$("#"+divId).width())/2);
	$("#"+divId).removeClass("hidden");
}

})(jQuery)
