function thisMovie(movieName) {
 if (navigator.appName.indexOf("Microsoft") != -1) {
  return window[movieName]
 }
 else {
  return document[movieName]
 }
}

function rgb2hex(str) {
 if (str.substr(0, 1) == '#')
 {
  return str.substring(1);
 }
 
 var rgb = str.match(/\d+/g);
 if (rgb == null)
  rgb = 'FFFFFF';
 //generates the hex-digits for a colour.
 function hex (x) {
  hexDigits = new Array("0", "1", "2", "3", "4", "5", "6", "7", "8","9", "A", "B", "C", "D", "E", "F");
  return hexDigits[(x - x % 16) / 16] + hexDigits[x% 16];
 }
 return hex(rgb[0]) + hex(rgb[1]) + hex(rgb[2]);
}

$(document).ready(function () {

 $('div#mainmenuWrapper ul li').each(function (i)
 {
  var ahref = $(this).children('a').attr('href');
  $(this).click(function () {
   location.href = ahref;
  });
 });
 
 $('div#mainmenuWrapper ul li:not(.active)').hover(function () {
  if (thisMovie($(this).children('object').attr('id')).changeColor != undefined)
   thisMovie($(this).children('object').attr('id')).changeColor('0x142071');
 }, function () {
  if (thisMovie($(this).children('object').attr('id')).changeColor != undefined)
   thisMovie($(this).children('object').attr('id')).changeColor('0xFFFFFF');
 });
 
 $('div#mainmenuWrapper ul li a, h1').each(function (i)
 {
  var flashTextId = 'flashText_' + i;
  if ($(this).attr('id') == '')
   $(this).attr('id', flashTextId)
  else
   var flashTextId       = $(this).attr('id');
   var href              = $(this).attr('href');
 	 var flashvars         = {};
 	 flashvars.containerId = flashTextId;
   flashvars.titleText   = $.trim($(this).text());
 	 flashvars.color       = '0x' + rgb2hex($(this).css('color'));
 	 var fontsize = $(this).css('font-size');
 	 flashvars.fontsize    = Math.floor(fontsize.substr(0, fontsize.length - 2));
 	 if (href != undefined)
    flashvars.link      = href;
   else
    flashvars.link      = '';
   var params     = {};
   params.wmode   = "transparent";
   params.salign  = "tl";
   var attributes = {};
   
   swfobject.embedSWF("/swf/flashtext.swf", flashTextId, "560", "21", "6","/swf/expressInstall.swf", flashvars, params, attributes);
 });
 
 $('div#submenuWrapper ul li').append('<div class="shadowRight">&nbsp;</div>' +
                                      '<div class="shadowBottom">&nbsp;</div>' +
                                      '<div class="shadowCorner">&nbsp;</div>');
 $("#contactformulier").validate({
  messages: {
   naam: "Vul uw naam in",
   bericht: "Vul een bericht in",
   email: {
    required: "Vul uw e-mailadres in",
    email: "Uw emailadres dient deze vorm te hebben: email@domein.nl"
   }
  }
 });
 
 $('#googlemapsinput').click(function () {
  if ($(this).val() == 'Voorbeeld: Garderenseweg 5 Ermelo')
   $(this).val('');
 });
 
 $('#googlemapsinput').blur(function () {
  if ($(this).val() == '')
   $(this).val('Voorbeeld: Garderenseweg 5 Ermelo');
 });
 
 $('#header').click(function(){
 	location.href = '/html/nl/1/Home';
 });
});

/**
 * Deze functie wordt aangeroepen vanuit /swf/title.swf
 * en stelt de hoogte in van het flash-object, deze hoogte
 * is gelijk aan de hoogte van het textField in title.swf
 */
function setDimensions(containerId, textHeight, textWidth)
{
 $('#' + containerId).attr('width',  textWidth);
 $('#' + containerId).attr('height', textHeight);
 //console.log(containerId + ': textHoogte: ' + textHeight + ', textBreedte: ' + textWidth);
}