window.siteurl='http://www.pensiunea-nagy.ro/';
var BASEHREF='http://www.pensiunea-nagy.ro/ro/';
$(document).ready(function(){
	$('#nav>ul>li').hover(
		function(){$(this).addClass('a')},
		function(){$(this).removeClass('a')}
	);
	/*jplayer*/
	var jpPlayTime = $("#jplayer_play_time");
	var jpTotalTime = $("#jplayer_total_time");
	$("#jquery_jplayer").jPlayer({
		swfPath:"http://www.pensiunea-nagy.ro/ro/includes/jquery/js/",
		ready:function () {
			this.element.jPlayer("setFile", "http://www.pensiunea-nagy.ro/spot/spot-nagy.mp3").jPlayer();
		},
		volume: 50,
		oggSupport: false,
		preload: 'none'
	})
	.jPlayer("onProgressChange", function(loadPercent, playedPercentRelative, playedPercentAbsolute, playedTime, totalTime) {
		jpPlayTime.text($.jPlayer.convertTime(playedTime));
		jpTotalTime.text($.jPlayer.convertTime(totalTime));
	})
	.jPlayer("onSoundComplete", function() {
		this.element.jPlayer("play");
	});
	/*endjplayer*/
	$('#add-alert button').live('click',function(){
		if ($('#keywords').val()=='') {
			error('You cannot add empy alerts!');
		} else {
			$.ajax({
				type: 'GET',
				url: 'http://www.pensiunea-nagy.ro/ro/upload.php',
				data:'alert=2&value='+$('#keywords').val()+'&category='+$('#category').val(),
				success: function(responseText){
					if (responseText=='success') {
						$('#tab-activity .navigation .a').removeAttr('class');
						$('#tab-activity .navigation a[rel="alerts"]').addClass('a');
						$('#tab-activity .content').animate({opacity:0.111,height:['toggle','swing']},500,'linear',function(){
							$('#tab-activity .content').load('http://www.pensiunea-nagy.ro/ro/content/account/alerts.php').animate({opacity:1,height:['toggle','swing']},500,'linear');
						});
					} else {
						error(responseText);
					}
				}
			});
		}
		return false;
	});
	var o = $("#printeaza");
	$('#print').click(function (){
		o.jqprint();
	});
	$('#preview-ad').live('submit',function(){
		var timestamp=new Date().getTime();
		window.open('','preview'+timestamp,'width=1024,height=768,resizeable,scrollbars').moveTo(0,0);
		this.target='preview'+timestamp;
	});
	$('#feature-ad input[type="checkbox"]').live('click',function(){
		var e=$(this);
		$('input[type="checkbox"][name="'+e.attr('name')+'"]').removeAttr('checked');
		e.attr('checked','checked');
		$('input[name="'+e.attr('title')+'"]').val(e.val());
	});
	$('#preview').live('click',function(){
		$('#preview-ad').html('');
		$('#action input,#action select').each(function(){
			var e=$(this);
			$('#preview-ad').prepend("<input type=\"hidden\" name=\""+e.attr('name')+"\" value=\""+e.val()+"\"");
		});
		$('#preview-ad').submit();
		return false;
	});
	$('#search-box button').live('click',function(){
		$('#search-form').submit();
	});
	$('#search-box input,#search-box select').live('change',function(){
		$('#'+$(this).attr('title')).val($(this).val());
	});
	var $search='';
	$('button[title="search-box"]').live('click',function(){
		if ($search=='') {
			$search=$(this).attr('title');
			$(this).removeAttr('title');
		}
		alerta($('.'+$search).html());
	});
	$('#account dd a').live('click',function(){
		var e=$(this);
		if (!$.validationEngine.loadValidation('#'+e.attr('rel'))) {
			$.ajax({
				type: 'GET',
				url: 'http://www.pensiunea-nagy.ro/ro/upload.php',
				data:'account=1&field='+e.attr('rel')+'&value='+$('#'+e.attr('rel')).val(),
				success: function(responseText){
					alerta((responseText=='success'?'Campul a fost actualizat.':'Eroare!'));
				}
			});
		} else {
			return false;
		}
	});
	$('#account dd input').live('focusout',function(){
		$.validationEngine.loadValidation('#'+$(this).attr('id'));
	});
	$('.select-all').live('click',function(){
		var e=$(this);
		if (e.attr('checked')) {
			$('input[name="'+e.attr('title')+'"]').attr('checked','checked');
		} else {
			$('input[name="'+e.attr('title')+'"]').removeAttr('checked');
		}
	});
	$('button.action').live('click',function(){
		var e=$(this);
		var ids=$('input[name="'+e.attr('title')+'"]:checked').map(function() { return $(this).val(); }).get();
		if (ids.length>0) {
			$.ajax({
				type: 'GET',
				url: 'http://www.pensiunea-nagy.ro/ro/upload.php',
				data:e.attr('title')+'=1&ids='+ids,
				success: function(responseText){
					for (var i=0;i<ids.length;i++) {
						$('#'+e.attr('title')+'-'+ids[i]).animate({"height": "toggle", "opacity": "toggle"}, "slow", "linear", function(){$('#'+e.attr('title')+'-'+ids[i]).remove()});
					}
					if ($('#'+e.attr('title')+' .list ul').length-ids.length==0) {
						$('#'+e.attr('title')+'>*:not(h4)').animate({"height": "toggle", "opacity": "toggle"}, "slow", "linear", function(){
							$('#'+e.attr('title')+'>*:not(h4)').remove();
							if ($('#'+e.attr('title')+' p').length==0) {
								$('#'+e.attr('title')).append('<p>No items.</p>');
							}
						});
					}
				}
			});
		}
	});
	$('#product a[title="Wishlist"]').live('click',function(){
		var o=$(this);
		$.ajax({
			type: 'GET',
			url: 'http://www.pensiunea-nagy.ro/ro/upload.php',
			data:'wishlist=2&id_ad='+o.attr('id').split('wishlist-')[1]+'&action='+(o.html()=='Wishlist'?'add':'remove'),
			success: function(responseText){
				alerta(responseText);
				o.html((o.html()=='Wishlist'?'Remove from wishlist':'Wishlist'));
			}
		});
	});
	$('#per-page a').live('click',function(){
		$('#pages').val($(this).html());
		$('#per-page').submit();
	});
	$('#video-loader').live('click',function(){
		if ($('#video').val()!='') {
			if (!$.validationEngine.loadValidation("#video")) {
				$('#embed').load("http://www.pensiunea-nagy.ro/ro/upload.php?link="+escape($('#video').val())+"");
			} else {
				$.validationEngine.loadValidation("#video");
			}
		} else {
			$.validationEngine.buildPrompt("#video","You cannot preview an empty link","error");
		}
		return false;
	});
	$("#menu a").live('click',function(){
		var locationHref=window.location.href;
		var href=$(this).attr('href');
		if (href.match('(#)')) {
			var elementClick=$(this).attr("href");
			var destination=$(elementClick).offset().top;
			$("html:not(:animated),body:not(:animated)").animate({scrollTop:destination},1100,function() { window.location.hash=elementClick; });
			return false;
		}
	});
	$('#tabs .navigation a').live('click',function(){
		var e=$(this);
		var page=e.attr('rel');
		if (page.length>0) {
			var id=$(e).parent().parent().parent().parent().parent().attr('id');
			$('#'+id+' .navigation a').removeAttr('class');
			e.addClass('a');
			$('#'+id+' .content').animate({opacity:0.111,height:['toggle','swing']},500,'linear',function(){
				$('#'+id+' .content').load('http://www.pensiunea-nagy.ro/ro/content/account/'+page+'.php',function(){
					$('#wishlist .category p,#wishlist .price span,#free-ads .category p').each(function(){
						var el=$(this);
						el.css('top',(el.parent().height()/2-el.height()/2));
					});
				}).animate({opacity:1,height:['toggle','swing']},500,'linear');
			});
			return false;
		}
	});
	$('#tabs .navigation .a').each(function(){
		var e=$(this);
		var page=e.attr('rel');
		if (page.length>0) {
			var id=$(e).parent().parent().parent().parent().parent().attr('id');
			$('#'+id+' .content').load('http://www.pensiunea-nagy.ro/ro/content/account/'+page+'.php',function(){
				$('#wishlist .category p,#wishlist .price span,#free-ads .category p').each(function(){
					var el=$(this);
					el.css('top',(el.parent().height()/2-el.height()/2));
				});
			});
		}
	});
	$('#tabs ul a, #tabs .tabsBody a').click(function(){
		var e=$(this);
		if (e.attr('href')) {
			var id=e.attr('href').split('#')[1];
			$('#tabs>ul>li:not(.c)').each(function(){
				$(this).removeAttr('class');
			});
			e.parent().addClass('active');
			$('#tabs>div').each(function(){
				var el=$(this);
				el.removeClass('active');
				if (el.attr('id')==id) { el.addClass('active'); }
			});
			return false;
		}
	});
	$('#choose-category a').click(function(){
		toggleCatLink($(this));
		return false;
	});
	//	alert('a');
	$(".datepicker").datepicker({
		dateFormat :'mm-dd-yy',
		changeYear:true,
		yearRange:'2012:2017',
		dayNames: ['Duminica','Luni','Marti','Miercuri','Joi','Vineri','Sambata'],
		dayNamesMin: ['Du','Lu','Ma','Mi','Jo','Vi','Sa'],
		monthNames: ['Ianuarie','Februarie','Martie','Aprilie','Mai','Iunie','Iulie','August','Septembrie','Octombrie','Noiembrie','Decembrie'],
		monthNamesShort: ['Ian','Feb','Mar','Apr','Mai','Iun','Iul','Aug','Sep','Oct','Noi','Dec'],
		firstDay:1,
		minDate:new Date(2012,1,7),
		defaultDate:new Date(2012,1,7),
		nextText:'urmatoarea luna',
		prevText:'precedenta luna'
	});
	if ($.fancybox) {
		$("a.group").fancybox({
			'opacity':true,
			'cyclic':true,
			'centerOnScroll':true,
			'overlayColor':'#333',
			'overlayOpacity':0.6,
			'titlePosition':'over',
			'speedIn':600,
			'speedOut':200,
			'transitionIn':'elastic',
			'easingIn':'swing',
			'transitionOut':'elastic',
			'easingOut':'swing'
		});
	}
	if ($.validationEngine) {
		$("form:not('#account')").validationEngine({
			inlineValidation:true,
			promptPosition:"centerRight"
		});
	}
	$("a[rel='external'],#footerLinks a").click(function(){
		window.open($(this).attr('href'));
		return false;
	});
	if ($('#validation').length!=0) {
		$.get(BASEHREF+"includes/token.php",function(txt){$("#validation").val(''+txt+'');});
	}
	$('form input,form textarea,form select').live('focus',function(){
		var id=$(this).parent().parent().parent().parent().attr('id');
		var thiseq=$('dd').index($(this).parent());
		$('#'+id+' input,#'+id+' textarea,#'+id+' select').removeClass('focused');
		$('#'+id+' dt').removeAttr('class');
		if($(this).attr('type')!='checkbox') $(this).addClass('focused');
		$('dt:eq('+thiseq+')').addClass('focused');
	});
	$('.clearfield').each(function() {
		var el=$(this);
		if(el.attr('rel')==undefined) { el.attr('rel', el.val()).addClass('cf-blur'); }
		el.focus(function() { if(el.val()==el.attr('rel')) { el.val('').removeClass('cf-blur').addClass('cf-blur'); } });
		el.blur(function() { if(el.val()=='') { el.val(el.attr('rel')).removeClass('cf-blur').addClass('cf-blur'); } });
	});
	$("input").attr('autocomplete', 'off');
	$("body").append("<div id=\"window_alerta\"></div><div id=\"AjaxLoading\"></div>");
	if ($("#map_canvas").gMap) {
		$("#map_canvas").gMap({markers:[{latitude:47.713977,longitude:24.425000,html: "Pensiunea Nagy - Str. Prislopului nr. 82 , Viseu de Sus, Maramures, cod postal 435700",popup: true}],zoom:15});
	}
	if ($("#map_canvas2").gMap) {
		$("#map_canvas2").gMap({markers:[{latitude:47.713977,longitude:24.425000,html: "Pensiunea Nagy - Str. Prislopului nr. 82 , Viseu de Sus, Maramures, cod postal 435700",popup: true}],zoom:16});
	}
});
if (window.location=='http://pensiunea-nagy.ro/') {
	window.location=window.siteurl;
}
function alerta(mesaj, error_var, width) {
	if (error_var == null) error_var = false;
	if (width == null) width = 642;
	options={
	'modal' :true,
	'width' :width,
	'minWidth' :642,
	'title' : 'Mesaj atentionare!'
	};
	var mesaj_new="";
	if (error_var) {
		mesaj_new="<div class=\"ui-widget\"><div class=\"ui-state-error ui-corner-all\" style=\"padding:20px; margin:12px;\"><span class=\"ui-icon ui-icon-alert\" style=\"float: left; margin-right: 0.3em;\" ></span>" + mesaj + "</div></div>";
	} else {
		mesaj_new="<div class=\"ui-widget\"><div class=\"ui-state-highlight ui-corner-all\" style=\"padding:20px;  margin:12px;\"><span class=\"ui-icon ui-icon-info\" style=\"float: left; margin-right: 0.3em;\" ></span>" + mesaj + "</div></div>";
	}
	do_win(mesaj_new,options);
}
function do_win(mesaj,options,callback) {
	if ($("#window_alerta").dialog('isOpen')!=undefined) $("#window_alerta").dialog('destroy');
	$("#window_alerta").html(mesaj);
	$("#window_alerta").dialog(options);
	if(callback!=null) callback();
}
function confirma(title,mesaj,button,callback) {
	options={
	'modal' :true,
	'width' :240,
	'buttons': { " Renunta ": function() { $(this).dialog("close"); } ,  " Confirma " : function() { callback(); $(this).dialog("close"); }   },
	'title' : title
	};
	do_win(mesaj,options);
}
function error(mesaj) {
	alerta(mesaj, true);
}
function delete_uploaded(file,id_form) {
	if (confirm('Sunteti sigur ca doriti sa stergeti imaginea')) {
		$(id_form).parent().remove();
		$.post('ajax/base.php', 'delete_file=1&file=' + file);
	}
}

//vortex
function utf8_encode(string) {
	string = string.replace(/\r\n/g,"\n");
	var utftext = "";
	for (var n = 0; n < string.length; n++) {
		var c = string.charCodeAt(n);
		if (c < 128) {
			utftext += String.fromCharCode(c);
		} else if((c > 127) && (c < 2048)) {
			utftext += String.fromCharCode((c >> 6) | 192);
			utftext += String.fromCharCode((c & 63) | 128);
		} else {
			utftext += String.fromCharCode((c >> 12) | 224);
			utftext += String.fromCharCode(((c >> 6) & 63) | 128);
			utftext += String.fromCharCode((c & 63) | 128);
		}
	}
	return utftext;
}
function utf8_decode(utftext) {
	var string = "";
	var i = 0;
	var c = c1 = c2 = 0;
	while ( i < utftext.length ) {
		c = utftext.charCodeAt(i);
		if (c < 128) {
			string += String.fromCharCode(c);
			i++;
		} else if((c > 191) && (c < 224)) {
			c2 = utftext.charCodeAt(i+1);
			string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
			i += 2;
		} else {
			c2 = utftext.charCodeAt(i+1);
			c3 = utftext.charCodeAt(i+2);
			string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
			i += 3;
		}
	}
	return string;
}
function delete_file(file,el) {
	if (confirm('Sunteti sigur ca doriti sa stergeti imaginea')) {
		$(el).parent().remove();
		$.post(BASEHREF+'upload.php','delete_file=1&file='+file);
	}
}
