﻿/// <reference path="jquery.js"/>
$(document).ready(function () {
	// Adds a class to the body tag so any elements on the page can be styled differently if the browser supports JS
	$("body").addClass("has_js");

	// Calls the addCaption function for left and right aligned images
	addCaption("imgLeft");
	addCaption("imgRight");

	// Career story tab selection
	$("ul.careerStoryMenu>li>a").click(function () {

		//change classes on tabs
		$("ul.careerStoryMenu>li.careerStoryMenuCurrent").removeClass("careerStoryMenuCurrent");
		$(this).parents('li:eq(0)').addClass("careerStoryMenuCurrent");

		//switch content
		$(".csCurrent").hide().removeClass("csCurrent");
		$("#" + $(this).parents('li:eq(0)').attr('id') + "careerstory").show().addClass("csCurrent");

		return false;
	})
	if ($('.tagentry').length > 0)
		$('.tagentry').autocomplete({
			source: '/tags.axd',
			minLength: 2,
			appendTo: '.tagEditor',
			select: function (event, ui) {
				$(this).val(ui.item.label);
				return false;
			},
			focus: function (event, ui) {
				$(this).val(ui.item.label);
				return false;
			}
		});

	$('.commentEdit').click(function () {
		$(this).parents('li:first').toggleClass('editing');
		return false;
	});
	// Social
	var socialEvent = function (socialName) {
		var url = $(this).attr('href');
		if(typeof(pageTracker) !== 'undefined') pageTracker._trackEvent(socialName, userType, location.href);
		window.open(url, 'social', 'toolbar=no,width=550,height=550');
	}
	$("#facebookShare a.social").click(function (e) { socialEvent.apply(this, ['Facebook']); e.preventDefault(); });
	$("#twitterShare a.social").click(function (e) { socialEvent.apply(this, ['Twitter']); e.preventDefault(); });
	$("#linkedinShare a.social").click(function (e) { socialEvent.apply(this, ['Linked In']); e.preventDefault(); });
	$("#deliciousShare a.social").click(function (e) { socialEvent.apply(this, ['Delicious']); e.preventDefault(); });
	$("#mailUtil a.social").click(function (e) { socialEvent.apply(this, ['Email']); e.preventDefault(); });

	$('.track').click(function () {
		var url = $(this).attr('href');
		pageTracker._trackEvent('Links', 'Click', url);
	});
});

$(window).load(function () {
    // Auto scrolling to content
    $('html:has(body.skipToContent),body.skipToContent').each(function () {
        $(this).scrollTop($('#content').offset().top);
    });
});

// Fix IE6 image flashing problem
try {
  document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}

function toggle_filter(anchor)
{
	var filters = document.getElementById('more-filters');
	if (filters.style.display != 'none')
	{
		filters.style.display = 'none';
		if (anchor)
		{
			anchor.className = '';
			anchor.innerHTML = '<span>See more...</span>';
		}
	}
	else
	{
		filters.style.display = 'block';
		if (anchor)
		{
			anchor.className = 'alt';
			anchor.innerHTML = '<span>See less...</span>';
		}
	}
	return false;
}

// Convert external links
this.blankwin = function(){
	var hostname = window.location.hostname;
	hostname = hostname.replace("www.","").toLowerCase();
	var a = document.getElementsByTagName("a");
	this.check = function(obj){
	    try {
		    var href = obj.href.toLowerCase();
		    return ((href.indexOf("http")!=-1 && href.indexOf(hostname)==-1) || href.indexOf("relatedlink.html")!=-1) ? true : false;
		} catch(err) {
		    return false;
		}
	};
	this.set = function(obj){
		obj.target = "_blank";
		//obj.className = "external";
	};
	for (var i=0;i<a.length;i++){
		if(check(a[i])) set(a[i]);
	};
	
};
window.onload = blankwin;

function fade(fadeLevel,itemId)
{
    var item = document.getElementById(itemId);
    if (fadeLevel==1 && item.offsetHeight)
    {
	    item.style.height = (item.offsetHeight - 14) + 'px';
	    item.style.width = (item.offsetWidth -26) + 'px';
    }
    fadeLevel *= 0.8;
    changeOpac(fadeLevel,itemId);
    if (fadeLevel < 0.05)
	{
		item.style.display='none';
	}
	else
	{
 		setTimeout('fade(' + fadeLevel + ',"' + itemId + '");',100);
	}
}

var shrinkItem;
function shrink(itemId,init)
{
    if (!shrinkItem)
        shrinkItem = document.getElementById(itemId); 
    shrinkItem.style.overflow='hidden';
    if(init)
    {
        shrinkItem.style.height = parseInt(init) + 'px';
    }
    else
    {
        shrinkItem.style.height = parseInt(shrinkItem.style.height) - 2 + 'px';
	
    }
	
	if (parseInt(shrinkItem.style.height) < 3)
		{
			shrinkItem.style.display='none';
			shrinkItem = null;
		}
		else
		{
			setTimeout('shrink("' + itemId + '");',100);
		}
	}

// change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity );
    object.MozOpacity = (opacity );
    object.KhtmlOpacity = (opacity);
    object.filter = "alpha(opacity=" + opacity * 100 + ")";
}
