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

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


$(function(){
    $('#slideshow1').cycle({
		fx: 'fade'
	});
});

$(function(){
    $('#slideshow2').cycle({
		fx: 'fade'
	});
});


$(document).ready(function() {
	$("#twitter").getTwitter({
		userName: "Syndiqate",
		numTweets: 2,
		loaderText: "Loading tweets..",
		slideIn: true,
		slideDuration: 750,
		showHeading: true,
		headingText: "Latest Tweets",
		showProfileLink: true,
		showTimestamp: true
	});
});

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");
	$(".news_block .top_block_img div:first-child").css("margin-right","0px");
});


//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');
	
}

$(document).ready(function() {
	$("a[href^='http:']:not([href*='" + window.location.host + "'][target='_blank'])").live('click', function(){
        $(this).attr('target','_blank');
    });
});
