// Sponsor Rotate
this.randomtip = function(){
	var length = $("#SponsorRotate a").length;
	var ran = Math.floor(Math.random()*length) + 1;
	$("#SponsorRotate a:nth-child(" + ran + ")").show();
};


$(document).ready(function(){

	// Sponsor Rotate activate
	randomtip()
	
	
	// Fancybox
	$("a.group").fancybox({
		'transitionIn'			:	'elastic',
		'transitionOut'			:	'elastic',
		'speedIn'				:	600, 
		'speedOut'				:	200, 
		'padding'				:	0,
		'overlayShow'			:	true,
		'hideOnOverlayClick'	:	true,
		'overlayOpacity'		: 	'0.8',
		'titleShow'				:	false,
		'overlayColor'			:	'#000',
		'centerOnScroll'		:	true
	});

	// Front page slider
	$('#HeaderImage').innerfade({
		speed: 1000,
		timeout: 5000,
		type: 'sequence',
		containerheight: '220px'
	});
	// Add silly arrow after .current links
	$('#Menu2 a.current').append(' &rarr;');	
	
	
	// Gallery tweaks
	// Making whole div clickable and follow the same URL as $Link
	$('.galleryController').click(function(){
		window.location=$(this).find("a").attr("href");
		return false;
	});
	// Remove margin on 4th child
	$('#galleryWrapper .galleryController:nth-child(4)').css("margin","0 0 20px 0");	
	// Remove margin on 5th child
	$('#Gallery .galleryThumb:nth-child(5)').css("margin","0 0 15px 0");		


	// Unifying div height of all .galleryController 's
	var _height = 0;
	$(".galleryController").each(function() {
		if($(this).height() > _height) {
			_height = $(this).height();
		};
	});
	$(".galleryController").height(_height);


	// Unifying div height of all .hotTopicBox 's
	var _height = 0;
	$(".hotTopicBox").each(function() {
		if($(this).height() > _height) {
			_height = $(this).height();
		};
	});
	$(".hotTopicBox")
		.height(_height)
		.css("cursor","pointer")
		.click(function(){
		window.location=$(this).find("a").attr("href");
		return false;
	});
	
	// Remove margin on 2nd child
	$('.hotTopicBox:nth-child(odd)').css("margin","10px 0px 10px 0px");	


	// Unifying div height of all .miniTopicBox 's (hotTopicBox's younger brother)
	var _height = 0;
	$(".miniTopicBox").each(function() {
		if($(this).height() > _height) {
			_height = $(this).height();
		};
	});
	$(".miniTopicBox")
		.height(_height)
		.css("cursor","pointer")
		.click(function(){
		window.location=$(this).find("a").attr("href");
		return false;
	});

	// Remove margin on 2nd child
	$('.miniTopicBox:nth-child(even)').css("margin","10px 0px 10px 0px");	

	$("#HeaderNews div.first:first")
		.prepend("<img src='themes/bms/images/newtag.png' alt='newtag' title='Nyeste Artikel' />")
		.css("cursor","pointer")
		.click(function(){
			window.location=$(this).find("a").attr("href");
			return false;
	});


});
