var mobile = false;
var ipad = false;

function adjustStyle(height) {
	height = parseInt(height)/2;
	$('.feature-content').css({'height':height, 'bottom':-height-1});
}

function getFeatHeight() {
	var height = $('.feature-list li').height();
	return height;
}

function replacePhone() {
	var telNr = $('.tel').text();
	$('.tel').html(function() {return '<a href="tel:+36702365642">' + telNr + '</a>';});
}

if( $('html.mobile').length ) {
	if( $('html.ipad').length ) {
		// mobile and ipad. leaves mobile on false to treat ipads as desktop
		ipad = true;
	} else {
		// only mobile, not ipad. sets mobile to seperate scripts
		mobile = true;
	}
}

$(document).ready(function() {
	
	Cufon.replace('.col-contents h1, .col-navigation h2, .article-contact h2, .feature-list li h3');
	Cufon.replace('h2 a', {
		color: '#fff',
		hover: {
			color: '#0f0'
		}
	});
	
	$('#goto-top').css({'display':'none'});
	
	if(mobile) {
		replacePhone();
		$(window).scroll(function () {
			if($(window).scrollTop()>370) { $('#goto-top').fadeOut().animate({'top':$(window).scrollTop()+27}, 100).animate({'top':$(window).scrollTop(),'opacity':'toggle'}, 500); }
			else { $('#goto-top').fadeOut(); }
		});
	} else {
		// adds "more" link to content
		$('.more-content').prepend('<a class="more">More info +</a><a class="less">Less info -</a>');
		// hides full content, defines onclick animation 
		var contentHeight = $('.projects #inline_top_text').height();
		$('.projects #inline_top_text').css({'height':'86px'});
		
		$('.more-content .more').click(function() {
			$('.projects #inline_top_text').animate({'height':contentHeight});
			$(this).hide().next('.less').show();
			$(this).parents('.colpadding').addClass('background-color');
			return false;
		});
		$('.more-content .less').click(function() {
			$('.projects #inline_top_text').animate({'height':'86px'});
			$(this).hide().prev('.more').show();
			$(this).parents('.colpadding').removeClass('background-color');
			return false;
		});
		
		if(!ipad) {
			// hover animation on featured content. won't work on an ipad of course.
			adjustStyle( getFeatHeight() );
			$('.feature-list li a').hover(
				function() { $(this).find('.feature-content').animate({bottom:0}, 200, 'easeOutCubic');	},
				function() { $(this).find('.feature-content').animate({bottom:-(getFeatHeight()/2)-1}, 200, 'easeInCubic'); }
			);
		} else {
			replacePhone();
			$(window).scroll(function () {
				if($(window).scrollTop()>370) { $('#goto-top').fadeOut().animate({'top':$(window).scrollTop()+27}, 100).animate({'top':$(window).scrollTop(),'opacity':'toggle'}, 500); }
				else { $('#goto-top').fadeOut(); }
			});
		}
		
	}
	
	$(window).resize( function() {
		if(!mobile) { adjustStyle( getFeatHeight() ); }
	});
	
	
});
