/* SVN $Id: main.js 96 2009-05-08 14:09:24Z jeroen $ */
/* SVN $URL: file:///T:/SOURCE_SVN/Start_Website/httpdocs/js/main.js $ */

/*############################################################################*/
/*# Initialize */
    
function Main_Initialize()
{
  var oForm = WHITE_GetElementFlex('search');
  if ('object' == typeof oForm)
  {
    WHITE_InitFieldExplanation('searchfield', '(Zoekterm)');
    WHITE_AddEvent(oForm, 'submit', WHITE_FormRemoveEplanationsEvent);
  }
  
  initDesc();
  openCloseDiv();
  initCarousel();
  animateGraph();
  setVideo();
  showHandShake();
    
  $(".contact_link").fancybox({
    'autoDimensions'	: false,
    'autoScale'				: false,
    'width'           : 489,
    'height'          : 400,
    'transitionIn'		: 'none',
    'transitionOut'		: 'none',
    'type'						: 'iframe',
    'showCloseButton' : true,
    'titleShow' 			: false,
    'padding'					: 0,
    'scrolling'       : 'no'
  });
  
  $(".email_link").fancybox({
    'autoDimensions'	: false,
    'autoScale'				: false,
    'width'           : 489,
    'height'          : 321,
    'transitionIn'		: 'none',
    'transitionOut'		: 'none',
    'type'						: 'iframe',
    'showCloseButton' : true,
    'titleShow' 			: false,
    'padding'					: 0,
    'scrolling'       : 'no'
  });
  
  $(".offer_link").fancybox({
    'autoDimensions'	: false,
    'autoScale'				: false,
    'width'           : 489,
    'height'          : 321,
    'transitionIn'		: 'none',
    'transitionOut'		: 'none',
    'type'						: 'iframe',
    'showCloseButton' : true,
    'titleShow' 			: false,
    'padding'					: 0,
    'scrolling'       : 'no'
  });
  
  // show advice form with direct URL link
  var bShowAdviceForm = GetUrlParameter('saf');
  if (bShowAdviceForm)
  {
    $(document).ready(function() {
      $(".advice_link").trigger('click');
    });
  }
  
  // show advice form with direct URL link
  var bShowAdviceForm = GetUrlParameter('spf');
  if (bShowAdviceForm)
  {
    $(document).ready(function() {
      $(".phone_link").trigger('click');
    });
  }
  
  // show advice form with direct URL link
  var bShowAdviceForm = GetUrlParameter('smf');
  if (bShowAdviceForm)
  {
    $(document).ready(function() {
      $(".email_link").trigger('click');
    });
  }
  
  // show advice form with direct URL link
  var bShowOfferForm = GetUrlParameter('sof');
  if (bShowOfferForm)
  {
    $(document).ready(function() {
      $(".offer_link").trigger('click');
    });
  }
}

if ('function' == typeof WHITE_AddBodyLoadFunction)
{
  WHITE_AddBodyLoadFunction(Main_Initialize);
}


/*# /Initialize */
/*############################################################################*/
/*# VIDEO EMBED */

function setVideo(){
  var aFlashVars = {
    file: 'http://www.please.nl/videos/Please_payroll_Helene_v2_608x342.flv',
    image: 'http://www.please.nl/videos/Banner_Payroll_Film_608x342.png',
    autostart:'false',
    displayclick: 'false',
    linktarget: '_blank'
  }

  var aParams = {
    allowfullscreen: 'true',
    wmode: 'opaque'
  }

  swfobject.embedSWF("http://www.please.nl/flash/player.swf", "mediaspace", "608", "362", "9.0.0", "", aFlashVars, aParams);
}

/*# /VIDEO EMBED */
/*############################################################################*/
/*# Show menu description */

function initDesc()
{
  $(".subitem_line").mouseover( function() {
    var itemParent = $(this).parent();
    var itemChild  = $(this).children(".menu_description");
    
    itemChild.show();
    
    var maxY = itemParent.height();
    var minY = itemChild.height();
    var posY = .5 * (maxY - minY);
    
    itemChild.css("top", posY);
    
    var minX = itemParent.position().left;
    var rightX = itemParent.width();
    var leftX = itemChild.width();
    var offsetX = 20;

    if(minX < .5 * $(".doormat_bg").width()) {
      itemChild.css("left", rightX + offsetX);
    }
    else {
      itemChild.css("left", -leftX - offsetX);	
    }
  });

  $(".subitem_line").mouseleave( function() {
    var itemChild = $(this).children(".menu_description");
    itemChild.hide();
  });
}

/*# /Show menu description */
/*############################################################################*/
/*# Show news description */

function openCloseDiv()
{  
  $(".toggle").click( function(){
       
    if($(this).hasClass("selected"))
    {
      $(this).removeClass("selected");
    } else {
      $(".toggle").removeClass("selected");
      $(this).addClass("selected");
    }

  });
}
 
/*# /Show news description */
/*############################################################################*/
/*# Handshake */

function showHandShake()
{
  $('#handshake').mouseenter(function(){
    $('#handshake_text').show();
  });
  
  $('#handshake').mouseleave(function(){
    $('#handshake_text').hide();
  });
}

/*# /Handshake */
/*############################################################################*/
/*# Carousel */

function initCarousel()
{ 
  var itemCurrentID;
  var itemCurrent;
  var itemPrevious;
  var itemLength = $('#rotate_content').children().length;
  var itemTimerLength = 6000;
  var itemAutoScroll = true;
  var itemTimer;
  
  $('#rotatemenu_holder').append('<ul class="rotate_menu" />')
  
  for (var i=0; i<itemLength; i++) {
    $(".rotate_menu").append('<li id="item'+ i +'" class="rotate_menuitem">'+ String(i + 1) + '<\/li>');
  }
  
  showItem(0)
    
  $('li').click(function() {
    unsetTimer()
    var id = Number(($(this).attr('id')).substr(4));
    showItem(id);
    setTimer();
	});
  
  $('.rotate_text').mouseover(function() {
    unsetTimer()
  });
  
  $('.rotate_text').mouseleave(function() {
    setTimer();
  });
  
  function showItem(id) {
  
    if(itemCurrentID != id) {
    
    	$('li').removeClass('rotate_menuitem_on');
      $('#item'+String(id)).addClass('rotate_menuitem_on');
      
           
      if(itemCurrent) {
        itemPrevious = itemCurrent;
        itemPrevious.css("zIndex", 1);
        itemPrevious.animate({left:-290}, 500);  
      }
      
      if(itemPrevious) {
        itemPrevious.animate({left:290}, 0);
      }
      
      itemCurrent = $('#rotate_content').children().eq(id);
      itemCurrentID = id;
    
      itemCurrent.css("zIndex", 2);
      itemCurrent.css("left", 290);
      itemCurrent.animate({left:0}, 500);
    }
  }
  
  function nextItem() {
    
    if(itemCurrentID + 1 >= itemLength) {
      showItem(0);
    }
    else {
      showItem(itemCurrentID + 1);
    }
   
  }

  function setTimer(){
    if(itemAutoScroll){
      itemTimer = setInterval(nextItem, itemTimerLength);
    }
  }
  
  function unsetTimer(){
    if(itemTimer){
      clearInterval(itemTimer);
    }
  }
  
  setTimer();

};

/*# /Carousel */
/*############################################################################*/
/*# SLIDER */

$(function(){
  
  // Slider
  
  $('#slider1').insertAfter($("#amount")).slider({
    range: 'min',
    value: $("#amount").val(),
    min: 1,
    max: 50,
    slide: function(event, ui) {
      $("#amount").val(ui.value);
    }
  });
  
  $('#slider2').insertAfter($("#amount")).slider({
    range: 'min',
    value: $("#amount").val(),
    min: 1,
    max: 15,
    slide: function(event, ui) {
      $("#amount").val(ui.value);
    }
  });

  
  $("#amount").change(function() {
    
    var iNewValue = $("#amount").val();
    
    $("#slider").slider("value", iNewValue);
    $("#slider2").slider("value", iNewValue);
  });
  
  
});
  
/*# /SLIDER */
/*############################################################################*/

function showHideTeamPerson(teamperson)
{
	var aTeamPersons = aTeamPersons = WHITE_GetElementsByClass('employeeholder','employees_sub');
	var oTeamPerson = WHITE_GetElementFlex('employees_sub'+teamperson);
  
	for (var iTP=0; iTP<aTeamPersons.length; iTP++)
	{
		var oTeamPersontmp = WHITE_GetElementFlex(aTeamPersons[iTP].id);
		oTeamPersontmp.style.display = 'none';
	}
	
	if (oTeamPerson)
	{
		oTeamPerson.style.display = 'block';
	}
}

function animateGraph()
{
  var h01 = $('#graph01').height();
  var h02 = $('#graph02').height();
  var h03 = $('#graph03').height();
  var h04 = $('#graph04').height();

  $('.graph_background').height(0)
  
  $('#graph01').animate({height: h01}, 1000);
  $('#graph02').animate({height: h02}, 1000);
  $('#graph03').animate({height: h03}, 1000);
  $('#graph04').animate({height: h04}, 1000);
}

function GetUrlParameter( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}


$('document').ready(function(){
  jwplayer("video").setup({ flashplayer: "http://www.please.nl/flash/player.swf", 'file': "http://www.please.nl/flash/tevreden_klanten.mp4", 'controlbar': "none", 'image': "http://www.please.nl/flash/tevreden_splash_shot.png", 'dock': "none", 'height': 350, 'width': 560 });
});
