//Activating news slider
$(function() {
	
		$( "#news_slider" ).accessNews({
			headline : "The News",
			speed : "normal",
			slideBy : 4
		});
		
	});

$(function() {
	
		$( "#clients_slider" ).accessNews({
			headline : "Clients",
			speed : "normal",
			slideBy : 1
		});
		
	});

Cufon.replace("h3");
Cufon.replace("h4");
Cufon.replace("#content_date");
Cufon.replace(".overview_date");
Cufon.replace("#news_slider_nav a");
Cufon.replace("#go_back");
Cufon.replace("#menu ul li a");

//OPENS LINKS IN NEW WINDOW/TAB
$(function() {
	$(".external").attr("target","_blank");
});


//Ajax Submitting form
$(document).ready(function(){
						   	
    $("#form_subscribe").validate({ //start validation of the subscribe form
 		submitHandler: function() { //if validation is true start with ajax submit
   			$("#form_subscribe").after('<div id="emailInfo"></div>'); //creating div after form to be used as a place for user messages
			var formdata = $("#form_subscribe").serialize();
			var tablename = $("#form_subscribe").attr("name");
		
			$.ajax({
				type: "POST",
				url: "../subscr_newsletter.php",
				data: "table=" + tablename + "&" + formdata,
				timeout: 2000,
				error: function (XMLHttpRequest, textStatus, errorThrown) {
					ajaxSubmitError(XMLHttpRequest, textStatus, errorThrown);
					$("#emailInfo").addClass("emailinfo_negative");
					$("#emailInfo").html("Invalid Email");
				},
				success: function (data) {
					$("#emailInfo").addClass("emailinfo_positive");
					$("#emailInfo").html("Emailadress added");
				}
			});
			return false;		
 		}
	});
});





function resizeImage() {
	var window_height = parseInt($(window).height());
	var window_width  = parseInt($(window).width());
	
	var image_width = parseInt($('#background-image').attr('width'));
	var image_height = parseInt($('#background-image').attr('height'));

	var height_ratio = window_height / image_height
	var width_ratio = window_width / image_width
	
	
	if (height_ratio > width_ratio) {
		var new_height = Math.ceil(height_ratio * image_height);
		var new_width = Math.ceil(height_ratio * image_width);
		
	} else {
		var new_height = Math.ceil(width_ratio * image_height);
		var new_width = Math.ceil(width_ratio * image_width)
	}

	$('#background-image').attr('width', new_width);
	$('#background-image').attr('height', new_height);
	
	// Render offsets
	var lMargin = Math.floor((new_width-window_width)/2);
	var hMargin = Math.floor((new_height-window_height)/2);
	$('#background-image').css('margin-left', '-'+lMargin+'px');
	$('#background-image').css('margin-top', '-'+hMargin+'px');
	
}


