$(document).ready(function() {
	// put all your jQuery goodness in here.
	
	
	
	$("div#scrollingText").smoothDivScroll({autoScroll: "always", autoScrollDirection: "endlessloopright", autoScrollInterval: 40, autoScrollStep: 1});

	
	
	function loadit(url) {
		
		$('#target').fadeOut("slow").html('');
		$('#target').fadeIn("slow").html('<img src="http://www.cumap4.se/cuponweb/loading.gif" class="loading">');
		$('#target').fadeIn("slow").load(url, function() {
			
		
		});
	}
	
	function load_ticker(url) {
		
		$('#ticker_target').fadeOut("slow").html('');
		$('#ticker_target').fadeIn("slow").html('Laddar');
		$('#ticker_target').fadeIn("slow").load(url);
		
		console.log('123');
	}


	
	
	
	
	function loadnews(url) {
		
		
		$('.lightbox-content-text').fadeOut("slow").html('');
		$('.lightbox-content-text').fadeIn("slow").html('<img src="http://www.cumap4.se/cuponweb/loading.gif" class="loading-news">');
		$('.lightbox-content-text').fadeIn("slow").load(url, '', function() {
			
			$('.news-left a, .news-right a').click(function() {
				
				var url2 = $(this).attr('href');
				loadnews(url2);
				return false;
			});
		
		});
	}
	
	
	
	
	$('a.falseit').click(function() {
		
		var url = $(this).attr('href');
		loadit(url);
		return false;
	
	});
	
	
	$('.menu-projects li:first').addClass('active');
	
	$('.menu-p a').click(function() {
		
		var url = $(this).attr("href");
		$('.menu-p li').removeClass('active');
		$(this).parent().addClass('active');
		//$('#target').fadeOut('100', loadContent(url));
		loadit(url);
		return false;
	
	});
	
	$('#discipliner.big div').click(function() {
		
		var re = $(this).attr('id');
		var url = 'discipliner/'+ re;
		
		
		loadit(url);
	});
	
	
	
	$('.lightbox').dialog( {
		width:958,
		autoOpen:false,
		closeText: '',
		modal: true
		
	});
	
	
	
	$('.news a').click(function() {
		var url = $(this).attr('href');
		$('.lightbox').dialog('open');
		
		$('.slides').hide();
		
		loadnews(url);
		$('body,html').scrollTop('0');
		return false;
	});
	
	$('.lightbox-close a').click(function() {
		
		$('.lightbox').dialog('close');
		$('.slides').show();
		return false;
	});
	
	$('.scrollableArea').hover(function() {
		
		$("div#scrollingText").smoothDivScroll('stopAutoScroll');
	}, function() {
		$("div#scrollingText").smoothDivScroll('startAutoScroll');
	
	});
	
	
	$('.ticker-read-more').hover(function(e) {
		
		$("div#scrollingText").smoothDivScroll('stopAutoScroll');

	}, function() {
		$('.ticker-read-more').hide();
		$("div#scrollingText").smoothDivScroll('startAutoScroll');
		
	});
	
	$('.scrollableArea a').click(function(e) {
		
		var url = $(this).attr('href');
		
		$('#ticker_target').fadeOut("slow").html('');
		$('#ticker_target').fadeIn("slow").html('Laddar');
		$('#ticker_target').fadeIn("slow").load(url, '', function(ele, h) {
			
			var toppen = $('.ticker-read-more').height();
			
			var x = e.pageX - 110;
			var y = e.pageY - toppen;

			$('.ticker-read-more').css('top',y+"px");
			$('.ticker-read-more').css('left',x+"px");
		
			$('.ticker-read-more').show();
		});
		
		return false;
	});
	
	

});
