function slidePoll() {
	$('.pollSpacer').each(function() {
		var id = parseInt($(this).attr('id'));
		$(this).parent().animate({width:id}, 1800, 'swing');
	});
}

$(document).ready(function(){

	$('.back').css({
		cursor:'pointer'
	});
	$('.back').click(function(){
		history.back();
	});
	$('.slideshow').each(function(){
		var data = eval('('+$(this).attr('ssData')+')');
		$('.ssImage').css({visibility:'visible'});
		$(this).cycle(data);
		$(this).height(data.height);
		$(this).width(data.width);
	});

	jQuery('.slideshow img').click(function (){
      document.location.href = jQuery(this).attr('rel');
    }).css('cursor', 'pointer');

	$('.itemMap').each(function(){
		var opts = eval('('+$(this).attr('mapOptions')+')');
		var center = eval('('+opts.center+')');
		var ll = [];
		var llc = 0;
		for(var i in center){
			ll[llc++] = center[i];
		}
		opts.center = new google.maps.LatLng(ll[0],ll[1]);
		opts.zoom = parseFloat(opts.zoom);
		if(opts.draggable !== '1'){
			opts.draggable = '0';
		}
		var el = $(this)[0];
		var markers = [];
		$(this).find('.itemMarker').each(function(){
			markers[markers.length] = {
				data:eval('('+$(this).attr('markerOptions')+')'),
				description:$(this).html()
			};
		});
		var map = null;
		if(el){
			map = new google.maps.Map(el,opts);
		}
		if(map != null && markers.length > 0){
			for(var i = 0; i < markers.length; i++){
				var opts = markers[i].data;
				if(opts.cmsDraggable != undefined){
					opts.draggable = opts.cmsDraggable;
				}
				if(opts.cmsClickable != undefined){
					opts.clickable = opts.cmsClickable;
				}
				var position = eval('('+opts.position+')');
				var ll = [];
				var llc = 0;
				for(var j in position){
					ll[llc++] = position[j];
				}
				opts.position = new google.maps.LatLng(ll[0],ll[1]);
				opts.map = map;
				opts.icon = new google.maps.MarkerImage('http://www.woerden.tv/images/marker_sprite.png', new google.maps.Size(29,34,'px','px'));
				opts.shadow = new google.maps.MarkerImage('http://www.woerden.tv/images/marker_sprite_shadow.png', new google.maps.Size(50,34,'px','px'),new google.maps.Point(6,0));
				var m = new google.maps.Marker(opts);
				if(markers[i].description != ''){
					var w = new google.maps.InfoWindow({
						content:markers[i].description,
						position:opts.position
					});
					w.open(map);
					google.maps.event.addListener(m, 'click', function(e){
						w.open(map);
					});
				}
			}
		}
	});

	$('.googleMap').each(function(){
		var opts = eval('('+$(this).attr('mapOptions')+')');
		var center = eval('('+opts.center+')');
		var ll = [];
		var llc = 0;
		for(var i in center){
			ll[llc++] = center[i];
		}
		opts.center = new google.maps.LatLng(ll[0],ll[1]);
		opts.zoom = parseFloat(opts.zoom);
		var el = document.getElementById($(this).attr('id'));
		// Markers ophalen
		var markers = [];
		$(this).find('.marker').each(function(){
			markers[markers.length] = {
				data:eval('('+$(this).attr('markerOptions')+')'),
				description:$(this).html()
			}
		});
		var map = null;
		if(el){
			map = new google.maps.Map(el,opts);
		}
		if(map != null && markers.length > 0){
			for(var i = 0; i < markers.length; i++){
				var opts = markers[i].data;
				if(opts.cmsDraggable != undefined){
					opts.draggable = opts.cmsDraggable;
				}
				if(opts.cmsClickable != undefined){
					opts.clickable = opts.cmsClickable;
				}
				var position = eval('('+opts.position+')');
				var ll = [];
				var llc = 0;
				for(var i in position){
					ll[llc++] = position[i];
				}
				opts.position = new google.maps.LatLng(ll[0],ll[1]);
				opts.map = map;
				var m = new google.maps.Marker(opts);
				if(markers[i].description != ''){
					var w = new google.maps.InfoWindow({
						content:markers[i].description,
						position:opts.position
					});
					w.open(map);
					google.maps.event.addListener(m, 'click', function(e){
						w.open(map);
					});
				}
			}
		}
	});

	function setPreview(id){
		$('#previewList ul li').removeClass('active');
		$('#previewLink_'+id).parent().addClass('active');
		$('#previewImage img').css({zIndex:1});
		$('#previewImage_'+id).css({zIndex:2});
		$('#previewTitle').html($('#previewLink_'+id).attr('iname'));
		$('#previewInfo').html('Bijdrage van:'+$('#previewLink_'+id).attr('iauthor'));
	}
	$('#previewList ul li a').mouseover(function(){
		var id = parseInt(this.id.split('_').pop());
		setPreview(id);
		return false;
	});

	$('#itemMask').click(function(){
		var data = {
			'ad':$(this).attr('ad'),
			'play':$(this).attr('play')
		}
		var vars = {
			youtubeId:data.play
		}
		var params = {
			quality:'high',
			bgcolor:'#ffffff',
			allowscriptaccess:'sameDomain',
			allowfullscreen:'true'
		}
		var attributes = {
			id:'LucasPlayer',
			name:'LucasPlayer',
			align:'middle'			
		}
		if(typeof data.ad != 'undefined'){
			vars.ad = '../../../uploadedfiles/ads/'+data.ad;			
		}
		swfobject.embedSWF('../../customer/plugins/tv/player/LucasPlayer.swf', 'itemImage', '465', '260', '10.1.0', '../../customer/plugins/tv/player/playerProductInstall.swf',vars, params, attributes);
		
		
	});
	$('body').css({
		backgroundColor:'#ffffff',
		backgroundImage:'url("/images/bg_body.jpg")',
		backgroundRepeat:'repeat-x'
	});
	$('#buttonPlay').mouseover(function() {
		this.src = '/images/play_hover.png';
	});
	$('#buttonPlay').mouseout(function() {
		this.src = '/images/play.png';
	});

	slidePoll();

	$('#mask,#errors').click(function(){
		$('#mask,#errors').remove();
	});

	$('#main h1').first().each(function(){
		$(this).css({
			'float':'left'
		});
	});

	//$('#username').focus(function(){
	//	if($(this).val() == 'Inlognaam'){
	//		$(this).val('');
	//	}
	//});

	//$('#username').blur(function(){
	//	if($(this).val() == ''){
	//		$(this).val('Inlognaam');
	//	}
	//});

	function togglePassword(){
		$('#password').focus(function(){
			if($(this).attr('type') == 'text'){
				var i = $('<input></input>');
				i.attr('id', 'password');
				i.attr('type', 'password');
				i.attr('value', '');
				i.attr('name', 'password');
				$(this).replaceWith(i);
				setTimeout(function(){
					$('#password').focus();
				},1);
				togglePassword();
			}
		});
		$('#password').blur(function(){
			if($(this).attr('type') == 'password'){
				if($(this).val() == ''){
					var i = $('<input></input>');
					i.attr('id', 'password');
					i.attr('type', 'text');
					i.attr('value', 'Wachtwoord');
					i.attr('name', 'password');
					$(this).replaceWith(i);
					togglePassword();
				}
			}
		});
	}
	
	//togglePassword();

	function initCheckbox(){
		$('.checkbox').click(function(){
			$(this).addClass('checkboxChecked');
			$(this).removeClass('checkbox');
			var i = $('#'+$(this).attr('CBID'));
			i.attr('checked',true);
			initCheckbox();
		});

		$('.checkboxError').click(function(){
			$(this).addClass('checkboxChecked');
			$(this).removeClass('checkboxError');
			$('#'+$(this).attr('CBID')).attr('checked',true);
			initCheckbox();
		});

		$('.checkboxChecked').click(function(){
			$(this).addClass('checkbox');
			$(this).removeClass('checkboxChecked');
			$('#'+$(this).attr('CBID')).attr('checked',false);
			initCheckbox();
		});
	}
	var year = new Date().getFullYear();
	$('.datePickerInput').datepicker({
		dateFormat:'dd-mm-yy',
		maxDate:0,
		showAnim:'slide',
		showOtherMonths:true,
		selectOtherMonths:true,
		changeYear:true,
		defaultDate:0,
		yearRange:'1900:'+year
	});

	$('.datePickerInputSelect').datepicker({
		dateFormat:'dd-mm-yy',
		minDate:0,
		maxDate:null,
		showAnim:'slide',
		showOtherMonths:true,
		selectOtherMonths:true,
		changeYear:true,
		defaultDate:0,
		yearRange:year+':'+(year+1)
	});

	initCheckbox();

	

	$('#gallery').galleria({
        width:470,
        /*height:360,*/
		height:390,
		transition:'pulse',
		image_crop: false

	});
	
	/*$('#gallery').galleryView({
		panel_width: 480,
		frame_width: 90,
		pause_on_hover: true,
		show_overlays: true,
		after:function(){
			$('.gv-panel img').each(function(){
				var a = $('<a></a>');
				a.attr('href', $(this).attr('src'));
				a.click(function(){
					fb.start($(this)[0]);
					return false;
				});
				var img = $(this).clone();
				img.appendTo(a);
				$(this).replaceWith(a);
			});
		}
	});*/

	$("a[rel=evenement]").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
		}
	});

});

var http;
var browser = navigator.appName;
if ( browser == 'Microsoft Internet Explorer' )
	http = new ActiveXObject("Microsoft.XMLHTTP");
else
	http = new XMLHttpRequest();

function loadPage(pagina, album, maxrows, paginas, ipr){
	http.open('get', '/customer/gallery.php?pagina='+pagina+'&album='+album+'&rijen='+maxrows+'&paginas='+paginas+'&ipr='+ipr); 
	http.onreadystatechange = handleResponseAlbum; 
	http.send(null);	
}


function handleResponseAlbum()
{	
	if(http.readyState == 4 && http.status == 200)
	{ 
		if(http.responseText) { 
			document.getElementById('newGallery').innerHTML = http.responseText; 		
			$("a[rel=evenement]").fancybox({
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'titlePosition' 	: 'over',
				'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
					return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
				}
			});
			//Maak floatbox mogelijk na de ajaxrequest
			//fb.anchors.length = 0;
			//fb.tagAnchors(document);
			//Einde Floatbox fix
		}
		
	} else if(http.readyState == 4 && http.status == 404) { 
	  document.getElementById('newGallery').innerHTML = "HTTP ERROR 404: <br /><br />Page not found"; 
	} 
} 


function showDiv(naam){
	if(document.getElementById(naam).style.display == 'none'){
		document.getElementById(naam).style.display='block';
	}else{
		document.getElementById(naam).style.display='none';
	}
}

