$(document).ready(function() {
    $.fn.autosugguest({  
          className: 'ausu-suggest',
          methodType: 'POST',
          minChars: 2,
          rtnIDs: true,
          dataFile: '/wp-content/plugins/ayntt/selectbox.php'
    });
	
    $.fn.autosugguest({  
          className: 'locationfind',
          methodType: 'POST',
          minChars: 2,
          rtnIDs: true,
          dataFile: '/wp-content/plugins/ayntt/selectbox2.php'
    });
	
    $.fn.autosugguest({  
          className: 'xlocationfind',
          methodType: 'POST',
          minChars: 2,
          rtnIDs: true,
          dataFile: '/wp-content/plugins/ayntt/selectbox2.php'
    });


	$('.mapboxt').click(function() {
		var idcat = $(this).find("a").attr("id");
		$(".mapbox ul").hide();
		$(idcat).show();
		$('.mapboxt a').addClass('arrrt');
		$(this).find("a").removeClass().addClass('arrdw');
		//arrrt arrdw
	});
	
	

	var nbheigh = $(".mapnav").height();
	$("#clickdis").css({height: nbheigh+'px'})
	

	$("#dealload").html('<div class="loadist"><img src="/wp-content/themes/ayntt/images/loader.gif" width="16" height="16" /> loading please wait ...</div>');
	$("#dealload").load("/wp-content/plugins/ayntt/dealajax.php?part=default&typ=1");
	$(".listnv ul li").click(function() {
		$(".listnv ul li a").css({"background-position":"bottom"});
		$(".listnv ul li a").removeClass('activemode');
		$(this).find("a").css({"background-position":"top"});
		$(this).find("a").addClass("activemode");
		var loaditem = $(this).find("a").attr("href");
		var teks = loaditem.replace("#", "")
		$("#dealload").html('<div class="loadist"><img src="/wp-content/themes/ayntt/images/loader.gif" width="16" height="16" /> loading please wait ...</div>');
		$("#dealload").load("/wp-content/plugins/ayntt/dealajax.php?part="+teks+"&typ=1");
		return false;
	});
	
	
	$('.mpchk').click(function() {
		var citem = $(this).attr("rel");
		idclas = citem+' li';
		$(idclas).find(':checkbox').attr('checked', this.checked);

     var allVals = [];
     $('.mapbox ul li input:checked').each(function() {
       allVals.push($(this).val());
     });
     $('#allid').val(allVals);
	 var dkal =  $('#allid').val()

	 $.post("/wp-content/plugins/ayntt/googlemap.php",{ catids:dkal,formsact:'yes' } ,function(data) {
	  if(data=='yes') {
		  
		$("#clickdis").show();
	var nbheigh = $(".mapnav").height();
	$("#clickdis").css({height: nbheigh+'px'})
			refreshpage();
	  } else {

	  }
	 });

	});
	
	
	$("#bigbutA").click(function() {
		$('#bigbutB').removeClass('hprodB');
		$("#bigbutB").addClass("prodB");
		$('#bigbutC').removeClass('hprodC');
		$("#bigbutC").addClass("prodC");
		$("#bigbutA").addClass("hprodA");
		$('.adcovz').hide();
		$('#blockA').show();
		return false;
	});
	
	$("#bigbutB").click(function() {
		$('#bigbutA').removeClass('hprodA');
		$("#bigbutA").addClass("prodA");
		$('#bigbutC').removeClass('hprodC');
		$("#bigbutC").addClass("prodC");
		$("#bigbutB").addClass("hprodB");
		$('.adcovz').hide();
		$('#blockB').show();
		return false;
	});
	
	$("#bigbutC").click(function() {
		$('#bigbutA').removeClass('hprodA');
		$("#bigbutA").addClass("prodA");
		$('#bigbutB').removeClass('hprodB');
		$("#bigbutB").addClass("prodB");
		$("#bigbutC").addClass("hprodC");
		$('.adcovz').hide();
		$('#blockC').show();
		return false;
	});
	
	$("#xbigbutA").click(function() {
		$('#bigbutB').removeClass('hprodB');
		$("#bigbutB").addClass("prodB");
		$('#bigbutC').removeClass('hprodC');
		$("#bigbutC").addClass("prodC");
		$("#bigbutA").addClass("hprodA");
		$('.adcovz').hide();
		$('#blockA').show();
		return false;
	});
	
	$("#xbigbutB").click(function() {
		$('#bigbutA').removeClass('hprodA');
		$("#bigbutA").addClass("prodA");
		$('#bigbutC').removeClass('hprodC');
		$("#bigbutC").addClass("prodC");
		$("#bigbutB").addClass("hprodB");
		$('.adcovz').hide();
		$('#blockB').show();
		return false;
	});
	
	$("#xbigbutC").click(function() {
		$('#bigbutA').removeClass('hprodA');
		$("#bigbutA").addClass("prodA");
		$('#bigbutB').removeClass('hprodB');
		$("#bigbutB").addClass("prodB");
		$("#bigbutC").addClass("hprodC");
		$('.adcovz').hide();
		$('#blockC').show();
		return false;
	});
	
	
	$('#recodo').click(function() {
		var idcat = $(this).find("a").attr("href");
		var relid = $(this).find("a").attr("rel");
		$(idcat).fadeTo(10,1);
		$(idcat).show();
		
		 $("#recomsg").html('');
		 $("#recomsg").html('<div class="loadist"><img src="/wp-content/themes/ayntt/images/loader.gif" width="16" height="16" /></div>');
		 $.post("/wp-content/plugins/ayntt/recommend.php",{ listid:relid } ,function(data)
		 {
		  if(data=='yes') //if username not avaiable
		  {
			var xcount = $("#rmcount").text();
			var rmtotl = parseInt(xcount)+1;
			$("#rmcount").html(rmtotl);
			$("#recomsg").html('You have successfully cast a recommendation for this list, thank you. ');
		  }
		  else
		  {
			$("#recomsg").html(data);
		  }
		 });
		$(idcat).fadeTo(5000,0,function () {
            $(this).hide();
          });
		return false;
	});
	
	$('#addowner').click(function() {
	var idcat = $(this).find("a").attr("href");
	$(idcat).show();
	return false;
	});
	$('#closeit').click(function() {
	var idcat = $(this).find("a").attr("href");
	$(idcat).hide();
	return false;
	});
	
	$('a[rel=boxpop]').click(function(e) {

		
		e.preventDefault();
		var id = $(this).attr('href');
		var scrd = $(this).attr('id');
		if (scrd == 'scroll') {
		$("html, body").animate({scrollTop:"70px"});
		}
		var nid = id.replace('#','');
		var nkid = "#mod-"+nid;
		$(nkid).html('<div class="loadist"><img src="/wp-content/themes/ayntt/images/loader.gif" width="16" height="16" /> loading please wait ...</div>');
		$(nkid).load("/wp-content/themes/ayntt/modalpop.php?type="+nid);

		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
		$('#mask').css({'width':maskWidth,'height':maskHeight});
		//$('#mask').fadeIn(1000);	
		$('#mask').fadeTo("slow",0.8);	

		var winH = $(window).height();
		var winW = $(window).width();
		$(id).css('top',  winH/2-$(id).height()/2);
		$(id).css('left', winW/2-$(id).width()/2);
		$(id).fadeIn(2000); 
	});
	
	$('.window .close').click(function (e) {
		e.preventDefault();
		$('#mask').hide();
		$('.window').hide();
	});		
	$('#mask').click(function () {
		$(this).hide();
		$('.window').hide();
	});	
	

});

function pageloader(hid,url) {
		$(hid).html('<div class="loadist"><img src="/wp-content/themes/ayntt/images/loader.gif" width="16" height="16" /> loading please wait ...</div>');
		$(hid).load(url);
		return false;
}

function forgot(typ) {
	
		$('#mask').hide();
		$('.window').hide();
		
		var id = '#forgot';
		var nkid = "#mod-forgot";
		$(nkid).html('<div class="loadist">loading please wait ...</div>');
		$(nkid).load("/wp-content/themes/ayntt/modalpop.php?type=forgot&acc="+typ);

		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
		$('#mask').css({'width':maskWidth,'height':maskHeight});
		//$('#mask').fadeIn(1000);	
		$('#mask').fadeTo("slow",0.8);	

		var winH = $(window).height();
		var winW = $(window).width();
		$(id).css('top',  winH/2-$(id).height()/2);
		$(id).css('left', winW/2-$(id).width()/2);
		$(id).fadeIn(2000);
		
		return false;
}

function regmodal() {
	
		$('#mask').hide();
		$('.window').hide();
		var id = '#register';
		var nkid = "#mod-register";
		$(nkid).html('<div class="loadist">loading please wait ...</div>');
		$(nkid).load("/wp-content/themes/ayntt/modalpop.php?type=register");

		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
		$('#mask').css({'width':maskWidth,'height':maskHeight});
		//$('#mask').fadeIn(1000);	
		$('#mask').fadeTo("slow",0.8);	

		var winH = $(window).height();
		var winW = $(window).width();
		$(id).css('top',  winH/2-$(id).height()/2);
		$(id).css('left', winW/2-$(id).width()/2);
		$(id).fadeIn(2000);
		
		return false;
}


function registerlog (typmo) {
if (typmo == 0) {
 var usrmail = $('#usrmail:input').val();
 var usrpass = $('#usrpass:input').val();
 $(".error_msg").html('');
 $(".error_msg").html('<div class="loadist"><img src="/wp-content/themes/ayntt/images/loader.gif" width="16" height="16" /></div>');
 $.post("/wp-content/plugins/ayntt/login.php",{ useremail:usrmail,userpass:usrpass,logtype:'0' } ,function(data)
 {
  if(data=='yes') //if username not avaiable
  {
		$('#mask').hide();
		$('.window').hide();
		//window.document.location.href = top.location;
		window.document.location.href = '/';
  }
  else
  {
	$(".error_msg").html('Error login: '+data).fadeTo(900,1);
  }
 });
} else {
 var usrmail = $('#busrmail:input').val();
 var usrpass = $('#busrpass:input').val();
 $(".berror_msg").html('');
 $(".berror_msg").html('<div class="loadist"><img src="/wp-content/themes/ayntt/images/loader.gif" width="16" height="16" /></div>')
 $.post("/wp-content/plugins/ayntt/login.php",{ useremail:usrmail,userpass:usrpass,logtype:'1' } ,function(data)
 {
  if(data=='yes') //if username not avaiable
  {
		$('#mask').hide();
		$('.window').hide();
		window.document.location.href = '/user-panel';
  }
  else
  {
	$(".berror_msg").html('Error login: '+data).fadeTo(900,1);
  }
 });
}
}


function registermo () {
 var regemail = $('#remail:input').val();
 var regname = $('#rname:input').val();
 var regtel = $('#rtel:input').val();
 var regree = $('#rterms:checkbox:checked').val();
 $(".error_msg").html('');
 $(".error_msg").html('<div class="loadist"><img src="/wp-content/themes/ayntt/images/loader.gif" width="16" height="16" /></div>')
 var errz = 0;
if (regree !== undefined) {
 if (!/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(regemail)) {
	$(".error_msg").html('Please enter a valid e-mail.').fadeTo(900,1);
	errz = 1;
 }
 if (regemail == '' && regname == '' && regtel == '') {
	$(".error_msg").html('Please fill all fields.').fadeTo(900,1);
	errz = 1;
 }
 if (errz == 0) {
 $.post("/wp-content/plugins/ayntt/register.php",{ remail:regemail,rname:regname, rtel:regtel } ,function(data)
 {
  if(data=='yes') //if username not avaiable
  {
	//$(".error_msg").css({"color":"green"});
	//$(".error_msg").html('Registration Success, please check email for your password').fadeTo(900,1);
		$('#mask').hide();
		$('.window').hide();
		window.document.location.href = '/information/?msg=24';
  }
  else
  {
	$(".error_msg").html('Error: '+data).fadeTo(900,1);
  }
 });
  }
} else {
 $(".error_msg").html('You must agree to terms of use').fadeTo(900,1);
}

}



function forgotpass() {

 var usrmail = $('#emailadd:input').val();
 var usrtyp = $('#acctype').val();

 $(".error_msg").html('');
 $(".error_msg").html('<div class="loadist"><img src="/wp-content/themes/ayntt/images/loader.gif" width="16" height="16" /></div>');
 $.post("/wp-content/plugins/ayntt/forgot.php?test=s",{ useremail:usrmail,usertype:usrtyp } ,function(data)
 {
  if(data=='yes') //if username not avaiable
  {
		$('#mask').hide();
		$('.window').hide();
		window.document.location.href = '/information/?msg=21';
  }
  else
  {
	$(".error_msg").html('Error: '+data).fadeTo(900,1);
  }
 });
 
}


function suggestlist () {
 var regemail = $('#radd:input').val();
 var regname = $('#rname:input').val();
 var regtel = $('#rwww:input').val();
 var regree = $('#rterms:checkbox:checked').val();
 $(".error_msg").html('');
 $(".error_msg").html('<div class="loadist"><img src="/wp-content/themes/ayntt/images/loader.gif" width="16" height="16" /></div>')
 var errz = 0;
if (regree !== undefined) {
 if (regemail == '' && regname == '' && regtel == '') {
	$(".error_msg").html('Please fill all fields.').fadeTo(900,1);
	errz = 1;
 }
 if (errz == 0) {
 $.post("/wp-content/plugins/ayntt/suggest.php",{ radd:regemail,rname:regname, rwww:regtel } ,function(data)
 {
  if(data=='yes') //if username not avaiable
  {
		$('#mask').hide();
		$('.window').hide();
		window.document.location.href = '/information/?msg=23';
  }
  else
  {
	$(".error_msg").html('Error: '+data).fadeTo(900,1);
  }
 });
  }
} else {
 $(".error_msg").html('You must agree to terms of use').fadeTo(900,1);
}

}
