$(function() {
		   
	Cufon.replace('#nav-top ul.menu > li > a, #tagline h2, #nav-middle ul.menu > li > a, .widget-bottom h3, .box h3', { fontFamily: 'DIN', hover: true, hoverables: { strong: true, em: true } });
	
	// call slideshow if slideshow area have images
	if($('#slideshow').find('img').length > 0) $('#slideshow').nivoSlider({controlNavThumbs: true,pauseTime: 5000}).parent().css('height', 318);

	// taglines rotator
	$('#tagline ul').innerfade({
		speed: 1000,
		timeout: 5000,
		type: 'random'
	});
	
	// Dropdown menu
    $("#nav-top ul li a").hover(function(){
        $(this).parent().addClass("hover");
        $(this).parent().find('ul:first').show();
    }, function(){
    });
	
    $("#nav-top ul li").hover(function(){
    }, function(){
        $(this).removeClass("hover");
        $(this).find('ul:first').hide();
    });
	
	// Dropdown menu
    $("#nav-middle ul li a").hover(function(){
		var position = $(this).position();
        $(this).parent().addClass("hover");
        $(this).parent().find('ul:first').show();
    }, function(){
    });
	
    $("#nav-middle ul li").hover(function(){
    }, function(){
        $(this).removeClass("hover");
        $(this).find('ul:first').hide();
    });

	equalHeight($(".equal-height")); // function to make boxes have equal height
	equalHeight($(".equal-height2")); // function to make boxes have equal height

	// calculate popup
	$('#get-started').click(function(e) {
		e.preventDefault();

		//Get the A tag
		var id = $(this).attr('href');

		//Get the window width
		var winW = $(window).width();

		//Get the div/modal width
		var idW = $(id).width();
		
		//Set the popup window to center
		$(id).css('top', 479);
		$(id).css('left', ((winW/2)-(idW/2)-20));

		$(id).fadeTo(250, 1);

	});

	//if close button is clicked
	$('.close-button a').click(function (e) {
		e.preventDefault();
		$('.window').fadeOut(150);
	});
	
	var fontDefault = $.cookie('goodwillText');

	if(fontDefault == '' || fontDefault == 'null' || fontDefault == null || fontDefault < 12){
		fontDefault = 12; // default font variable
	} else if(fontDefault > 12) {
		var i = parseInt(fontDefault) - 11;
		$(".equal-height").height('auto'); // set auto height to div with equal height
		$(".equal-height2").height('auto'); // set auto height to div with equal height
		$('div.box > p').css('font-size', parseInt($('div.box > p').css('font-size'))+(2*i));
		$('div.box > p').css('line-height', parseInt($('div.box li').css('line-height'))+(2*i)+'px');
		$('div.box > p a').css('font-size', parseInt($('div.box > p a').css('font-size'))+(2*i));
		$('div.box > p a').css('line-height', parseInt($('div.box > p a').css('line-height'))+(2*i)+'px');
		$('div.box li h4, div.latest-events li h5').css('font-size', parseInt($('div.box li h4, div.latest-events li h5').css('font-size'))+(2*i));
		$('div.box li h4, div.latest-events li h5').css('line-height', parseInt($('div.box li h4, div.latest-events li h5').css('line-height'))+(2*i)+'px');
		$('div.box li, div.box td').css('font-size', parseInt($('div.box li, div.box td').css('font-size'))+(2*i));
		$('div.box li, div.box td').css('line-height', parseInt($('div.box li, div.box td').css('line-height'))+(2*i)+'px');
		$('div.box li').css('padding-left', parseInt($('div.box li').css('padding-left'))+(2*i)+'px');
		$('div.entries ul li div.box h4 a').css('font-size', parseInt($('div.entries ul li div.box h4 a').css('font-size'))+(2*i));
		$('div.entries ul li div.box h4 a').css('line-height', parseInt($('div.entries ul li div.box h4 a').css('line-height'))+(2*i)+'px');
		$('div.box li p, div.latest-events li p, div.latest-tweets li, div.facebook li').css('font-size', parseInt($('div.box li p, div.latest-events li p, div.latest-tweets li, div.facebook li').css('font-size'))+(2*i));
		$('div.box li p, div.latest-events li p, div.latest-tweets li, div.facebook li').css('line-height', parseInt($('div.box li p, div.latest-events li p, div.latest-tweets li, div.facebook li').css('line-height'))+(2*i)+'px');
		$('div.entry h5, div.single h5').css('font-size', parseInt($('div.entry h5, div.single h5').css('font-size'))+(2*i));
		$('div.entry h5, div.single h5').css('line-height', parseInt($('div.entry h5, div.single h5').css('line-height'))+(2*i)+'px');
		$('div.box h5 a, .no-space li a, .entry h6 a').css('font-size', parseInt($('div.box h5 a, .no-space li a, .entry h6 a').css('font-size'))+(2*i));
		$('div.box h5 a, .no-space li a, .entry h6 a').css('line-height', parseInt($('div.box h5 a, .no-space li a, .entry h6 a').css('line-height'))+(2*i)+'px');
		$('div.entry h2, div.single h2').css('font-size', parseInt($('div.entry h2, div.single h2').css('font-size'))+(2*i));
		$('div.entry h2, div.single h2').css('line-height', parseInt($('div.entry h2, div.single h2').css('line-height'))+(2*i)+'px');
		$('div.entry p').css('font-size', parseInt($('div.entry p').css('font-size'))+(2*i));
		$('div.entry p').css('line-height', parseInt($('div.entry p').css('line-height'))+(2*i)+'px');
		equalHeight($(".equal-height")); // set height to div with equal height
		equalHeight($(".equal-height2")); // set height to div with equal height
	}
	
	// Increase / decrease font size
	$('#increaseText').click(function() {
		$(".equal-height").height('auto'); // set auto height to div with equal height
		$(".equal-height2").height('auto'); // set auto height to div with equal height
		$('div.box > p').css('font-size', parseInt($('div.box > p').css('font-size'))+2);
		$('div.box > p').css('line-height', parseInt($('div.box > p').css('line-height'))+2+'px');
		$('div.box > p a').css('font-size', parseInt($('div.box > p a').css('font-size'))+2);
		$('div.box > p a').css('line-height', parseInt($('div.box > p a').css('line-height'))+2+'px');
		$('div.box li h4, div.latest-events li h5').css('font-size', parseInt($('div.box li h4, div.latest-events li h5').css('font-size'))+2);
		$('div.box li h4, div.latest-events li h5').css('line-height', parseInt($('div.box li h4, div.latest-events li h5').css('line-height'))+2+'px');
		$('div.box li, div.box td').css('font-size', parseInt($('div.box li, div.box td').css('font-size'))+2);
		$('div.box li, div.box td').css('line-height', parseInt($('div.box li, div.box td').css('line-height'))+2+'px');
		$('div.box li').css('padding-left', parseInt($('div.box li').css('padding-left'))+2+'px');
		$('div.entries ul li div.box h4 a').css('font-size', parseInt($('div.entries ul li div.box h4 a').css('font-size'))+2);
		$('div.entries ul li div.box h4 a').css('line-height', parseInt($('div.entries ul li div.box h4 a').css('line-height'))+2+'px');
		$('div.box li p, div.latest-events li p, div.latest-tweets li, div.facebook li').css('font-size', parseInt($('div.box li p, div.latest-events li p, div.latest-tweets li, div.facebook li').css('font-size'))+2);
		$('div.box li p, div.latest-events li p, div.latest-tweets li, div.facebook li').css('line-height', parseInt($('div.box li p, div.latest-events li p, div.latest-tweets li, div.facebook li').css('line-height'))+2+'px');
		$('div.entry h5, div.single h5').css('font-size', parseInt($('div.entry h5, div.single h5').css('font-size'))+2);
		$('div.entry h5, div.single h5').css('line-height', parseInt($('div.entry h5, div.single h5').css('line-height'))+2+'px');
		$('div.box h5 a, .no-space li a, .entry h6 a').css('font-size', parseInt($('div.box h5 a, .no-space li a, .entry h6 a').css('font-size'))+2);
		$('div.box h5 a, .no-space li a, .entry h6 a').css('line-height', parseInt($('div.box h5 a, .no-space li a, .entry h6 a').css('line-height'))+2+'px');
		$('div.entry h2, div.single h2').css('font-size', parseInt($('div.entry h2, div.single h2').css('font-size'))+2);
		$('div.entry h2, div.single h2').css('line-height', parseInt($('div.entry h2, div.single h2').css('line-height'))+2+'px');
		$('div.entry p').css('font-size', parseInt($('div.entry p').css('font-size'))+2);
		$('div.entry p').css('line-height', parseInt($('div.entry p').css('line-height'))+2+'px');
		fontDefault = parseInt(fontDefault) + 1; // change font variable (add)
		equalHeight($(".equal-height")); // set height to div with equal height
		equalHeight($(".equal-height2")); // set height to div with equal height
		$.cookie('goodwillText', fontDefault, { path: '/' });
		return false;
	});
	$('#decreaseText').click(function() {
		if(fontDefault > 12) {
			$(".equal-height").height('auto'); // set auto height to div with equal height
			$(".equal-height2").height('auto'); // set auto height to div with equal height
			$('div.box > p').css('font-size', parseInt($('div.box > p').css('font-size'))-2);
			$('div.box > p').css('line-height', parseInt($('div.box > p').css('line-height'))-2+'px');
			$('div.box > p a').css('font-size', parseInt($('div.box > p a').css('font-size'))-2);
			$('div.box > p a').css('line-height', parseInt($('div.box > p a').css('line-height'))-2+'px');
			$('div.box li h4, div.latest-events li h5').css('font-size', parseInt($('div.box li h4, div.latest-events li h5').css('font-size'))-2);
			$('div.box li h4, div.latest-events li h5').css('line-height', parseInt($('div.box li h4, div.latest-events li h5').css('line-height'))-2+'px');
			$('div.box li, div.box td').css('font-size', parseInt($('div.box li, div.box td').css('font-size'))-2);
			$('div.box li, div.box td').css('line-height', parseInt($('div.box li, div.box td').css('line-height'))-2+'px');
			$('div.box li').css('padding-left', parseInt($('div.box li').css('padding-left'))-2+'px');
			$('div.box li p, div.latest-events li p, div.latest-tweets li, div.facebook li').css('font-size', parseInt($('div.box li p, div.latest-events li p, div.latest-tweets li, div.facebook li').css('font-size'))-2);
			$('div.box li p, div.latest-events li p, div.latest-tweets li, div.facebook li').css('line-height', parseInt($('div.box li p, div.latest-events li p, div.latest-tweets li, div.facebook li').css('line-height'))-2+'px');
			$('div.entries ul li div.box h4 a').css('font-size', parseInt($('div.entries ul li div.box h4 a').css('font-size'))-2);
			$('div.entries ul li div.box h4 a').css('line-height', parseInt($('div.entries ul li div.box h4 a').css('line-height'))-2+'px');
			$('div.entry h5, div.single h5').css('font-size', parseInt($('div.entry h5, div.single h5').css('font-size'))-2);
			$('div.entry h5, div.single h5').css('line-height', parseInt($('div.entry h5, div.single h5').css('line-height'))-2+'px');
			$('div.box h5 a, .no-space li a, .entry h6 a').css('font-size', parseInt($('div.box h5 a, .no-space li a, .entry h6 a').css('font-size'))-2);
			$('div.box h5 a, .no-space li a, .entry h6 a').css('line-height', parseInt($('div.box h5 a, .no-space li a, .entry h6 a').css('line-height'))-2+'px');
			$('div.entry h2, div.single h2').css('font-size', parseInt($('div.entry h2, div.single h2').css('font-size'))-2);
			$('div.entry h2, div.single h2').css('line-height', parseInt($('div.entry h2, div.single h2').css('line-height'))-2+'px');
			$('div.entry p').css('font-size', parseInt($('div.entry p').css('font-size'))-2);
			$('div.entry p').css('line-height', parseInt($('div.entry p').css('line-height'))-2+'px');
			equalHeight($(".equal-height")); // set height to div with equal height
			equalHeight($(".equal-height2")); // set height to div with equal height
			fontDefault = parseInt(fontDefault) - 1; // change font variable (substract)
			$.cookie('goodwillText', fontDefault, { path: '/' });
		}
		return false;
	});
	
});

function equalHeight(group) {
	tallest = 0;
	group.each(function() {
		thisHeight = $(this).outerHeight();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
}
