/*
**	
*/

$(function() {

/*
	$('.main-menu LI.selected').each(bkgImageOn);

	$('.main-menu LI').not(".selected").hover(function() {
		$(this).each(bkgImageOn); //(this);
	}, function() {
		$(this).each(bkgImageOff); //(this);
//		bkgImageOff(this);
	});
*/

	$('.readmore').after('<div class="readmorelink"><span>Läs mer &raquo;</span></div>');
	$('.readmorelink SPAN').click(function() {
		$(this).parent().prev(".readmore").show("normal");
		$(this).parent().hide();
	});
	
	
	$('.doc-showall').click(function() {
		$(this).parent().parent().children(".doc-hidden").show("normal");
		$(this).parent().parent().children(".hideall").show("normal");
		$(this).parent().hide("normal");
		return false;
	});

	$('.doc-hideall').click(function() {
		$(this).parent().parent().children(".doc-hidden").hide("normal");
		$(this).parent().parent().children(".showall").show("normal");
		$(this).parent().hide("normal");
		return false;
	});

	$('.quickmore').hide();
	$('A.quicka').click(function() {
		var nextmore = $(this).next('.quickmore');
		$('.quickmore').not(nextmore).hide();
		nextmore.toggle();
		return false;
	});

	
	// All external links should open in a new window/tab.
	$('a[href^="http://"]').not('a[href^="http://www.volvofinans.se"]').not('a[href^="http://volvofinans.se"]').attr({ target: "_blank", title: "Länken öppnas i ett nytt fönster" });
	$('a[href^="https://"]').not('a[href^="https://www.volvofinans.se"]').not('a[href^="https://volvofinans.se"]').attr({ target: "_blank", title: "Länken öppnas i ett nytt fönster" });

	$('a[href^="/_docs/"]').attr({ target: "_blank", title: "Dokumentet öppnas i ett nytt fönster" });

	
});

function bkgImageOn() {
	var bkgImage = $(this).css("background-image");
	bkgImage = bkgImage.replace(/_on\.gif/i, ".gif"); // Strip it so we avoid adding double "_on"
	bkgImage = bkgImage.replace(/\.gif/i, "_on.gif");
	$(this).css("background-image", bkgImage);
}
function bkgImageOff() {
	var bkgImage = $(this).css("background-image");
	bkgImage = bkgImage.replace(/_on\.gif/i, ".gif");
	$(this).css("background-image", bkgImage);
}


function openBox(url, width, height) {
	// Opens a Thickbox with an iframe in it.
	// The IFRAME must contain an own closing link ("javascript:self.parent.tb_remove();")
	$('#flash_main').css('visibility', 'hidden');
	$('.flash').css('visibility', 'hidden');
	var newurl = url+"?TB_iframe=true&height="+(height-8)+"&width="+(width-25)+"&modal=true";
	tb_show("Volvofinans", newurl);
}

function closeBox() {
	tb_remove();
	$('#flash_main').css('visibility', 'visible');
	$('.flash').css('visibility', 'visible');
}
