function slideSwitch() {
    var $active = $svjq('#bildspelet img.active');
    if ( $active.length == 0 ) $active = $svjq('#bildspelet img:last');
    var $sibs  = $active.siblings();
    var rndNum = Math.floor(Math.random() * $sibs.length );
    var $next  = $svjq( $sibs[ rndNum ] );
    $active.addClass('last-active');
    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

function generateEvents(param_res,vAntal) {
	$('#jquery_snippets').html('');
	$(param_res).find('.proxy_Product').each(function(index,val) {
		if(index==vAntal)
			return false;
		var anchor = $(this).find('h2').children('a:last');
		var datumtid = $(this).find('.proxy_occasionText').html();
		var bild = $(this).find('.vp_image a img');
		jQuery('<li/>', {
			style: 'background-image:'+bild.attr('src'),
			html: jQuery('<a/>', {
				href: 'http://www.bokahalsingland.se' + anchor.attr('href'),
				style: 'text-decoration:none;',
				text: anchor.text()
			}).append('<br/><span style="font-size:80%;color:#999;">'+datumtid+'</span>').addClass('blaxlank'),
			style: 'padding-bottom:5px;border-bottom:solid 3px #F4F4EC;'
		}).prepend($('<img style="margin-top:2px;margin-left:5px;margin-bottom:0px;width:40px;float:right;" src="'+bild.attr('src')+'"/>')).appendTo($('#jquery_snippets'));
	});
	return true;
}

$(document).ajaxError(function(e, xhr, settings, exception) {
	getEvenemangOther('http://services.ovanaker.se/services/files/evenemang.html',4);
}); 

function getEvenemang(vAdress, vAntal) {
	$.get(vAdress, function(res) {
		if(res.responseText!=null) {
			generateEvents(res.responseText,vAntal);
		}
		else {
			generateEvents(res,vAntal);
		}
	});
}
function getEvenemangOther(vAdress, vAntal) {
	$.get(vAdress, function(res) {
		if(res.responseText!=null) {
			generateEvents(res.responseText,vAntal);
		}
		else {
			generateEvents(res,vAntal);
		}
	});
}

function getEvenemang2(vAdress, vAntal) {
	$('#jquery_snippets').html('');
	$.get(vAdress, function(res) {
		if(res.responseText!=null) {
			$(res.responseText).find('.proxy_Product').each(function(index,val) {
			if(index==vAntal)
				return false;
				var anchor = $(this).find('h2').children('a:last');
				var datumtid = $(this).find('.proxy_occasionText').html();
				jQuery('<li/>', {
					html: jQuery('<a/>', {
						href: 'http://www.bokahalsingland.se' + anchor.attr('href'),
						text: anchor.text(),
						style: 'text-decoration:none;padding:0;margin:0;'
					}).append('<br/><span style="font-size:80%;color:#999;">'+datumtid+'</span>').addClass('normal c63 c64'),
					style: 'padding-bottom:5px;border-bottom:solid 3px #F4F4EC;'
				}).appendTo($('#jquery_snippets'));
			});
		}
		else {
			$('#jquery_snippets').html('<li>Tyv&auml;rr &auml;r evenemangssidan nere, f&ouml;rs&ouml;k igen lite senare!</li>');
		}
	});
}

function getWeather() {
	$.get('http://widget.vackertvader.se/widgetv3?geonameid=2685093&bgcolor=ffffff&border=none&size=x120&textcolor=363636&days=2&maxtemp=no&wind=no', function(res) {
		$('#weather').append($(res.responseText));
		$('#weather img').each(function() {
		$(this).attr('src','http://widget.vackertvader.se'+$(this).attr('src'));
		});
	});
}
function fixMailLinks() {
	$('a[href^="mailto:"]').addClass('maillink');
}
