// Hide typekit fonts until rendered through typekit
TypekitConfig = {
  kitId: 'vfx4bdq',
  scriptTimeout: 3000
};
(function() {
  var h = document.getElementsByTagName('html')[0];
  h.className += ' wf-loading';
  var t = setTimeout(function() {
    h.className = h.className.replace(/(\s|^)wf-loading(\s|$)/g, '');
    h.className += ' wf-inactive';
  }, TypekitConfig.scriptTimeout);
  var tk = document.createElement('script');
  tk.src = '//use.typekit.com/' + TypekitConfig.kitId + '.js';
  tk.type = 'text/javascript';
  tk.async = 'true';
  tk.onload = tk.onreadystatechange = function() {
    var rs = this.readyState;
    if (rs && rs != 'complete' && rs != 'loaded') return;
    clearTimeout(t);
    try { Typekit.load(TypekitConfig); } catch (e) {}
  };
  var s = document.getElementsByTagName('script')[0];
  s.parentNode.insertBefore(tk, s);
})();


$(document).ready(function(){

// Fix for animated png issues in IE
var i;
for (i in document.images) {
    if (document.images[i].src) {
        var imgSrc = document.images[i].src;
        if (imgSrc.substr(imgSrc.length-4) === '.png' || imgSrc.substr(imgSrc.length-4) === '.PNG') {
            document.images[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true',sizingMethod='crop',src='" + imgSrc + "')";
        }
    }
}

// Social and logo rollovers
$("#socials li, #logo").mouseover(function () {
$(this).stop(true, true).animate({bottom: "2px"}, "fast");
});

$("#socials li, #logo").mouseleave(function () {
$(this).stop(true, true).animate({bottom: "0px"}, "fast");
});


// Homepage slider tab controller
$.featureList2(
$("#slider-tab2 h3"),
$("#slider-control div"), {
    start_item	:	0
}
);

// Case study controller
$.featureList(
$("#case-pager li"),
$("#case-study ul.case"), {
    start_item	:	0,
    transition_interval : 8000
}
);

// Wrap all internal page images and grab longdesc if exists and use for caption
$("#internal .content img").each(function() {
	if ($(this).css('float') == 'left'){
		$(this).wrap('<div class="image-wrapper float-left">');
		var attr = $(this).attr("longdesc");
		if (typeof attr !== 'undefined' && attr !== false) {
		$('<div class="caption"><p>' + attr + '</p></div>').insertAfter(this);
		}
	} else if ($(this).css('vertical-align') == 'top' || $(this).css('vertical-align') == 'middle' || $(this).css('vertical-align') == 'bottom'){
		$(this).wrap('<div class="image-wrapper center">');
		var attr = $(this).attr("longdesc");
		if (typeof attr !== 'undefined' && attr !== false) {
		$('<div class="caption"><p>' + attr + '</p></div>').insertAfter(this);
		}
	}
	
	else {
		$(this).wrap('<div class="image-wrapper">');
		var attr = $(this).attr("longdesc");
		if (typeof attr !== 'undefined' && attr !== false) {
		$('<div class="caption"><p>' + attr + '</p></div>').insertAfter(this);
		}
	}
});

$(".photogallery img").each(function() {
$(this).unwrap('<div class="image-wrapper">');
});

$(".photogallery a").fancybox({
'titlePosition'	:	'inside'
});



/*
$('.image-wrapper').each(function(index) {
    if ($('.image-wrapper img').css('float') == 'left')
		{
   			$(this).parent().addClass('float-left');
		}
});
*/

// Add class to checkboxes
$('input:checkbox').addClass("checkbox");
$('input:radio').addClass("radio");

// Add an asterisk to all required form labels
$('form label.required').append("<span class='ast'>*</span>");

// Input and textarea field value (disappear and re-appear)
$('input:not(.formsubmit), textarea').each(function() {
    var default_value = this.value;
    $(this).focus(function() {
        if(this.value == default_value) {
            this.value = '';
            $(this).toggleClass("value-color");
        }
    });
    $(this).blur(function() {
        if(this.value == '') {
            this.value = default_value;
            $(this).toggleClass("value-color");
        }
    });
});

// Zebra stripe table rows
$('#internal .content tbody tr:even').addClass('even');

// Adjust sidebar height to match content height
var darkHght = $('.sidebar-dark').height();
var subtractHght = darkHght - 60;
var contentHght = $('.content-wrapper').height();
var newHght = contentHght - subtractHght;
$('.sidebar-light').css('height', newHght);

// Style main nav first list item (can't do in css because of lavalamp navigation)
$('.main-nav li:first').css('border', 'none');

// Lavalamp Navigation (Typekit causes issues with lavalamp in FF only)
/*
if ($('ul.main-nav li.active').length ) {
if ($('ul.main-nav li').hasClass('active')) {
$(this).addClass('selectedLava');
}
$('ul.main-nav').lavaLamp({
	speed: 500,
	returnDelay: 400
});
} else {
$('ul.main-nav').lavaLamp({
	speed: 500,
	homeTop: -50,
	returnDelay: 400
});
}
*/

});
