//get basepath
var site_base = (window.location.hostname)? window.location.hostname : window.location.host;
site_base = "http://"+site_base;

var prev 	= 0;
var num 	= 0;

String.prototype.lpad = function (size,PaddingCharacter) {
  var dif = size - this.length ;
  var s = this;

  if (dif > 0) {
    for (;dif!=0;dif+=-1) { s = PaddingCharacter + s;}
  }
  return(s);
}

function popup(url,w,h,scroll)
{
  var l = (screen.width-w)/2;
  var t = (screen.height-h)/2;

  window.open(url,'_blank','resizable=yes,location=no,menubar=no,scrollbars='+scroll+',status=no,toolbar=no,fullscreen=no,dependent=no,width='+w+',height='+h+',left='+l+',top='+t);
}

var secondsleft = 0;
var lasttime = "000000000";

var lastactive = null;
window.addEvent('domready', function()
{
    var frontpage_block_height = 0;
    var frontpage_blocks = $$('.frontpage_block_content');
    frontpage_blocks.each(function(el)
    {
        var current_height = el.getSize().y;
        if (current_height > frontpage_block_height)
        {
            frontpage_block_height = current_height;
        }
    });
    
    if (frontpage_block_height > 0)
    {
        frontpage_block_height = frontpage_block_height - frontpage_blocks[0].getStyle('padding-bottom').toInt() - frontpage_blocks[0].getStyle('padding-top').toInt();
        frontpage_blocks.each(function(el)
        {
            el.setStyle('height', frontpage_block_height);
        });
    }
    
    var obj = new Swiff(site_base+'/resources/media/tagcloud.swf', {
        id: 'tagcloud',
        width: 269,
        height: 179,
        container: 'wpcumulus',
        vars: { 
            //xmlpath:    site_base+'/resources/media/tagcloud.xml.php',
            tagcloud:   "<tags><a href='http://forum.newventure.nl/index.php?board=18' style='font-size:15pt;' target='_blank'>Businessplan</a><a href='http://forum.newventure.nl/index.php?board=26' style='font-size:15pt;' target='_blank'>Innovatie</a><a href='http://forum.newventure.nl/index.php?board=18' style='font-size:15pt;' target='_blank'>Ondernemingsplan</a><a href='http://forum.newventure.nl/index.php?board=26' style='font-size:14pt;' target='_blank'>Bedrijfsideeën</a><a href='http://forum.newventure.nl/index.php?board=41' style='font-size:14pt;' target='_blank'>Intellectueel Eigendom</a><a href='http://forum.newventure.nl/index.php?board=14' style='font-size:14pt;' target='_blank'>Marketing</a><a href='http://forum.newventure.nl/index.php?board=15' style='font-size:14pt;' target='_blank'>Financiering</a><a href='http://forum.newventure.nl/index.php?board=28' style='font-size:13pt;' target='_blank'>Logistiek</a><a href='http://forum.newventure.nl/index.php?board=49' style='font-size:13pt;' target='_blank'>Fiscale zaken</a><a href='http://forum.newventure.nl/index.php?board=51' style='font-size:13pt;' target='_blank'>Mediazaken</a><a href='http://forum.newventure.nl/index.php?board=16' style='font-size:13pt;' target='_blank'>Administratie</a><a href='http://forum.newventure.nl/index.php?board=3' style='font-size:12pt;' target='_blank'>Automatisering</a><a href='http://forum.newventure.nl/index.php?board=48' style='font-size:12pt;' target='_blank'>Arbeidsrecht</a><a href='http://forum.newventure.nl/index.php?board=41' style='font-size:12pt;' target='_blank'>Merknamen</a><a href='http://forum.newventure.nl/index.php?board=41' style='font-size:12pt;' target='_blank'>Auteursrechten</a><a href='http://forum.newventure.nl/index.php?board=46' style='font-size:11pt;' target='_blank'>Algemene voorwaarden</a><a href='http://forum.newventure.nl/index.php?board=41' style='font-size:11pt;' target='_blank'>Octrooien</a><a href='http://forum.newventure.nl/index.php?board=41' style='font-size:11pt;' target='_blank'>Patenten</a><a href='http://forum.newventure.nl/index.php?board=41' style='font-size:11pt;' target='_blank'>Licenties</a><a href='http://forum.newventure.nl/index.php?board=41' style='font-size:10pt;' target='_blank'>Geheimhouding</a><a href='http://forum.newventure.nl/index.php?board=47' style='font-size:10pt;' target='_blank'>Rechtsvormen</a><a href='http://forum.newventure.nl/index.php?board=47' style='font-size:10pt;' target='_blank'>Eenmanszaak</a><a href='http://forum.newventure.nl/index.php?board=47' style='font-size:10pt;' target='_blank'>BV</a><a href='http://forum.newventure.nl/index.php?board=50' style='font-size:9pt;' target='_blank'>KvK</a><a href='http://forum.newventure.nl/index.php?board=44' style='font-size:9pt;' target='_blank'>Internationaal ondernemen</a><a href='http://forum.newventure.nl/index.php?board=45' style='font-size:9pt;' target='_blank'>Leiderschap</a><a href='http://forum.newventure.nl/index.php?board=23' style='font-size:9pt;' target='_blank'>Life Sciences</a><a href='http://forum.newventure.nl/index.php?board=20' style='font-size:8pt;' target='_blank'>Wedstrijden</a><a href='http://forum.newventure.nl/index.php?board=20' style='font-size:8pt;' target='_blank'>Beurzen en evementen</a></tags>",
            tcolor:     '0x000000',
            tcolor2:    '0x000000',
            hicolor:    '0xc3bf01',
            bgcolor:    '0xffffff',
            speed:      '100',
            trans:      'false',
            distr:      'true',
            args:       '',
            compmode:   'false',
            showwptags: 'false',
            mode:       'tags'
        }
    });
	
	if ($('frontpage_banner'))
	{
		var container	= $('frontpage_banner');
		var images 		= $('frontpage_banner').getElements('img');

		num = $random(0, images.length-1);
		images.each(function(el, i)
		{
			el.set('tween', {duration: 2000}); 
			if (num == i)
			{
				el.fade('show');
			}
			else
			{
				el.fade('hide');
			}
		});
		
		if (images.length > 1)
		{
			(function() { rotate_banners(images); }).periodical(10000);
		}
	}
	
	function rotate_banners(images)
	{
		prev = num;
		while (num == prev)
		{
			num = $random(0, images.length-1);
		}
		images[prev].fade('out');
		images[num].fade('in');
	}
	
    if ($('partners_horizontal'))
    {
		var itemsVisible = 5;
		if ($('partners_horizontal').getParent().id == 'border_scroller')
		{
			itemsVisible = 4;
		}

        new SlideItMoo({overallContainer: 'partners_horizontal',
                        elementScrolled: 'partners_horizontal_inner',
                        thumbsContainer: 'partners_horizontal_items',		
                        itemsVisible:itemsVisible,
                        itemsSelector: '.partner',
                        showControls:0,
                        autoSlide: 2000,
                        transition: Fx.Transitions.Sine.easeOut,
                        duration: 4000,
                        direction:-1});					
    }
    
    if ($('partners_vertical'))
    { 
        new SlideItMooVertical({overallContainer: 'partners_vertical',
                        elementScrolled: 'partners_vertical_inner',
                        thumbsContainer: 'partners_vertical_items',		
                        itemsVisible:4,
                        itemsSelector: '.partner',
                        showControls:0,
                        autoSlide: 2000,
                        transition: Fx.Transitions.Sine.easeOut,
                        duration: 4000,
                        direction:-1});					
    }
    
    
    if($("timer") && $("starttime"))
    {
        secondsleft = parseInt($("starttime").get('html'));

        $("timercontainer").set('html',
         "<span id='time0'>0</span><span id='time1'>0</span><span id='time2'>0</span><span class='smalltime'>:</span>"
        +"<span id='time3'>0</span><span id='time4'>0</span><span class='smalltime'>:</span>"
        +"<span id='time5'>0</span><span id='time6'>0</span><span class='smalltime'>:</span>"
        +"<span id='time7'>0</span><span id='time8'>0</span>"
        );
        
        clockTick();
    }
    
    if($('nav')){$('nav').getElements('li').each(function(el){el.addEvents({mouseenter: function(e){el.addClass('iehover')},mouseleave: function(e){el.removeClass('iehover')}});});}
    $$('.subnav').each(function(sn){sn.getElements('li').each(function(el){el.addEvents({mouseenter: function(e){el.addClass('iehover')},mouseleave: function(e){el.removeClass('iehover')}});});});
});
function el_fadein(el, delay)
{
    var delay = delay || 0;
    var delay2 = (delay == 0)? 0 : delay*2;
    (function(){el.addClass('iehover')}).delay(delay);
    (function(){el.target.fade('in')}).delay(delay2);
}
function el_fadeout(el, delay)
{
    var delay = delay || 0;
    var delay2 = (delay == 0)? 400 : delay*2;
    (function(){el.target.fade('out')}).delay(delay);
    (function(){el.removeClass('iehover');}).delay(delay2);
}


/*** Timer ***/

function clockTick()
{
  var d,h,m,s,t;

  s = secondsleft;
  d = Math.floor(s/86400); s%=86400;
  h = Math.floor(s/3600);  s%=3600;
  m = Math.floor(s/60);    s%=60;
    
  d = d.toString().lpad(3,"0");
  h = h.toString().lpad(2,"0");
  m = m.toString().lpad(2,"0");
  s = s.toString().lpad(2,"0");

  var time = d+h+m+s;

  for(var i=0;i<=8;i++)
  {
    slideController(i,time);
  }

  lasttime = time;

  secondsleft--;
  setTimeout("clockTick()",1000);
}

function slideController(pos,curtime)
{
  if(lasttime!="")
  {
    var now = curtime.charAt(pos);
    var lst = lasttime.charAt(pos);
    
    obj = $('time'+pos);
    
    if(now!=lst)
    {
      slideTick(pos,0);
    }
    
    obj.set('html', lst+"<br />"+now);
  }
}

function slideTick(i,cnt)
{
  $('time'+i).style.marginTop = "-"+cnt+"px";
  cnt+=2;
  if(cnt<=24)
  {
    setTimeout("slideTick("+i+","+cnt+")",20);
  }
}

/********/


/**
Vertical slider
**/
var SlideItMooVertical = new Class({
	
	Implements: [Options],
	options: {
		overallContainer: null,
		elementScrolled: null,
		thumbsContainer: null,		
		itemsVisible:5,
		elemsSlide: null,
		itemsSelector: null,
		itemHeight: null,
		showControls:1,
		transition: Fx.Transitions.linear,
		duration: 800,
		direction: 1,
		autoSlide: false,
		mouseWheelNav: false
	},
	
	initialize: function(options){
		this.setOptions(options);
		/* all elements are identified on CSS selector (itemsSelector) */
		this.elements = $(this.options.thumbsContainer).getElements(this.options.itemsSelector);
		this.totalElements = this.elements.length;
		if( this.totalElements <= this.options.itemsVisible ) return;
		// width of thumbsContainer children
		this.elementHeight = this.options.itemHeight || this.elements[0].getSize().y;
		this.currentElement = 0;
		this.direction = this.options.direction;
		this.autoSlideTotal = this.options.autoSlide + this.options.duration;
        this.begin();
	},
		
	begin: function(){	
		// resizes the container div's according to the number of itemsVisible thumbnails
		this.setContainersSize();
		
		this.myFx = new Fx.Morph(this.options.thumbsContainer, { 
			wait: true, 
			transition: this.options.transition,
			duration: this.options.duration
		});		
				
		/* if navigation is needed and enabled, add it */
		this.addControls();
		/* if autoSlide is not set, scoll on mouse wheel */
		if( this.options.mouseWheelNav && !this.options.autoSlide ){
			$(this.options.thumbsContainer).addEvent('mousewheel', function(ev){
				new Event(ev).stop();
				this.slide(-ev.wheel);								
			}.bind(this));
		}
		
		if( this.options.autoSlide )
			this.startAutoSlide();		
	},
	
	setContainersSize: function(){
		$(this.options.overallContainer).set({
			styles:{
				'height': this.options.itemsVisible * this.elementHeight + 50 * this.options.showControls
			}
		});
		$(this.options.elementScrolled).set({
			styles:{
				'height': this.options.itemsVisible * this.elementHeight
			}
		});
		$(this.options.thumbsContainer).set({
			styles:{
				'height': this.totalElements * (this.elementHeight + 10)	
			}
		});
	},
	
	addControls: function(){
		if( !this.options.showControls ) return;
		
		this.fwd = new Element('div', {
			'class': 'SlideItMoo_forward',
			'events':{
				'click':this.slide.pass(1, this)
			}
		});
		this.bkwd = new Element('div', {
			'class': 'SlideItMoo_back',
			'events':{
				'click': this.slide.pass(-1, this)
			}
		});
		$(this.options.overallContainer).adopt(this.fwd, this.bkwd);		
	},
	
	slide: function( direction ){
		
		if(this.started) return;
		this.direction = direction;
		var currentIndex = this.currentIndex();
		
		if( this.options.elemsSlide && this.options.elemsSlide>1 && this.endingElem==null ){
			this.endingElem = this.currentElement;			
			for(var i = 0; i < this.options.elemsSlide; i++ ){
				this.endingElem += direction;
				if( this.endingElem >= this.totalElements ) this.endingElem = 0;
				if( this.endingElem < 0 ) this.endingElem = this.totalElements-1;
			}
		}	
		
		if( this.direction == -1 ){
			this.rearange();
			$(this.options.thumbsContainer).setStyle('margin-top', -this.elementHeight);			
		}
		this.started = true;
		this.myFx.start({ 
			'margin-top': this.direction == 1 ? -this.elementHeight : 0 
		}).chain( function(){			
			this.rearange(true);			
			if(this.options.elemsSlide){
				if( this.endingElem !== this.currentElement ) this.slide(this.direction);
				else this.endingElem=null;	
			}
		}.bind(this)  );
	},
	
	rearange: function( rerun ){
		
		if(rerun) this.started = false;
		if( rerun && this.direction == -1 ) {
			return;
		}
		this.currentElement = this.currentIndex( this.direction );
		//$('debug').innerHTML+= this.currentElement+'<br>';
		
		$(this.options.thumbsContainer).setStyle('margin-top',0);
		
		if( this.currentElement == 1 && this.direction == 1 ){
			this.elements[0].injectAfter(this.elements[this.totalElements-1]);
			return;
		}
		if( (this.currentElement == 0 && this.direction ==1) || (this.direction==-1 && this.currentElement == this.totalElements-1) ){
			this.rearrangeElement( this.elements.getLast(), this.direction == 1 ? this.elements[this.totalElements-2] : this.elements[0]);
			return;
		}
		
		if( this.direction == 1 ){
			this.rearrangeElement( this.elements[this.currentElement-1], this.elements[this.currentElement-2]);
		}
		else{
			this.rearrangeElement( this.elements[this.currentElement], this.elements[this.currentElement+1]);
		}		
	},
	
	rearrangeElement: function( element , indicator ){
		this.direction == 1 ? element.injectAfter(indicator) : element.injectBefore(indicator);
	},
	
	currentIndex: function(){
		var elemIndex = null;
		switch( this.direction ){
			/* forward */
			case 1:
				elemIndex = this.currentElement >= this.totalElements-1 ? 0 : this.currentElement + this.direction;				
			break;
			/* backwards */
			case -1:
				elemIndex = this.currentElement == 0 ? this.totalElements - 1 : this.currentElement + this.direction;
			break;
		}
		return elemIndex;
	},
	
	startAutoSlide: function(){
		this.startIt = this.slide.bind(this).pass(this.direction||1);
		this.autoSlide = this.startIt.periodical(this.autoSlideTotal, this);
		this.elements.addEvents({
			'mouseover':function(){
				$clear(this.autoSlide);						
			}.bind(this),
			'mouseout':function(){
				this.autoSlide = this.startIt.periodical(this.autoSlideTotal, this);
			}.bind(this)
		})
	}
})







/**
	SlideItMoo v1.1 - Image slider
	(c) 2007-2008 Constantin Boiangiu <http://www.php-help.ro>
	MIT-style license.
	
	Changes from version 1.0
	- added continuous navigation
	- changed the navigation from Fx.Scroll to Fx.Morph
	- added new parameters: itemsSelector: pass the CSS class for divs
	- itemWidth: for elements with margin/padding pass their width including margin/padding
	
	Updates ( August 4'th 2009 )
	- added new parameter 'elemsSlide'. When this is set to a value lower that the actual number of elements in HTML, it will slide at once that number of elements when navigation clicked. Default: null
**/
var SlideItMoo = new Class({
	
	Implements: [Options],
	options: {
		overallContainer: null,
		elementScrolled: null,
		thumbsContainer: null,		
		itemsVisible:5,
		elemsSlide: null,
		itemsSelector: null,
		itemWidth: null,
		showControls:1,
		transition: Fx.Transitions.linear,
		duration: 800,
		direction: 1,
		autoSlide: false,
		mouseWheelNav: false
	},
	
	initialize: function(options){
		this.setOptions(options);
		/* all elements are identified on CSS selector (itemsSelector) */
		this.elements = $(this.options.thumbsContainer).getElements(this.options.itemsSelector);
		this.totalElements = this.elements.length;
		if( this.totalElements <= this.options.itemsVisible ) return;
		// width of thumbsContainer children
		this.elementWidth = this.options.itemWidth || this.elements[0].getSize().x;
		this.currentElement = 0;
		this.direction = this.options.direction;
		this.autoSlideTotal = this.options.autoSlide + this.options.duration;
		this.begin();
	},
		
	begin: function(){	
		// resizes the container div's according to the number of itemsVisible thumbnails
		this.setContainersSize();
		
		this.myFx = new Fx.Morph(this.options.thumbsContainer, { 
			wait: true, 
			transition: this.options.transition,
			duration: this.options.duration
		});		
				
		/* if navigation is needed and enabled, add it */
		this.addControls();
		/* if autoSlide is not set, scoll on mouse wheel */
		if( this.options.mouseWheelNav && !this.options.autoSlide ){
			$(this.options.thumbsContainer).addEvent('mousewheel', function(ev){
				new Event(ev).stop();
				this.slide(-ev.wheel);								
			}.bind(this));
		}
		
		if( this.options.autoSlide )
			this.startAutoSlide();		
	},
	
	setContainersSize: function(){
		$(this.options.overallContainer).set({
			styles:{
				'width': this.options.itemsVisible * this.elementWidth + 50 * this.options.showControls
			}
		});
		$(this.options.elementScrolled).set({
			styles:{
				'width': this.options.itemsVisible * this.elementWidth
			}
		});
		$(this.options.thumbsContainer).set({
			styles:{
				'width': this.totalElements * (this.elementWidth + 10)	
			}
		});
	},
	
	addControls: function(){
		if( !this.options.showControls ) return;
		
		this.fwd = new Element('div', {
			'class': 'SlideItMoo_forward',
			'events':{
				'click':this.slide.pass(1, this)
			}
		});
		this.bkwd = new Element('div', {
			'class': 'SlideItMoo_back',
			'events':{
				'click': this.slide.pass(-1, this)
			}
		});
		$(this.options.overallContainer).adopt(this.fwd, this.bkwd);		
	},
	
	slide: function( direction ){
		
		if(this.started) return;
		this.direction = direction;
		var currentIndex = this.currentIndex();
		
		if( this.options.elemsSlide && this.options.elemsSlide>1 && this.endingElem==null ){
			this.endingElem = this.currentElement;			
			for(var i = 0; i < this.options.elemsSlide; i++ ){
				this.endingElem += direction;
				if( this.endingElem >= this.totalElements ) this.endingElem = 0;
				if( this.endingElem < 0 ) this.endingElem = this.totalElements-1;
			}
		}	
		
		if( this.direction == -1 ){
			this.rearange();
			$(this.options.thumbsContainer).setStyle('margin-left', -this.elementWidth);			
		}
		this.started = true;
		this.myFx.start({ 
			'margin-left': this.direction == 1 ? -this.elementWidth : 0 
		}).chain( function(){			
			this.rearange(true);			
			if(this.options.elemsSlide){
				if( this.endingElem !== this.currentElement ) this.slide(this.direction);
				else this.endingElem=null;	
			}
		}.bind(this)  );
	},
	
	rearange: function( rerun ){
		
		if(rerun) this.started = false;
		if( rerun && this.direction == -1 ) {
			return;
		}
		this.currentElement = this.currentIndex( this.direction );
		//$('debug').innerHTML+= this.currentElement+'<br>';
		
		$(this.options.thumbsContainer).setStyle('margin-left',0);
		
		if( this.currentElement == 1 && this.direction == 1 ){
			this.elements[0].injectAfter(this.elements[this.totalElements-1]);
			return;
		}
		if( (this.currentElement == 0 && this.direction ==1) || (this.direction==-1 && this.currentElement == this.totalElements-1) ){
			this.rearrangeElement( this.elements.getLast(), this.direction == 1 ? this.elements[this.totalElements-2] : this.elements[0]);
			return;
		}
		
		if( this.direction == 1 ){
			this.rearrangeElement( this.elements[this.currentElement-1], this.elements[this.currentElement-2]);
		}
		else{
			this.rearrangeElement( this.elements[this.currentElement], this.elements[this.currentElement+1]);
		}		
	},
	
	rearrangeElement: function( element , indicator ){
		this.direction == 1 ? element.injectAfter(indicator) : element.injectBefore(indicator);
	},
	
	currentIndex: function(){
		var elemIndex = null;
		switch( this.direction ){
			/* forward */
			case 1:
				elemIndex = this.currentElement >= this.totalElements-1 ? 0 : this.currentElement + this.direction;				
			break;
			/* backwards */
			case -1:
				elemIndex = this.currentElement == 0 ? this.totalElements - 1 : this.currentElement + this.direction;
			break;
		}
		return elemIndex;
	},
	
	startAutoSlide: function(){
		this.startIt = this.slide.bind(this).pass(this.direction||1);
		this.autoSlide = this.startIt.periodical(this.autoSlideTotal, this);
		this.elements.addEvents({
			'mouseover':function(){
				$clear(this.autoSlide);						
			}.bind(this),
			'mouseout':function(){
				this.autoSlide = this.startIt.periodical(this.autoSlideTotal, this);
			}.bind(this)
		})
	}
})