// when the DOM is ready...
$(document).ready(function () {
	
	$('#coda-slider-1').codaSlider({
           dynamicArrows: false,
           dynamicTabs: false
       	});
	
	function initColumns()
	{
		$('#vara_bostadsomraden_con').jScrollPane({showArrows:false, scrollbarWidth: 9, arrowSize: 16});
		$('#bovardar_con').jScrollPane({showArrows:false, scrollbarWidth: 9, arrowSize: 16});
		$('#tv-kanaler_con').jScrollPane({showArrows:false, scrollbarWidth: 9, arrowSize: 16});
		$('#personal_con').jScrollPane({showArrows:false, scrollbarWidth: 9, arrowSize: 16});
		$('#styrelsen_con').jScrollPane({showArrows:false, scrollbarWidth: 9, arrowSize: 16});
		$('#faq_con').jScrollPane({showArrows:false, scrollbarWidth: 9, arrowSize: 16});
		$('#felanmalan_con').jScrollPane({showArrows:false, scrollbarWidth: 9, arrowSize: 16});
	}
	
	$('a:first', '.submenu').each(function(){
	$(this).addClass('current');
	
		var page = $(this).attr('rel');
		var lPage = $(this).attr('href').replace("#", "");
		$('.content', '#'+page).fadeTo("fast", 0.1, function(){
			$('.content', '#'+page).load('page/load_page/'+lPage, '', function(){
				initColumns();
				$('.content', '#'+page).fadeTo("fast", 1, function(){
					if (jQuery.browser.msie)  
                 	this.style.removeAttribute('filter');  
				});
			});
		});

	});
	
	$('.submenu a').click(function(){
		$(this).parent().siblings().find('a').removeClass('current');	
		
		$(this).addClass('current');
	
		var page = $(this).attr('rel');
		var lPage = $(this).attr('href').replace("#", "");
		$('.content', '#'+page).fadeTo("fast", 0.1, function(){
			$('.content', '#'+page).load('page/load_page/'+lPage, '', function(){
				initColumns();
				$('.content', '#'+page).fadeTo("fast", 1, function(){
					if (jQuery.browser.msie)  
                 	this.style.removeAttribute('filter');  
				});
			});
		});
		return false;
	});
    function selectNav() {
        $(this)
            .parents('ul:first')
                .find('a')
                    .removeClass('selected')
                .end()
            .end()
            .addClass('selected');
    }

    $('#menu').find('a').click(selectNav);

    // go find the navigation link that has this target and select the nav
    function trigger(data) {
        var el = $('#menu ul').find('a[href$="' + data.id + '"]').get(0);
        selectNav.call(el);
    }

    if (window.location.hash) {
        trigger({ id : window.location.hash.substr(1) });
    } else {
        $('#menu a:first').click();
    }
});