$(document.getElementById('keybox')).ready(function() {
  if ($('#keybox').length) 
	{
		$('#tokeybox').append($('#keybox').html());
		$('#tokeybox').addClass('keybox');
		$('#keybox').remove();
	}
});

$(document).ready(function() {

		$("#show-debug").click(function(){  $("#debug").toggle(); });
	// $("#search-input").focus();	
   	$(".hash").click(function() {
   	if ($(this).hasClass("external")) 
		{
			window.open(location.hostname+"?hash="+$(this).attr("id"));
   	}
   	else
		{
    	document.location.href= "?hash="+$(this).attr("id"); 
    }
	 });
   
    $('.hash').hover(function(){
               $(this).addClass('over');
    }, function() {
        $(this).removeClass('over');
    });

	$("#readmore").click(function(){ 
		$(this).css("display","none");
	 	$("#more").slideDown(300);
	 });
	 
	 if (typeof verifyAge != 'undefined') 
	{
		$('#overlay').css({ opacity: 0.9, width: '100%', height: $(document).height()+'px' });
	}

$('#checkAll').click(
   function()
   {
      $("input.checkbox").attr('checked', $('#checkAll').is(':checked'));   
   }
)

$("#search-input").keyup(function() {
   if($(this).val()!="")
   {
	  $("#searchclose").show();
   }
   else
   {
    $("#searchclose").hide();
   }
});

$("#searchclose").click(function() {
	$("#searchclose").hide();
	$("#search-input").val('');
	$("#search-input").focus();
});

});


function setVerifyAge(aDomain)
{
	document.cookie="verifyAge=1 ; path=/; domain="+aDomain+";";
	$('#overlay').remove();
	$('#verify-box').remove();
}
/*
function checkDiscrict()
{
	if($("#locations option:selected").attr('class')=="discrict")
	{
		$("#locations").attr( 'name', "d" ) 
		$('#hidden').removeAttr('disabled');
	}else
	{
		$("#locations").attr( 'name', "gdzie" ) 
		$('#hidden').attr("disabled", "true");
	}
}
*/
function confirmSubmitAction(Text, Text2)
{
	if($("#select option:selected").val()=="delete")
	{
		var agree=confirm(Text);
		if (agree)
			return true ;
		else
			return false ;
	}
	else if($("#select option:selected").val()==0)
	{
		alert(Text2)
		return false ;
	}
}


function showMiddle(img,imgid)
{
	imgid="middle"+imgid;
  $('body').append("<div id=\""+imgid+"\" class=\"popmiddle\"><div class=\"corner\"></div><img src=\""+$(img).attr("src").replace("thumbnail", "middle")+"\" alt=\"\"/></div>");
  
	$('#'+imgid+' img').load(function() {
		$('#'+imgid).fadeIn(20).css({'top':$(img).offset().top-25+'px','left':$(img).offset().left+72+'px'});
	
		var offsetBott	=  ($('#'+imgid).offset().top + $('#'+imgid).height() - $(window).scrollTop()) - ($(window).height())		
		if(offsetBott>0)
		{
			if(offsetBott>235)
			{
			$('#'+imgid+' div.corner').css('top', 25+offsetBott+'px')
			}
			else
			{
			$('#'+imgid+' div.corner').css('top', 65+offsetBott+'px')
			}
			$('#'+imgid).css('top',parseInt($('#'+imgid).css('top'))-20-offsetBott+'px')
		}	
	  var offsetTop	=  $('#'+imgid).offset().top  - $(window).scrollTop()
		if(offsetTop<0)
		{
			if(offsetTop>-32)
			{
			  $('#'+imgid+' div.corner').css('top', 40+offsetTop+'px')
			}
			else
			{
			 $('#'+imgid+' div.corner').css('top', '0px')
			}
			
	   $('#'+imgid).css('top',(+1*(parseInt($('#'+imgid).css('top'))-(offsetTop))+'px'))
		}
	})
	
	$(img).mouseout(function() {
		 //$('#'+imgid).fadeOut(100, function() {
	   $('#'+imgid).remove();
	 // });  
		});

}
	
function fcountrywidged(valuedOpt, checkedOpt)
{			
		valuedOpt = valuedOpt.replace("-", "_");
		$("select#m option").remove(); 
		if(valuedOpt!='www')
		{
				$("select#m").show(); 
          
           $.each(eval(valuedOpt), function(i, j){ 
           				if(i=="allcounties" || i=="allcities")
           				{
                  	var row = "<option value=\"" + j.value + "\" class=\"grey\">" + j.text + "</option>"; 
                  }
                  else
                  {
                  	if(checkedOpt==j.value)
                  	{
                   	 var row = "<option value=\"" + j.value + "\"    class=\"selected\" selected=\"selected\">" + j.text + "</option>"; 
                  	}
                  	else
                  	{
                  		var row = "<option value=\"" + j.value + "\">" + j.text + "</option>";
                  	}
								}
								$(row).appendTo("select#m"); 
           }); 
      }
		else
		{
		 $("select#m").hide(); 
		}       
}		
	
