function gb_pages(page, msgperpage, lang,local)
{
	$.post("/site/guestbook/gb.php",  
		{ page: page, msgperpage: msgperpage, lang: lang, local:local}, 
		function(res){ 
		//alert(res);
		$('.gb_msg').remove();
		$('#gbpage').append(res);
		} 
	);
};

function contentlist()
{
	var style=document.getElementById('contentlist').style.display;
	if (style=="none")
	{
		document.getElementById('show').style.display="none"; 
		document.getElementById('hide').style.display=""; 
		document.getElementById('contentlist').style.display="";
	}
	else 
	{
		document.getElementById('show').style.display=""; 
		document.getElementById('hide').style.display="none";
		document.getElementById('contentlist').style.display="none";
	}
}

function filteralbum(table,lang,tag,page)
{
	$.post("/site/galleryfilter.php",  
		{ table: table, lang: lang, tag: tag, p:page }, 
		function(res){ 
		//alert(res);
			$('#gallery_area').remove();
			$('#gallery_header').append(res);
			_gaq.push(['_trackEvent', 'Gallery ('+table+')', 'filter',tag]);
		} 
	)
}

function getVotes(lang,pollid,type)
{
	var res=''; 
	if (type=="radio")
	{
		res = $("input[@name='pollquest']:checked").val();
	}; 
	if	(type=="checkbox")
	{
		$("input[@name='pollquest']:checked").each( function() {

			if (res=='')
			{  res=this.value; } else { res=res+'_'+this.value; };
		});
	};
	if (res!='')
	{	
		$.post("/system/vote.php",  
		{ type: type, value: res, pollid: pollid, lang: lang }, 
		function(res){ 
		//alert (res);
		$('#quest_area').remove();
		$('#quest').append(res);
		} 
	);
	};	
}

function pollResults(lang,pollid)
{
	$.post("/system/vote.php",  
		{ pollid: pollid, lang: lang }, 
		function(res){ 
		$('#quest_area').remove();
		$('#quest').append(res);
		} 
	);
};

function validate_email(field,alerttxt)
{
with (field)
  {
  apos=value.indexOf("@");
  dotpos=value.lastIndexOf(".");
  if (apos<1||dotpos-apos<2)
    {alert(alerttxt);return false;}
  else {return true;}
  }
}

function validate_form(thisform)
{
with (thisform)
  {
    if (validate_email(email,"Not a valid e-mail address!")==false)
    {email.focus();return false;} 
  if (msg.value=='') {alert('Please enter your message'); return false;} else {return true;} 
  }
 }
   
function sendsupport()
{
   var form=document.form;
   if (validate_form(form)==true) {
		var name=form.name.value;
		var email=form.email.value;
		var msg=form.msg.value;
		var lang=form.lang.value;
		$.post("/site/send.php",  
			{ name: name, email: email, msg: msg,lang: lang }, 
			function(res){ 
			 $('#contactform').remove();
			 $('#result').append(res);
			})
		};
};

function fullscreen(album)
{
	$.post('/site/photo/showall.php',  
		{ album: album}, 
		function(res){ 
			if (res!=='error') 
			{ 
				$("#gallery_area").before(res); 
				$("#gallery_area").css('display','none');
				_gaq.push(['_trackEvent', 'Photo Album', 'full']);
			}
		} 
	);
};

function thumbs()
{ 
	$("#gallery_area").css('display','block');
	$("#gallery_area2").remove();
	_gaq.push(['_trackEvent', 'Photo Album', 'thumbs']);
};

function visibility(id)
{
   if ( $('#'+id).css('display') == 'none')
   {
		$('#'+id).css('display','block');
   } else 
   {
		$('#'+id).css('display','none');
   }  
};

$(function()  
{  
  var hideDelay = 500;    
  var name;  
  var more='';
  var hideTimer = null;  
 
  var container = $('<div id="personPopupContainer"><div id="personPopupContent"></div></div>');  
  $('body').append(container);  
  
  $('.halloffame').live('mouseover', function(event)  
  {  
	  // format of name
	  var href=$(this).attr('href');
      name=href.substring(1);
	  if (name[name.length-1]=='/') { name=name.slice(0,-1); }
      
	  if (name == '' || href[0]!='#')  
          return;        // If no name tag, don't popup blank  
  
      if (hideTimer)  
          clearTimeout(hideTimer);  
  
      var pos = $(this).offset();  
      var width = $(this).width();  
      container.css({  
          left: (pos.left)+50 + 'px',  
          top: pos.top + 20 + 'px'
      });  
  
      $('#personPopupContent').html('&nbsp;');  
      var photo='<img src="/files/masters/'+name+'.jpg" style="padding: 5px;" id="'+name+'"/>';
	  morelink="<br/><a onclick=\"LoadMasterProfile('"+name+"','"+lang+"')\" style=\"text-decoration: underline; color: black; cursor:pointer \"  > "+moretext+"...</a>";
	  $('#personPopupContent').html(photo+morelink); 
		      /*$.ajax({  
		          type: 'POST',  
		          url: '/system/mastertip.php',  
		          data: 'name=' + name + '&lang=ru',  
		          success: function(res)  
		          {  $('#personPopupContent').html(res); }  
		      });  */
        container.css('display', 'block');  
		_gaq.push(['_trackEvent', 'Masters', 'photo', name]);
  });  
  
  $('.halloffame').live('mouseout', function()  
  {  
      if (hideTimer)  
          clearTimeout(hideTimer);  
      hideTimer = setTimeout(function()  
      {  
          container.css('display', 'none');  
      }, hideDelay);  
  });  
  
  // Allow mouse over of details without hiding details  
  $('#personPopupContainer').mouseover(function()  
  {  
      if (hideTimer)  
          clearTimeout(hideTimer);  
  });  
  
  // Hide after mouseout  
  $('#personPopupContainer').mouseout(function()  
  {  
      if (hideTimer)  
          clearTimeout(hideTimer);  
      hideTimer = setTimeout(function()  
      {  
          container.css('display', 'none');  
      }, hideDelay);  
  });  
});  

function LoadMasterProfile(name,lang)
{
     if (name!='' && lang!='')
	 {
		 $.ajax({  
	          type: 'POST',  
	          url: '/site/mastertip.php',  
	          data: 'name=' + name + '&lang='+lang,  
	          success: function(res)  
	          {  
				$('#personPopupContent').html(res); 
				_gaq.push(['_trackEvent', 'Masters', 'profile', name]);
			  }  
	      });
	  }
}
