/**
* KSCMS TEMPLATE PLUGINS
*/

// Popup med informasjon om utvikler
jQuery.fn.brand = function(){

	$('a[rel*=ksw_element]').click(function(){
 		$('.ksw_cont').fadeIn('fast');
		return false;
	});
			
	$('a[rel*=ksw_element_close]').click(function(){
		$('.ksw_cont').fadeOut('fast');
		return false;
	});
}

// Når man er logget inn fungerer dette på brukermenyen
jQuery.fn.accordion = function(options){

	var settings = $.extend({
		affect_id: '#list',
		speed: 'normal'
	}, options);
	
	$(settings.affect_id+' ul').hide();
	$(settings.affect_id+' li a').click(function() {

		var checkElement = $(this).next();
	
		if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
			return false;
		}
		
		if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
			$(settings.affect_id+' ul:visible').slideUp(settings.speed);
			checkElement.slideDown(settings.speed);
			return false;
		}
		
	});
}

// Animere alle Hash
jQuery.fn.slideHash = function(i){

	settings = $.extend({
		speed: 'normal'
	}, i);
	
	$('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}, settings.speed);
				return false;
			}
		}	
	});
}

// Tooltip
jQuery.fn.tooltip = function(p){

	settings = $.extend({
		xOffset: 10,
		yOffset: 10
	}, p);
	

	$("a.tooltip").hover(function(e){	
			
		splitted_title = this.title.split('-');
		this.t = splitted_title[0];
		this.title = "";
													  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - settings.xOffset) + "px")
			.css("left",(e.pageX + settings.yOffset) + "px")
			.fadeIn("fast");		
	},
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
	});	
	$("a.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - settings.xOffset) + "px")
			.css("left",(e.pageX + settings.yOffset) + "px");
	});
}



