/* Experimental things.. START */
walpfloat = function(){	

/*
$("#cont:contains('KSCMS')").each(function(){

        $(this).html($(this).html().replace(/KSCMS/, "<a href='http://kimsandvold.com/kscms'>KSCMS</a>"));

});
*/
};




/* Animated hash slide */
function slideHash(){
	$('a[href*=#]').click(function() {
		if(location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
			var $target = $(this.hash);
			$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
			if ($target.length) {
				var targetOffset = $target.offset().top;
				$('html,body').animate({scrollTop: targetOffset}, 300);
				return false;
			}
		}
	});
}
/* Set language */
function setLang(){
	if($.cookie("lang") != ''){
		lang = ($.cookie("lang") == null) ? "norwegian" : $.cookie("lang");
		$('body').translate(lang);
		
		$("a[rel*=sel-lang]").click(function(){
			
			$.cookie("lang", $(this).attr("href"), { expires: 7 });
			lang = ($.cookie("lang") == "en") ? "english" : "norwegian";
			$('body').translate(lang);
			event.preventDefault();
	
		});
	}
}

/* Closeing the contact form */
function closeWin(){
	$('#contactForm').remove();
}

/* Sending the email */
function sendData(){
	var urlStr = 'process.php?n='+ $('#i_name').val() +'&e='+ $('#i_email').val() +'&m='+$('#contactMessage').val() +'';
	$.ajax({
		type: "GET",
		url: urlStr,
		data: "",
		success: function(msg){
			if(msg == ''){
				$('#center').html('<div id="heading">E-mail sendt!</div><p><a href="#" onclick="closeWin();return false;">Back to website!</a></p>');
			}else{
				$('#center').html('<div id="heading">Error!</div><p><a href="#" onclick="closeWin();return false;">'+msg+'. Back to website!</a></p>')
			}
		}
	});
}

/* Loading the contact form */
function tcf(data){
	$.ajax({
		type: "POST",
		url: data,
		data: "",
		success: function(msg){
			$("body").append(msg);
			$('#i_name').focus();
		}
	});
}
		
/* Facebook sharing popup */
function fbs_click() {
	var width = 626;
	var height = 400;
	var pop_top = (window.innerHeight / 2) - (height / 2);// Centers the popup vertically
	var pop_left = (window.innerWidth / 2) - (width / 2);// Centers the popup horizontally 
	u = location.href;
	t = document.title;
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width='+width+',height='+height+', left='+pop_left+',top='+pop_top+'');
	return false;
}



/* jQuery tooltip - Simple jQuery tooltip */
this.tooltip = function(){	

	xOffset = 10;
	yOffset = 20;		
	
	$("a.tooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.css('opacity', 0.8)
			.fadeIn(500);		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$("a.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};



