/* ------------------------------------------------------------------------ */
/* UTILS 																*/
/* ------------------------------------------------------------------------ */

function stopBubling(e)
{
    if (!e) var e = window.event;
	e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();
	
	return true;  
}

/* ------------------------------------------------------------------------ */
/* MOUSE OVER 																*/
/* ------------------------------------------------------------------------ */

function mOver(aObj){
	imgObj = aObj.getElementsByTagName('img');
	
	imgObj[0].src = imgObj[0].src.replace("_off.","_on.");
	
	aObj.onmouseout = function()
	{
		imgObj[0].src = imgObj[0].src.replace("_on.","_off.");
	}
}

/* ------------------------------------------------------------------------ */
/* BUTTON OVER 																*/
/* ------------------------------------------------------------------------ */

function mOverButton(inpObj){
	
	inpObj.src = inpObj.src.replace("_off.","_on.");
	
	inpObj.onmouseout = function()
	{
		this.src = this.src.replace("_on.","_off.");
	}
}

/* ------------------------------------------------------------------------ */
/* jQuery FAQ like expanding list											*/
/* ------------------------------------------------------------------------ */

$(document).ready(function(){									// body.onload()
	var aExpandingList = "dl.p80jq_expandinglist"; 				// dl-tag classname to trigger
	$(aExpandingList+" dt").click(function () { 				// add click function to dt-tags
		if($(this).hasClass('open')) {							// check to see if item is already open
			$(this).removeClass('open'); 						// remove the classname 'open' on all dt-tags
			$(this).next('dd').slideUp('fast');					// animate the dd-tag when clicked
		} else {
			$(aExpandingList+" dd:visible").slideUp('fast'); 	// hide the dd-tag
			$(aExpandingList+" dt").removeClass('open'); 		// remove the classname 'open' on all dt-tags
			$(this).toggleClass('open'); 						// toggle the classname 'open' on dt-tags
			$(this).next('dd').slideDown('fast'); 				// animate the dd-tag when clicked
		}
	});
	
	$('.p80faq_list').find('.selected').parent().parent().prev().addClass('open').next('dd').slideDown('fast');
	
	$('.tooltip').tooltip({delay: 0});
	
});


/* ------------------------------------------------------------------------ */
/* REMOVE FILL IN TEXTFIELDS												*/
/* ------------------------------------------------------------------------ */

 function removeDefaultFill( el, s )
	   {
	      if ( el.value == s ) 
	      {
	         el.value = '';
	      }	      
	   }
	   
	   function insertDefaultFill( el, s )
	   {     
	      if ( el.value == '' ) 
	      {
	         el.value = s;
	      }
	   }
	   
	   function checkDefault( value, defaultValue )
	   {
	      if ( value != defaultValue )
	      {
	         return true;
	      }
	      else
	      {
	         return false;
	      }
	   }
	   
	   
var currentSubBlok=null;

function showBlok(aElm,subBlokId,mOver)
{
	var imgElm = aElm.getElementsByTagName('img')[0];
	var subBlokObj = document.getElementById(subBlokId);


	if ($('#'+subBlokId).css('display') == 'none')
	{ 
		var img = $(aElm).find('a > span.title').css('background-image').replace('item-block-arrow','item-block-arrow-down');
	} else {
		var img = $(aElm).find('a > span.title').css('background-image').replace('item-block-arrow-down','item-block-arrow');
	}

	$('#'+subBlokId).toggle();
	$(aElm).find('a > span.title').css('background-image',img);

	
	
	/*
	
	if(currentSubBlok)
	{
		currentSubBlok.style.display="none";
	}
		
	if(subBlokObj)
	{
		subBlokObj.style.display="block";
		currentSubBlok=subBlokObj;
		document.onmouseup = function()
		{
			currentSubBlok.style.display="none";
			document.onmouseup=null;
		}
	}
	aElm.onmouseout = function()
	{
		var imgElm = this.getElementsByTagName('img')[0];
	}
	*/
}

function showPopup(id)
{
    scrollTo(0, 0);
    var popup = document.getElementById(id);
    if (popup) popup.style.display = 'block';
}

function closePopup(id)
{
    var popup = document.getElementById(id);
    if (popup) popup.style.display = 'none';
}

function rightClick(e) {
    if (navigator.appName == 'Netscape' && (e.which == 3 || e.which == 2)) return false;
    else if (navigator.appName == 'Microsoft Internet Explorer' && (event.button == 2 || event.button == 3)) 
    {
        if ( String(location.href).indexOf('.poort80.') >= 0) return true;
        alert("Deze functie is niet beschikbaar.");
        return false;
    }
    return true;
}

document.onmousedown = rightClick;
document.onmouseup = rightClick;
if (document.layers) window.captureEvents(Event.MOUSEDOWN);
if (document.layers) window.captureEvents(Event.MOUSEUP);
window.onmousedown = rightClick;
window.onmouseup = rightClick;

function Scroller(container)
{
	this.elements = {
		viewport: $(".thumb-images", container),
		scroller: $("#scrollTable", container),
		images: $(".thumb-images img", container),
		next: $("a.next", container),
		previous: $("a.previous", container)
	};

	this.direction = 1;
	this.margin = 0;
	this.minMargin = this.getMinimumMargin();
	this.timer = null;
	this.attachEventHandlers();
}

Scroller.prototype.attachEventHandlers = function()
{
	var $this = this;
	this.elements.next
		.bind("mouseover", function() { $this.start(1); })
		.bind("mouseout", function() { $this.stop(); });
	this.elements.previous
		.bind("mouseover", function() { $this.start(-1); })
		.bind("mouseout", function() { $this.stop(); });
	this.elements.viewport
		.bind("mousemove", function(e) { $this.scrollViewport(e); })
		.bind("mouseout", function(e) { $this.scrollViewport(e); });
};

Scroller.prototype.getMinimumMargin = function()
{
	var width = this.elements.viewport.width() - this.elements.scroller.width();
	return width < 0 ? width : 0;
}

Scroller.prototype.start = function(direction)
{
	if (null === this.timer)
	{
		var $this = this;
		this.direction = direction;
		this.timer = setInterval(function() { $this.scroll(); }, 25);
	}
};

Scroller.prototype.stop = function()
{
	if (null !== this.timer)
	{
		clearInterval(this.timer);
		this.timer = null;
	}
};

Scroller.prototype.scrollViewport = function(e)
{
	// scroll if the mouse is positioned in a margin at the left
	// or right side of the viewport.
	var offset = (e.clientX - this.elements.viewport.offset().left);
	var width = this.elements.viewport.width();
	var margin = 32;

	if (0 <= offset && offset <= margin)
	{
		this.start(-1);
	}
	else if (width - margin <= offset && offset <= width)
	{
		this.start(1);
	}
	else
	{
		this.stop();
	}
}

Scroller.prototype.scroll = function()
{
	this.margin -= this.direction * 5; // move 10px
	if (this.margin < this.minMargin)
	{
		this.margin = this.minMargin;
		this.stop();
	}
	else if (0 < this.margin)
	{
		this.margin = 0;
		this.stop();
	}
	this.elements.scroller.css("margin-left", this.margin);
};

Scroller.setPicture = function(src)
{
	var preloader = new Image();
	preloader.onload = function()
	{
		$("#imageview img").attr("src", src);
	};
	preloader.src = src;
}

Scroller.instances = [];
Scroller.setup = function()
{
	var container = $(".thumbs");
	if (0 != container.length)
	{
		var scroller = new Scroller(container);
		Scroller.instances[Scroller.instances.length] = scroller;
	}
};

$(document).ready(Scroller.setup);