$().ready(function(){

	$("#sidenav ul").parent().addClass('hide_corner');
	
	$("#sidenav ul li.selected a").wrapInner('<span>');

	$(".zoom-img img").after("<div class='zoom-icon'></div>");
	$(".zoom-img").fancybox({
								'padding': 0,
								'overlayOpacity' : 0
	});
	
	$("ul.blocks li").equalHeights();
	
	$("input#email_subscribe_text").focus(function(){
	
		 $(this).animate({backgroundPosition: '-55px 11px'});
	
	});
	
	$("input#email_subscribe_text").blur(function(){
	
		 $(this).animate({backgroundPosition: '10px 11px'});
	
	});
	
	$("#slideshow").cycle({
		fx: 'fade',
		pager:  '#slideshow_pages',
		timeout: 8000,
		prev:   '#slideshow_prev', 
    	next:   '#slideshow_next'    
	});

	var $width = $("#client_block").outerWidth()
	var $leftover =  Math.round((940 - $width) / 2);
	
	$("#client_block").css("margin-left", $leftover + "px");
	
	console.log($leftover);
	
	$('#header .container li a, #sidenav ul li.selected a span, #email_subscribe_btn, #search_button').corner();
	

});

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent(function() {
 
 $(".zoom-img").each(function(){
	
	var $img = $(this).find('img');
	var $width = $($img).outerWidth();
	var $height = $($img).outerHeight();
	
	$(this).width($width);
	$(this).height($height);
	
});
 
});


function applyShadow(targetElement, shadowColor, shadowOffset) {
  if (typeof(targetElement) != 'object') {
    targetElement = document.getElementById(targetElement);
  }
  var value = targetElement.firstChild.nodeValue;
  targetElement.style.position = 'relative';
  targetElement.style.zIndex = 1;
    
  var newEl = document.createElement('span');
  newEl.appendChild(document.createTextNode(value));
  newEl.className = 'shadowed';
  newEl.style.color = shadowColor;
  newEl.style.position = 'absolute';
  newEl.style.left = shadowOffset + 'px';
  newEl.style.top = shadowOffset + 'px';
  newEl.style.zIndex = -1;
  
  targetElement.appendChild(newEl);
}
