/* if user is using IE6 offer Google Chrome */
if(!window.XMLHttpRequest) { alert('Your browser is obsolete. Click OK to download Google Chrome, a faster and safer browser.'); window.location = 'http://www.google.com/chrome/'; }

function sendComment() {
  $('#commentform').submit();
}
function validateContactForm() {
  var ok = true;
  $.each($('.required-field'), function() {
    if($(this).val() == '') {
      ok = false;
      $(this).css({'border':'#c00 solid 1px'});
    } else {
      $(this).css({'border':'0'});
    }
  });
  if(ok) {
    return true;
  } else {
    $('#contact-error').fadeIn();
  }
  return false;
}


function initializeGoogleMaps(gLat, gLng) {
  if(gLat == undefined || gLng == undefined) {
    var gLat = 51.190098;
    var gLng = 5.9974175;
  }
  var latlng = new google.maps.LatLng(gLat, gLng);
  var myOptions = {
    zoom:zoom,
    center:latlng,
    navigationControl:true,
    mapTypeControl:false,
    scaleControl:false,
    mapTypeId:google.maps.MapTypeId.ROADMAP
  };
  var map = new google.maps.Map(document.getElementById('googlemaps'), myOptions);
  var marker = new google.maps.Marker({
      position:latlng,
      map:map,
      icon:'http://www.google.com/intl/en_us/mapfiles/ms/micons/orange-dot.png'
  });
}

$(document).ready(function() {

  
  /* Center the logo vertically */
  if($('#logo a img').length > 0) {
    $('#logo a img').css({'margin':((110 - $('#logo a img').height()) / 2) + 'px 0 0 0'});
  }
  
  


  
  /* Blog category image hover */
  if($('.hoverimg').length > 0) {
    if(!$.browser.opera) {
      $('.hoverimg').hover(function() {
        $(this).stop(true, true).animate({'opacity':'.7'}, {queue:false, duration:300, easing:'easeOutCubic'});
      }, function() {
        $(this).stop(true, true).animate({'opacity':'1'}, {queue:false, duration:200, easing:'easeOutCubic'});
      });
    }
  }
  
 
  
  
 
  
  /* Footer */
  $('#footer a').css({'opacity':0.7});
  $('#footer a').hover(function() {
    $(this).stop(true, true).animate({'opacity':1}, {queue:false, duration:500, easing:'easeOutCubic'});
    Cufon.replace('#footer a', {hover:true});
  }, function() {
    $(this).stop(true, true).animate({'opacity':.7}, {queue:false, duration:1500, easing:'easeOutCubic'});
    Cufon.replace('#footer a', {hover:false});
  });
});

/* Background-position animate fix by Alexander Farkas */
(function($) {
	if(!document.defaultView || !document.defaultView.getComputedStyle){ // IE6-IE8
		var oldCurCSS = jQuery.curCSS;
		jQuery.curCSS = function(elem, name, force){
			if(name === 'background-position'){
				name = 'backgroundPosition';
			}
			if(name !== 'backgroundPosition' || !elem.currentStyle || elem.currentStyle[ name ]){
				return oldCurCSS.apply(this, arguments);
			}
			var style = elem.style;
			if ( !force && style && style[ name ] ){
				return style[ name ];
			}
			return oldCurCSS(elem, 'backgroundPositionX', force) +' '+ oldCurCSS(elem, 'backgroundPositionY', force);
		};
	}
	
	var oldAnim = $.fn.animate;
	$.fn.animate = function(prop){
		if('background-position' in prop){
			prop.backgroundPosition = prop['background-position'];
			delete prop['background-position'];
		}
		if('backgroundPosition' in prop){
			prop.backgroundPosition = '('+ prop.backgroundPosition;
		}
		return oldAnim.apply(this, arguments);
	};
	
	function toArray(strg){
		strg = strg.replace(/left|top/g,'0px');
		strg = strg.replace(/right|bottom/g,'100%');
		strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,'$1px$2');
		var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
		return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
	}
	
	$.fx.step. backgroundPosition = function(fx) {
		if (!fx.bgPosReady) {
			var start = $.curCSS(fx.elem,'backgroundPosition');
			
			if(!start){//FF2 no inline-style fallback
				start = '0px 0px';
			}
			
			start = toArray(start);
			
			fx.start = [start[0],start[2]];
			
			var end = toArray(fx.options.curAnim.backgroundPosition);
			fx.end = [end[0],end[2]];
			
			fx.unit = [end[1],end[3]];
			fx.bgPosReady = true;
		}
		//return;
		

	};
})(jQuery);
