$(function(){


	// when no labels are used, but tekst inside an input or textarea, check if the value isn't the defaultvalue
	$.validator.addMethod("defaultvalue", function(value, element) {
		if($(element).data('defaultValue') == value){
			return false;		
		} else {
			return true;
		}
	}, $.validator.messages.required);

	$('.form .text, .form textarea').focus(function(){
		if($(this).val() == $(this).data('defaultValue')){
			$(this).val('');
		}
	}).blur(function(){
		if(!$(this).val()){
			$(this).val($(this).data('defaultValue'));
			if($(this).next('label.error').length){
				$(this).next('label.error').hide();
			}
		}
	});

	// form validation any form
	// give the required input fields a class 'required', and in case of special field like email, add a class 'email'.
	// more details http://docs.jquery.com/Plugins/validation
	if($('.form').length){
		$('.form').each(function(){			
			$(this).validate({
				submitHandler: function(form){
					$(form).find("input[type='submit']").attr('disabled', 'disabled');
					form.submit();
				}
			});			
		});
	}
});

function showall()
{
	$('ul.menu, div#content h1, ul.portfolio li, div#main h2, div#main h3').css({visibility:'visible'});
}

$(document).ready(function(){
	 try{Typekit.load({active: showall});}catch(e){}
	 
	 if ($('div#text').height() > $('div#main').height()) {
		 // alert($('div#text').css('margin-top'));
		 // alert(parseInt($('div#text').css('margin-top')));
		 $('div#main').css({'height': $('div#text').height() + parseInt($('div#text').css('margin-top')) + 46 + 'px'});
	 }
	 // alert($('div#main').css('height'));
	 // setTimeout(showall, 500);
//	$('div#menu'.css({display: 'block'}));
	(function animateLogoBigTop() {
		$('div#logobigtexturetop').animate({backgroundPosition:"0 141px"}, {duration: 12000, complete: function() {
			$(this).animate({backgroundPosition:"0px 941px"}, {duration: 12000, complete: function() {
				setTimeout(function() {
					animateLogoBigTop();
				},1);
			}
			});
			}
		});
	})();
	(function animateLogoTop() {
		$('div#logotexturetop').animate({backgroundPosition:"0 56px"}, {duration: 12000, complete: function() {
			$(this).animate({backgroundPosition:"0px 856px"}, {duration: 12000, complete: function() {
				setTimeout(function() {
					animateLogoTop();
				},1);
			}
			});
			}
		});
	})();
	(function animateLogoBigBottom() {
		$('div#logobigtexturebottom').animate({backgroundPosition:"0 950px"}, {duration: 12000, complete: function() {
			$(this).animate({backgroundPosition:"0px 150px"}, {duration: 12000, complete: function() {
				setTimeout(function() {
					animateLogoBigBottom();
				},1);
			}
			});
			}
		});
	})();
	(function animateLogoBottom() {
		$('div#logotexturebottom').animate({backgroundPosition:"0 854px"}, {duration: 12000, complete: function() {
			$(this).animate({backgroundPosition:"0px 54px"}, {duration: 12000, complete: function() {
				setTimeout(function() {
					animateLogoBottom();
				},1);
			}
			});
			}
		});
	})();
	$('table.portfolio a').mouseover(function() {
		$('img.portfolio', this).css({visibility: 'hidden'});
		$('div.title', this).css({visibility: 'visible'});
	}).mouseleave(function() {
		$('img.portfolio', this).css({visibility: 'visible'});
		$('div.title', this).css({visibility: 'hidden'});
	});
	$('span.emailaddress').each(function() {
		this.innerHTML = repairEmail();
	});
	/*
	$('a.presspopup').click(function() {
		if (!($('div#popup')[0])) {
			$('body').append('<div id="popup"><br /><h2>CLOSE</h2><img src="' + $('img', $(this))[0].src + '" /></div>');
		}
		$('div#popup').css({'visibility': 'visible'});
	});
	$('div#popup').keypress(function() {
		$(this).css({'visibility': 'hidden'});
	});
	*/
});

 function repairEmail(container) {
	// replace all occurences of <span class="emailaddress">...</span> with a clickable e-mail address
	// trying to give bots gathering e-mail addresses to spam a hard time
	var remail = 'o';
	remail += 't';
	remail += String.fromCharCode(8*8);
	remail += 'var';
	remail += 'enka.c';
	remail += 'o';
	
	return ('<a href="mailto: Varenka%20Paschke%20&lt;d' + remail + 'm&gt;?subject=Website%20reaction"><img src="/site/gfx/emailaddress.png" "alt="d' + remail + 'm"></a>');
}


