/**
 * @author Alexander Farkas
 */

(function($) {
	$.extend($.fx.step,{
	    backgroundPosition: function(fx) {
            if (fx.state == 0 && typeof fx.end == 'string') {
                var start = $.curCSS(fx.elem,'backgroundPosition');
                start = toArray(start);
                fx.start = [start[0],start[2]];
                var end = toArray(fx.end);
                fx.end = [end[0],end[2]];
                fx.unit = [end[1],end[3]];
			}
            var nowPosX = [];
            nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
            nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];           
            fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];
            
           function toArray(strg){
               strg = strg.replace(/left|top/g,'0px');
               strg = strg.replace(/right|bottom/g,'100%');
               strg = strg.replace(/(\d+)(\s|\)|$)/g,"$1px$2");
               var res = strg.match(/(\d+)(px|\%|em|pt)\s(\d+)(px|\%|em|pt)/);
               return [parseFloat(res[1]),res[2],parseFloat(res[3]),res[4]];
           }
        }
	});
    
})(jQuery);


/*-------------------------------------------------------------------- 
 * JQuery Plugin: "EqualHeights"
 * by:	Scott Jehl, Todd Parker, Maggie Costello Wachs (http://www.filamentgroup.com)
 *
 * Copyright (c) 2008 Filament Group
 * Licensed under GPL (http://www.opensource.org/licenses/gpl-license.php)
 *
 * Description: Compares the heights or widths of the top-level children of a provided element 
 		and sets their min-height to the tallest height (or width to widest width). Sets in em units 
 		by default if pxToEm() method is available.
 * Dependencies: jQuery library, pxToEm method	(article: 
		http://www.filamentgroup.com/lab/retaining_scalable_interfaces_with_pixel_to_em_conversion/)							  
 * Usage Example: $(element).equalHeights();
  		Optional: to set min-height in px, pass a true argument: $(element).equalHeights(true);
 * Version: 2.0, 08.01.2008
--------------------------------------------------------------------*/







$(function() {

	
	// fjerner borders fra billedlinks
	$('a img').parent().css("border", 0); 
	
	
	// Sætter col2 
	var col2gutter = $('#colTop .col2 .gutter:first');
	var col3gutter = $('#colTop .col3 .gutter:first');
			
	if ($.browser.msie && $.browser.version == 6.0) { $(this).children().css({ 'height': col3gutter.height() - 2}); }
	$(col2gutter).css({ 'min-height': col3gutter.height() - 4});
		
	
	// Zebra-striping
	$(".nyheder .nyhed:nth-child(even)").addClass("even");
	$("#uddLinks li:nth-child(even)").addClass("even");
	
	
	// Rounded corners på .abox billeder
	$('.abox .image').corner("top 5px");
	
	
	
	
	
	// Gør første og sidste en anelse mindre i højden, så de er ens (pga top- og bottom divs udenom)
	$('#uddLinks li:first, #uddLinks li:last').css("padding", "9px 0 8px");

	
	// Fancy effect på uddannelseslinks
	$('ul#uddLinks li').css( {backgroundPosition: '12px 55%'} );
	$('ul#uddLinks li').hover(function(){
			$(this).stop().animate({backgroundPosition: '(16px 55%)'}, 100);
		}, function(){
			$(this).stop().animate({backgroundPosition: '(12px 55%)'}, 100);
	});
	

	// Gør hele .abox elementet klikbart
	$('.abox').click(function(){
		window.location = $('.text a', this).attr("href"); return false;
	});	
	
	
	// Forkorter nyhedssummary
	$('.nyhed').each(function(){
		var maxLen	= 30;
		
		var str 	= $('.tekst', this).html();
		var currLen	= str.length;
		
		if (currLen >= maxLen) {
			var str = str.substr(0,maxLen) + '...';
			$('.tekst', this).html(str);
		}
	});
	
	
	// Sætter .gif ind på .abox til runde hjørner
	$('.abox').each(function(){
		var aboxTop = '<img class="aboxTop" width="213" height="8" src="http://eucnordvest.dk/media/abox-top.gif" alt="">';
		$(this).prepend(aboxTop);
	});
	
	
	
	// Forkorter nyhedsoverskrifter
	/*
	$('.nyhed').each(function(){
		var maxLen	= 30;
		
		var str 	= $('h3 a', this).html();
		var currLen	= str.length;
		
		if (currLen >= maxLen) {
			var str = str.substr(0,maxLen);
			$('h3 a', this).html(str);
		}
	});
	*/
	
	
	
	// UBRUGT
	
	/*
	
	$(document).find("*:not(td)").pngFix();
	
	$('#quicksearch_f input.btn').live("hover", function() {
		$(this).fadeTo(100,1);
	}, function(){
		$(this).fadeTo(100,0.7);
	});
	
	function shorten(el,maxLen){
		console.log(el);
		var currLen = el.length;
	
		if (currLen >= maxLen) {
			var str = str.substr(0,maxLen) + '...';
			el.html(str);
		}
	}

	$('.nyhed .tekst').each(function(){
		var txt = $('.nyhed .tekst');
		shorten(txt,5);
	});
	
	*/
	
	
	
	
	
});