var doneMoving = true;

$(document).ready(function() {
	Cufon.replace('.cufon');
	
	$('.slideshow').each(function(el){
		$(this).tabs({ fx: {opacity: 'toggle'} }).tabs('rotate', 4000);
		
		$(this).mouseover(function(){
			$(this).tabs('rotate', 0, false);
		});
		$(this).mouseout(function(){
			$(this).tabs({ fx: {opacity: 'toggle'} }).tabs('rotate', 4000);
		});
	});
	
	$("#contactform").validate();
	
	if($('#portfolio').length){
		$('.work img').lazyload({effect : "fadeIn"});
	}
	
	$(window).scroll(function(){
		if($(window).scrollTop() < 1200) {
			if($('#tothetop').length){
				$('#tothetop').fadeOut('slow');
			}
		} else {
			if($('#tothetop').length && doneMoving){
				$('#tothetop').fadeIn('slow');
			}
		}	
	});
	
	$('#tothetop').click(function(event){
		doneMoving = false;
		$('html, body').animate({scrollTop:'0px'},'slow','jswing', function(){
			doneMoving = true;
		});
	});
	
	$('#contact-form-link').click(function(event){
		doneMoving = false;
		$('html, body').animate({scrollTop: $('#contact-form').offset().top},'slow','jswing', function(){
		if($(window).scrollTop() > 1200) {
			if($('#tothetop').length){
				$('#tothetop').fadeIn('slow');
			}
		}	
		});
	});
	
});

function spamBlock(a,b,c){
	if(c=="mail"){
		locationstring="mailto:"+a+"@"+b;
	} else {
		locationstring=a+b;
	}
	window.location=locationstring;
}

function externalLinks() {  
	if (!document.getElementsByTagName) return;  
	var anchors = document.getElementsByTagName("a");  
	for (var i=0; i<anchors.length; i++) {  
		var anchor = anchors[i];  
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
			anchor.target = "_blank";
	}
}
window.onload = externalLinks;

