$.fn.dyanmicDetailList = function(options){

    return this.each(function()
	{
		$(this).find('a.show').click(function()
		{
			HideAllListItems($('#whowearelist > li'));		
			$(this).addClass('show2'); 
			$(this).removeClass('show'); 
			$('#profileimage').attr('src', $(this).next().val()).removeClass('displaynone');
			$(this).next().next().removeClass('displaynone');
		});
		
		$(this).find('a.hide').click(function()
		{
			$(this).parent().prev().prev().addClass('show'); 
			$(this).parent().prev().prev().removeClass('show2');  
			$('#profileimage').attr('src', '').addClass('displaynone');
			$(this).parent().addClass('displaynone');	
		});
    });
}

function HideAllListItems(list)
{
	list.each(function()
	{
		$(this).find('a.show2').next().next().addClass('displaynone');
		$(this).find('a.show2').addClass('show');
		$(this).find('a.show2').removeClass('show2');
	});	
}

$.fn.dyanmicDetailListwithoutimages = function(options){

    return this.each(function()
	{
		$(this).find('a.show').click(function()
		{
			HideAllListItemsWithoutImages($('#whatwedolist > li'));
			HideAllListItemsWithoutImages($('#whowearelist > li'));	
			$(this).addClass('show2'); 
			$(this).removeClass('show'); 
			$(this).next().removeClass('displaynone');
		});
		
		$(this).find('a.show2').click(function()
		{
			HideAllListItemsWithoutImages($('#whatwedolist > li'));
			HideAllListItemsWithoutImages($('#whowearelist > li'));	
			$(this).addClass('show2'); 
			$(this).removeClass('show'); 
			$(this).next().removeClass('displaynone');
		});
		
		$(this).find('a.hide').click(function()
		{
			$(this).parent().prev().addClass('show');
			$(this).parent().prev().removeClass('show2');  
			$(this).parent().addClass('displaynone');
		});
    });
}

function HideAllListItemsWithoutImages(list)
{
	list.each(function()
	{
		$(this).find('a.show2').next().addClass('displaynone');
		$(this).find('a.show2').addClass('show');
		$(this).find('a.show2').removeClass('show2');
	});	
}

$.fn.dyanmicDetailListforimages = function(options){

    return this.each(function()
	{
		$(this).find('a.showonlyimage2').click(function()
		{
			HideAllListItemsForImages($('#whatwedolistright > li'));		
			$(this).addClass('showonlyimage'); 
			$(this).removeClass('showonlyimage2'); 
			$(this).next().removeClass('displaynone');
		});
		
		$(this).find('a.hide').click(function()
		{
			$(this).parent().prev().addClass('showonlyimage2'); 
			$(this).parent().prev().removeClass('showonlyimage');  
			$(this).parent().addClass('displaynone');		
		});
    });
}

function HideAllListItemsForImages(list)
{
	list.each(function()
	{
		$(this).find('a.showonlyimage').next().addClass('displaynone');
		$(this).find('a.showonlyimage').addClass('showonlyimage2');
		$(this).find('a.showonlyimage').removeClass('showonlyimage');
	});	
}

$.fn.ClientSlider = function(currentclientID)
{	
	var queryString = unescape(location.search.substr(1));

	if (queryString != null)
	{
		UpdateDisplay(currentclientID, queryString, $('#clientsliderimages'), $('#clientslidertext'), $('#latestworkLink'));
	}

	$('#previous').click(function()
	{
		if ($(currentclientID).val() > 0)
		{
			var count = $(currentclientID).val();
			count--;			
			UpdateDisplay(currentclientID, count, $('#clientsliderimages'), $('#clientslidertext'), $('#latestworkLink'));
		}
		
	});
	
	$('#next').click(function() 
	{
		if ($(currentclientID).val() < ($('#clientsliderimages > div.client').length - 1))
		{
			var count = $(currentclientID).val();
			count++;
			UpdateDisplay(currentclientID, count, $('#clientsliderimages'), $('#clientslidertext'), $('#latestworkLink'));
		}
		
	});
};

function UpdateDisplay(currentIDHolder, newID, clientsliderimages, clientslidertext, latestworkLink)
{
	$(currentIDHolder).val(newID);
	var count = 0;
	$(clientsliderimages).find('.client').each(function() {
		$(this).addClass('displaynone');
	
		if (count == newID)
			$(this).removeClass('displaynone');
		count = count + 1;
	});
	
	count = 0;
	$(latestworkLink).find('.number').each(function() {
		$(this).addClass('noHighlight');
		
		if( count == newID)
			$(this).removeClass('noHighlight')
		count = count +1;
	});
	
	count = 0;
	$(clientslidertext).find('.client').each(function() {
		$(this).addClass('displaynone');
		
		if (count == newID)
			$(this).removeClass('displaynone');
		count = count + 1;
	});
};

function IE6FlickerFix()
{
        try { document.execCommand("BackgroundImageCache", false, true); } 
        catch(err) {}
};

$.fn.externalLinks = function() {
    $("a[rel]").each(function() {
        if (this.getAttribute("rel").indexOf("external") > -1) {
            this.target = "_blank";
        }
    });
};

$(document).ready(function(){
	IE6FlickerFix();
	jQuery().externalLinks();
});

$.fn.displayFlash = function(filename, title)
{
	var flashvars = {};
	var params = {
	  wmode: "transparent"
	};
	var attributes = {};
	swfobject.embedSWF(filename, "banner", "940", "275", "9.0.0", "/flash/expressInstall.swf", flashvars, params, attributes);
}

$.fn.getTweet = function(options) {
	var defaults = {
			userName: null,
			loaderHtml: "Loading tweet..."
	};

	var o = $.extend(defaults, options);

	return this.each(function() {
		var c = $(this);

		// remove alternative content
		c.empty();

		var preLoaderHTML = $(o.loaderHtml);
		c.append(preLoaderHTML);

		$.getJSON("http://twitter.com/statuses/user_timeline/"+o.userName+".json?count=3&callback=?", function(data) {

			$(preLoaderHTML).remove();
			
			var url = $('#HfBlogUrl').val();
			var htmlString = '';
			var count;
			for (count = 0; count < data.length; count++) {
				var item = data[count];
				htmlString += "<blockquote>" + "<a href='http://www.twitter.com/bcspr' class='redArrowTweet'>" + item.text + "<img alt='arrow' src='" + url + "/images/_generic/redArrow.png'>" + "</a>" + "</blockquote>";
			}
			
			c.html(htmlString);
		});
	});
}; 

function twitterRelativeTime(time_value) {
	var values = time_value.split(" ");
	time_value = values[1] + " " + values[2] + ", " + values[5] + " " + values[3];
	var parsed_date = Date.parse(time_value);
	var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
	var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);
	delta = delta + (relative_to.getTimezoneOffset() * 60);

	if (delta < 60) {
		return 'less than a minute ago';
	} else if(delta < 120) {
		return 'about a minute ago';
	} else if(delta < (60*60)) {
		return (parseInt(delta / 60)).toString() + ' minutes ago';
	} else if(delta < (120*60)) {
		return 'about an hour ago';
	} else if(delta < (24*60*60)) {
		return 'about ' + (parseInt(delta / 3600)).toString() + ' hours ago';
	} else if(delta < (48*60*60)) {
		return '1 day ago';
	} else {
		return (parseInt(delta / 86400)).toString() + ' days ago';
	}
}

