var activeNewsItem = 0;

var row2 = -1;

var open = 0;

function fetch(url, id, id2, arow){
	$.post(url, function(data){
		if (open == id2){ 
			$('.portfolio-view').html('');
			$('.portfolio-view').slideUp(400);
			$('.portfolio-preview').fadeTo(200, 1);
			
			open = 0;
			row2 = -1;
		} else {
			if (arow == row2) {
				var view = $('#' + id + '-view');
				// $('.portfolio-view').fadeOut(250);
				$('.portfolio-view').queue(function(){
					$(this).html('');	
					$(this).dequeue();
				});
				
				$('.portfolio-preview').fadeTo(200, 1);
				var select = $('#' + id2 + '-preview');
				select.fadeTo(250, 0.5);
			
				view.fadeIn(400);
			
				view.queue( function(){
					$(this).html(data); 
					$('#loopedSlider').loopedSlider({
						containerClick: false,
						autoStart: 10000,
						restart: 500,
						slidespeed: 800
					});		
					$(this).dequeue();
					
				});
			} else {
				var view = $('#' + id + '-view');
				$('.portfolio-view').html('');
				$('.portfolio-view').slideUp(400);
				$('.portfolio-preview').fadeTo(200, 1);
				var select = $('#' + id2 + '-preview');
				select.fadeTo(250, 0.5);		
				view.slideDown(400);
				view.html(data);
			
				$('#loopedSlider').loopedSlider({
					containerClick: false,
					autoStart: 10000,
					restart: 500,
					slidespeed: 800
				});
			}
			row2 = arow;
			open = id2;
		}
	});
}

function showNews(id){
	if(activeNewsItem != id){
		activeNewsItem = id;
		$('.news-content p').hide(250);
		$('#news-content-'+id+' p').fadeIn(500);
	}
}

function getNews(url, id){
	alert(url);
	$.post(url, function(data){
		$('#news-content-link-'+id).hide();
		$('#news-content-'+id).html('');
		$('#news-content-'+id).html(data);
	});
}

function initActiveList(){
	$('#diensten .col33 p').hide();
	$('#diensten .col33 h4').click(function(){
		if(!$(this).hasClass("open")){
			$("h4.open").removeClass("open").css("color","").next("p").slideUp(250);
			$(this).addClass("open").css("color","#000").next("p").slideDown(250);
		}else{
			$(this).removeClass("open").css("color","").next("p").slideUp(250);
		}
	});
	$('#diensten .col33 h4').mouseover(function(){
		$(this).css("color","#000");
	});
	$('#diensten .col33 h4').mouseout(function(){
		if($(this).next("p").css("display")=="none"){
			$(this).css("color","");
		}
	});
}

$(document).ready(function(){
	initActiveList();
	
	$('a.werk').click(function() {
		var arow = $(this).attr("class").substr(5,2);
		var top = 220 + arow * 195;
        $.scrollTo({top:top+'px',left:'0px'}, 1000);
    });

});
