var init_specific='';

function init() {
	init_formfields();
	init_poll();
	
	jQuery('#photoalbum a').nvsAlbum({
			overlayBackground: 		'#044775',
			overlayTransparancy: 	0.6,
			overlaySpeed:			500,
			popUpBackground:		'#fff',
			imageBtnPrev:			'/pix/nvsalbum_nav-left.gif',
			imageBtnNext:			'/pix/nvsalbum_nav-right.gif',
			imageBtnClose:			'/pix/nvsalbum_nav-close.gif'
	});
	
	if (window.init_weer) {
		init_weer();
	}
	
	if (window.init_vertrekkers) {
		init_vertrekkers();
	}
	
	enable_active_object();
//    eval(init_specific);
	var players = document.getElementsByClassName('im_player');
	for (var i = 0; i < players.length; ++i) {
		//alert(players[i].id);
		var video_key = players[i].id.replace('player_', '');
		im_player(video_key, players[i].title);
	}
	
	// image_rotator
	var img_rotator = document.getElementById('image_rotator');
	if(img_rotator){
		runPortal();
	}
	
	if (window.hide_selects_on_navigation) {
		hide_selects_on_navigation();
	}
}

function im_player_old(video_key, autostart) {
	var im_player = new SWFObject("http://st.ilsemedia.nl/video/smm_player.swf?instance="+(Math.floor(Math.random()*100000+1)),"single","480","270","8","#000000");
	im_player.addParam("allowfullscreen","true");
	im_player.addParam("allowScriptAccess", "always");
	im_player.addParam("quality","high");
	im_player.addParam("wmode", "transparent");
	im_player.addVariable("width","480");
	im_player.addVariable("height","270");
	im_player.addVariable("backcolor","0xFFFFFF");
	im_player.addVariable("frontcolor","0x000000");
	im_player.addVariable("showdigits","true");
	im_player.addVariable("autostart","true");
	if (autostart=='autostart0') {
		im_player.addVariable("autostart_preroll","false");
	} else {
		im_player.addVariable("autostart_preroll","true");
	}
	im_player.addVariable("button_playsmall","http://st.ilsemedia.nl/video/smm/button_playsmall.swf");
	im_player.addVariable("preroll","http://ad.doubleclick.net/pfadx/P4442.Zeilen.nl/preroll;sz=640x360");
	im_player.addVariable("preroll_overstretch","true");
	im_player.addVariable("ad_img_url","http://st.ilsemedia.nl/video/smm/preroll.png");
	im_player.addVariable("file","http://zeilen.smm.bin.ilsemedia.nl/m/" + video_key + ".flv");
	im_player.addVariable("button_playbig","http://www.zeilen.nl/pix/playbutton_big.png");
	im_player.addVariable("image","http://zeilen.smm.bin.ilsemedia.nl/m/" + video_key + "_p.jpg");
	im_player.write(video_key);
}

function im_player(video_key, autostart) {
	var s1 = new SWFObject("http://videoplayer.ilsemedia.nl/video/smm/2.1/im_player.swf?instance=" + ( Math.floor ( Math.random ( ) * 100000 + 1 ) ),"ply","480","290","9","#000000");
	s1.addParam("allowfullscreen","true");
	s1.addParam("allowscriptaccess","always");
	s1.addParam("wmode", "transparent");
	s1.addVariable("width","480"); 
	s1.addVariable("height","290"); 
	if (autostart!='autostart0') {
		s1.addVariable("autostart","true");
	} else {
		s1.addVariable("autostart","false");
	}
	s1.addVariable("backcolor","#F0F0F0");
	s1.addVariable("frontcolor","#000000");
	s1.addVariable("file","http://zeilen.smm.bin.ilsemedia.nl/m/" + video_key + ".flv");
	s1.addVariable("image","http://zeilen.smm.bin.ilsemedia.nl/m/" + video_key + "_p.jpg");
	
	//VIDEOSTRIP
	s1.addVariable("puid","23940510"); 
	s1.addVariable("categories","default");
	
	
	//PLUGINS
	s1.addVariable("plugins","http://assets.videostrip.com/plugins/JWPlayer4/AdMatcherClient.swf");
	
	s1.write("player_" + video_key);

}

var searchFieldstr;
function init_formfields() {
	searchFieldstr = document.getElementById('searchfield').value;
	document.getElementById('searchfield').onfocus = function() { 
		if(this.value == searchFieldstr) { this.value = '' }
	}
	document.getElementById('searchfield').onblur = function() { 
		if(this.value == '' ) { this.value = searchFieldstr }
	}	

}

/* short generic onload by Brothercake */
if(typeof window.addEventListener != 'undefined') {
	window.addEventListener('load', init, false);
} else if(typeof document.addEventListener != 'undefined') {
	document.addEventListener('load', init, false);
} else if(typeof window.attachEvent != 'undefined') {
	window.attachEvent('onload', init);
}

/*
* Nieuwsbrief 
*/

function nieuwsbrief_aanmelden() {
	var form = document.getElementById('nieuwsbrief_aanmeld_form');
	var email = form.nieuwsbrief_email;
	var valid = /^.*?((?:[\w.-])+\@(?:(?:[\w-])+\.)+(?:[\w]{2,5}))$/.test(email.value);
	
	if(!valid || email.value=='') {
		email.style.backgroundColor = '#da0000';
		email.style.color = '#ffffff';
	} else {
		form.submit();
	}
}

var poll_ajax;

function init_poll() {
	var i = 0;
	while(document.getElementById('polloption'+ i)) {
		document.getElementById('polloption'+ i).onclick = function () { vote(this); } 
		document.getElementById('polloption'+ i).onmouseover = function () { this.style.cursor= 'pointer'; } 
		i++;
	}
}

function save_vote(pollId) {
  pollchoice=document.getElementById('pollChoice').value;
  if(pollchoice) {
    poll_ajax = ajax_Request ('/ajax/poll.php?id='+pollId+'&choice='+pollchoice, vote_saved);
  }
}

function vote_saved() {
  if (!poll_ajax) poll_ajax = req;
	if (poll_ajax.readyState == 4 && poll_ajax.status == 200) {
		// Hiding options
    var i = 0;
	  while(document.getElementById('polloption'+ i)) {
	   document.getElementById('polloption'+ i).style.display='none';
	   i++;
    }
    // Hiding vote button
    document.getElementById('vote_button').style.display='none';
    
    // Resultaten verwerken
    var result=String(poll_ajax.responseText).split('|');
    for(i=0;i<result.length;i++) {
      var item=String(result[i]).split(':');
      var pollresult = document.getElementById('pollresult'+ item[0]);
      if(pollresult) {
        pollresult.innerHTML=item[1];
      }
    }
		poll_ajax = null;
	  return false;
  }
}

function vote(obj) 
{
	var url = obj.src;
	var state = url.substr(url.lastIndexOf('.') - 1, 1);
	newstate = state ^ 1;	
	
	var i = 0;
	while(document.getElementById('polloption'+ i)) {
	 	url = document.getElementById('polloption'+ i).src;
		document.getElementById('polloption'+ i).src = url.substr(0, url.lastIndexOf('.') - 1) + 0 + url.substr(url.lastIndexOf('.'));
		i++;
	}
	
	if(newstate == 1) {
		pollchoice = obj.id.substr(10, obj.id.length);
	} else {
		pollchoice = '';
	}
	
	obj.src = url.substr(0, url.lastIndexOf('.') - 1) + newstate + url.substr(url.lastIndexOf('.'));
	document.getElementById('pollChoice').value = pollchoice;
	
}

/*
* SOME GENERAL FUNCTIONS
*/



function cancelEventBubble(event) {
	if (event.stopPropagation) {
		event.stopPropagation ();
		event.preventDefault ();
	} else if (event.cancelBubble) {
		event.cancelBubble = true;
		event.returnValue = false;
	}	
}
_ScreenSize = { y: 0, x : 0}	
	
function _get_screensize() {
	if (typeof window.innerHeight != 'undefined') {
		_ScreenSize['y'] = window.innerHeight; 
		_ScreenSize['x'] = window.innerWidth;
	}
	else if (typeof document.body != 'undefined') {
		_ScreenSize['y'] = document.body.clientHeight;
		_ScreenSize['x'] = document.body.clientWidth;
	}
}

/*
* Agenda functions
*/

function maand_up() {
	if(parseInt(document.getElementById('maandkeuzecontent').style.top) < 0) {
		document.getElementById('maandkeuzecontent').style.top = (parseInt(document.getElementById('maandkeuzecontent').style.top) + 20) + 'px';
	}
}

function maand_down() {
	if(parseInt(document.getElementById('maandkeuzecontent').style.top) > - 400) {
		document.getElementById('maandkeuzecontent').style.top = (parseInt(document.getElementById('maandkeuzecontent').style.top) - 20) + 'px';
	}
}

/*
 * Functies voor weer blok
 */

function show_locations() {
	var parent_obj = document.getElementById('homelocationbox');
	var obj = document.getElementById('homelocationinnerbox');
	
	if(parent_obj.style.display == 'none') {
		parent_obj.style.display = 'block';
		obj.style.left = 509;
		new Effect.MoveBy('homelocationinnerbox', 0, -509);
	} else {
		obj.style.left = 0;
		new Effect.MoveBy('homelocationinnerbox', 0, 509, { afterFinish: function(obj) { parent_obj.style.display = 'none'; } } );
	}
} 

function switch_location_tabs() {
	var tab_binnenwater = document.getElementById('forecast_binnenwater');
	var tab_buitenwater = document.getElementById('forecast_buitenwater');
	
	var cl_binnenwater = String(tab_binnenwater.className).split(' ');
	var cl_buitenwater = String(tab_buitenwater.className).split(' ');
	
	if(cl_binnenwater.length<3) {
		tab_binnenwater.className+= ' selected';
		tab_buitenwater.className = cl_buitenwater[0]+' '+cl_buitenwater[1];
		tab_binnenwater.onclick = null;
		tab_buitenwater.onclick = function() { switch_location_tabs(); }
		document.getElementById('locations_binnenwater').style.display = 'block';
		document.getElementById('locations_buitenwater').style.display = 'none';
	
		get_weather(tab_binnenwater.getAttribute('default_location'))
	} else {
		tab_binnenwater.className = cl_binnenwater[0]+' '+cl_binnenwater[1];
		tab_buitenwater.className+= ' selected';
		tab_binnenwater.onclick = function() { switch_location_tabs(); };
		tab_buitenwater.onclick = null;
		document.getElementById('locations_binnenwater').style.display = 'none';
		document.getElementById('locations_buitenwater').style.display = 'block';
		
		get_weather(tab_buitenwater.getAttribute('default_location'))
	}
}

function laad_video(video_key, target_id) {
	var handlerFunc = function(t) {
		im_player(video_key);
	}
	
	new Ajax.Updater(target_id, '/ajax/geef_videoplayer.php', { parameters: { v: video_key }, evalScripts: true, onComplete: handlerFunc });
}

function laad_title(title, target_id, preview) {
	new Ajax.Updater(target_id, '/ajax/geef_videotitle.php', { parameters: { video_title: title, preview: preview }, evalScripts: true }) ;
}
