/* jQuery plugins */
/**
* jQuery.ScrollTo - Easy element scrolling using jQuery.
* Copyright (c) 2008 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
* Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
* and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
* Date: 2/19/2008
* @author Ariel Flesler
* @version 1.3.3
*/
;(function($){var o=$.scrollTo=function(a,b,c){o.window().scrollTo(a,b,c)};o.defaults={axis:'y',duration:1};o.window=function(){return $($.browser.safari?'body':'html')};$.fn.scrollTo=function(l,m,n){if(typeof m=='object'){n=m;m=0}n=$.extend({},o.defaults,n);m=m||n.speed||n.duration;n.queue=n.queue&&n.axis.length>1;if(n.queue)m/=2;n.offset=j(n.offset);n.over=j(n.over);return this.each(function(){var a=this,b=$(a),t=l,c,d={},w=b.is('html,body');switch(typeof t){case'number':case'string':if(/^([+-]=)?\d+(px)?$/.test(t)){t=j(t);break}t=$(t,this);case'object':if(t.is||t.style)c=(t=$(t)).offset()}$.each(n.axis.split(''),function(i,f){var P=f=='x'?'Left':'Top',p=P.toLowerCase(),k='scroll'+P,e=a[k],D=f=='x'?'Width':'Height';if(c){d[k]=c[p]+(w?0:e-b.offset()[p]);if(n.margin){d[k]-=parseInt(t.css('margin'+P))||0;d[k]-=parseInt(t.css('border'+P+'Width'))||0}d[k]+=n.offset[p]||0;if(n.over[p])d[k]+=t[D.toLowerCase()]()*n.over[p]}else d[k]=t[p];if(/^\d+$/.test(d[k]))d[k]=d[k]<=0?0:Math.min(d[k],h(D));if(!i&&n.queue){if(e!=d[k])g(n.onAfterFirst);delete d[k]}});g(n.onAfter);function g(a){b.animate(d,m,n.easing,a&&function(){a.call(this,l)})};function h(D){var b=w?$.browser.opera?document.body:document.documentElement:a;return b['scroll'+D]-b['client'+D]}})};function j(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);

/* Some variables */
var vars = {
 'services': {
  'show': 'Toon alleen de hoofddiensten',
  'hide': 'Uitbreidingen en extra diensten'
 },
 'addRemove': {
  'add': 'Voeg toe',
  'remove': 'Verwijder'
 },
 'GMap': {
  'txt': '<strong>FrenzyMedia b.v.</strong><br />Wateringweg 131<br />2031 EG  Haarlem<br />Tel: 023 - 54 27 111',
  'map': null,
  'marker': null,
  'gdir': null
 }
};



/* Once the DOM is loaded, let jQuery do some magic */
$(function() {


	// Let CSS know we have JS turned on
	$('body').addClass('js');

	// Make the menu a bit more fancy by polluting the DOM
 	$('#nav-main span').wrap('<span></span>').after('<i></i>');

 	// Same pollution for our sections
	$('div.section:not(:first), #portfolio, #portfolio .item, #portfolio .details').append('<div class="top"></div>');


	

	// And some stuff for the portfolio items, which is only needed when JS is on
	$('#portfolio h2').each(function() {
		$(this).next().prepend('<p class="desc">' + $(this).text() + '</p>');
 });

 // The forms on the contact page
 $('#formulier').hide();
 $('#continue-to-form').click(function() {
  if ($('#directions').is(':visible')) {
   $('#directions').slideUp(function() {
    $('#formulier').slideDown(function() {
     $.scrollTo('#formulier', {offset: {top: -50}, duration: 500});
    });
   });
  } else {
   $('#formulier').slideToggle(function() {
    $.scrollTo('#continue-to-form', {offset: {top: -50}, duration: 500});
   });
  };
  return false;
 });

 // Google Maps and directions
 $('#directions').hide();
 if ($('#google-maps').length && typeof(GBrowserIsCompatible) == 'function' && GBrowserIsCompatible()) {
  var element = $('#google-maps').addClass('google-maps-styled');
  vars.GMap.map = new GMap2(element[0]);
  vars.GMap.map.addControl(new GLargeMapControl());
  vars.GMap.map.addControl(new GMapTypeControl());
  vars.GMap.map.setCenter(new GLatLng(52.397174, 4.657098), 13);
  vars.GMap.marker = new GMarker(vars.GMap.map.getCenter());
  GEvent.addListener(vars.GMap.marker, 'click', function() {vars.GMap.marker.openInfoWindowHtml(vars.GMap.txt)});
  vars.GMap.map.addOverlay(vars.GMap.marker);
  vars.GMap.marker.openInfoWindowHtml(vars.GMap.txt);
  vars.GMap.gdir = new GDirections(vars.GMap.map, $('#directions')[0]);
  GEvent.addListener(vars.GMap.gdir, 'error', function() {
   var msg = 'Uw opdracht kon niet worden uitgevoerd.';
   switch (vars.GMap.gdir.getStatus().code) {
    case G_GEO_UNKNOWN_ADDRESS:
     msg = 'Geen adresgegevens gevonden.';
     break;
    case G_GEO_MISSING_QUERY:
     msg = 'Geen adresgegevens opgegeven.';
     break;
    case G_GEO_SERVER_ERROR:
    case G_GEO_BAD_KEY:
    case G_GEO_BAD_REQUEST:
     msg = 'Algemene fout bij ophalen van routebeschrijving. Excuses voor het ongemak.';
     break;
   }
   $('#directions').html('<div class="top"></div><p><strong class="error">' + msg + '</strong></p>');
  });
  $('#show-directions').submit(function() {
   if (!vars.GMap.gdir) return false;
   var from = $('#street').val() + ' ' + $('#house').val() + ' ' + $('#place').val() + ' ' + $('#country').val();
   if ($.trim(from) != '') {
    $('#formulier:visible').slideUp();
    $('#directions').hide().html('<div class="top"></div>');
    vars.GMap.gdir.load('from:' + from + ' to: Wateringweg 131, 2031 EG, Haarlem, Nederland', {locale: 'nl'});
    $.scrollTo($('#directions').slideDown(), {duration: 1000});
   };
   return false;
  });
 }
 
 
 
 
  
 

 // On the calculator page toggle between main- and subservices
 $('#services-switch a').toggle(function() {
  $('#more-services').show();
  $.scrollTo('#more-services', {offset: {top: -50}, duration: 500});
  
	  if (pageLabel == "action"){
	  		$(this).text("Toon alleen de hoofddiensten");	
	  }else{
	  	    $(this).text("Toon alleen de hoofddiensten");
	  }
   
 // $(this).text(vars.services.show);
  return false;
 }, function() {
  $.scrollTo('#prices', {duration: 500, onAfter: function() {
   $('#more-services').hide();
  }});
  	
	  if (pageLabel == "action"){
	  		$(this).text("Klik hier voor de extra webshop uitbreidingen");	
	  }else{
	  	    $(this).text("Uitbreidingen en extra diensten");
	  }
  return false;
 });

 // The add/remove buttons for the calculator page

	$('.add-remove label').toggle(
	
		function() {
	
			
			if (typeof $(this).attr('id') != 'undefined') {
		
				if (typeof SystionHoofdItem != 'undefined') {
				
					SystionHoofdItem.removeClass('remove').attr('title', vars.addRemove.add).parent().next().animate(
						{'textIndent': '-250px'}, 
						'fast', 
		  				function() {
		   					SystionHoofdItem.next().next().animate(
		   						{'textIndent': '-250px'}, 
		   						'fast', 
		   						function() {
							    	calculateTotals();
							   	}
							).removeClass('added');
							
		  				}
		  			).removeClass('added');
		  			
		 			SystionHoofdItem.attr('checked', false);
					SystionHoofdItem.attr('title', vars.addRemove.add).parent().next().css('text-indent', '-250px').next().next().css('text-indent', '-250px');
		 
		 			SystionHoofdItem.click();
		
				 			
				}
				
				SystionHoofdItem = $(this);
				
			}
			
			
			
			$(this).addClass('remove').attr('title', vars.addRemove.remove).parent().next().animate({'textIndent': 0}, 'fast', 
				function() {
					
	   				$(this).next().next().animate({'textIndent': 0}, 'fast', function() {
	   				
			    			calculateTotals();
			   			}).addClass('added');
	  		}).addClass('added');
	
			$('#' + $(this).attr('for')).attr('checked', true);
	 	}
	 	
	 	,	
	 	
	 	function() {
 	
  			$(this).removeClass('remove').attr('title', vars.addRemove.add).parent().next().animate({'textIndent': '-250px'}, 'fast', 
  				function() {
   					$(this).next().next().animate({'textIndent': '-250px'}, 'fast', 
   						function() {
					    	calculateTotals();
					   	}
					).removeClass('added');
  				}).removeClass('added');
 				$('#' + $(this).attr('for')).attr('checked', false);
		}).attr('title', vars.addRemove.add).parent().next().css('text-indent', '-250px').next().next().css('text-indent', '-250px');
 
 
 			$('#prices :checked').prev('label').click();

 			$('#more-services').hide();

 			// The forms for the calculator page
 			$('#continue a').click(function() {
  			var forms = {
			  '#offerte-aanvragen': '#laat-u-bellen',
			  '#laat-u-bellen': '#offerte-aanvragen'
 			};
 			
  			var clicked = $(this).attr('href');
 			
 			if ($(forms[clicked]).is(':visible')) {
   				$(forms[clicked]).slideUp(
   					function() {
    					$(clicked).slideToggle(function() {
     					$.scrollTo('#continue', {offset: {top: -50}, duration: 500});
    				});
   				});
  			} else {
   				$(clicked).slideToggle(
   					function() {
    					$.scrollTo('#continue', {offset: {top: -50}, duration: 500});
  					});
  			};
  		
  			return false;
 		}
 	);

 // Loop through all cells that are activated, and calculate the total
 function calculateTotals() {
  var totalStart = totalMonthly = 0;
  $('.costs-start.added[abbr]').each(function() {
   totalStart += parseInt($(this).attr('abbr'));
  });
  $('.costs-monthly.added[abbr]').each(function() {
   totalMonthly += parseInt($(this).attr('abbr'));
  });
  $('#total-costs-start strong').text('€ ' + number_format(totalStart, 0, ',', '.') + ',-');
  $('#total-costs-monthly strong').text('€ ' + number_format(totalMonthly, 0, ',', '.') + ',-');
 }

 function number_format(a, b, c, d) {
  a = Math.round(a * Math.pow(10, b)) / Math.pow(10, b), e = a + '', f = e.split('.');
  if (!f[0]) { f[0] = '0'; }
  if (!f[1]) { f[1] = ''; }
  if (f[1].length < b) {
   g = f[1];
   for (i=f[1].length + 1; i <= b; i++) { g += '0'; }
   f[1] = g;
  }
  if(d != '' && f[0].length > 3) {
   h = f[0];
   f[0] = '';
   for(j = 3; j < h.length; j+=3) {
    i = h.slice(h.length - j, h.length - j + 3);
    f[0] = d + i +  f[0] + '';
   }
   j = h.substr(0, (h.length % 3 == 0) ? 3 : (h.length % 3));
   f[0] = j + f[0];
  }
  c = (b <= 0) ? '' : c;
  return f[0] + c + f[1];
 }

 if ($.browser.msie && $.browser.version == 6) {
  $('#portfolio .item').hover(function() {
   $(this).addClass('item-hover');
  }, function() {
   $(this).removeClass('item-hover');
  });
 };

});


    






/* Some sIFR stuff */
var font = {
 src: '/js_sources/sifr3.swf'
};
sIFR.activate(font);
sIFR.replace(font, {
 'selector': 'h1, div.section h2, #main-services th strong',
 'css': {
  '.sIFR-root': {
   'color': '#0192dc'
  }
 },
 'wmode': 'transparent'
});

