$.fn.log = function (msg) {
  console.log("%s: %o", msg, this);
  return this;
};

function buildGallery(feed) {

	$.getJSON(feed+"&format=json&jsoncallback=?", function(data){
		$.each(data.items, function(i,item){
			$("<img/>").attr("src", item.media.m.replace(/_m\.jpg/g,'.jpg')).appendTo("#carousel").wrap("<li></li>");
			$('#carousel li:eq(1)').addClass('active');
		});
		
		$('ul#carousel').galleria({
			history   : false, // activates the history object for bookmarking, back-button etc.
			clickNext : true, // helper for making the image clickable
			insert    : '#galleryImg', // the containing selector for our main image
			onImage   : function(image,thumb) { // let's add some image effects for demonstration purposes

				// fade in the image & caption
				if(! ($.browser.mozilla && navigator.appVersion.indexOf("Win")!=-1) ) { // FF/Win fades large images terribly slow
					image.css('display','none').fadeIn(1000);
				}

				// fetch the thumbnail container
				var _li = thumb.parents('li');

				// fade out inactive thumbnail
				_li.siblings().children('img.selected').fadeTo(500,0.3);

				// fade in active thumbnail
				thumb.fadeTo('fast',1).addClass('selected');

				// add a title for the clickable image
				image.attr('title','Next image >>');
												
				var nextImg = $("li.active").next().find('img').attr('src');
				var prevImg = $("li.active").prev().find('img').attr('src');
				
				$('div.galleryNav').removeClass('disabled');
				
				if ($('ul#carousel li:last').hasClass('active')) {
					$('div.galleryNav.next').addClass('disabled');
				}
				if ($('ul#carousel li:first').hasClass('active')) {
					$('div.galleryNav.prev').addClass('disabled');
				}
				
				$('div.galleryNav.prev img').attr('src', prevImg );
				$('div.galleryNav.next img').attr('src', nextImg );
			}
		});
		
		$('.galleryNav.next').click(function() {
         		$.galleria.next();
			return false;
		});

		$('.galleryNav.prev').click(function() {
         		$.galleria.prev();
			return false;
		});
		
	});
}

$(document).ready(function() {
	
	$('#landingContent .leftColumn p:first, .caseStudy p:first, .page p:first').addClass('first');
	$('#footNav li:last').addClass('last')
	
	
	$('ul.clients li:odd').addClass('odd');

    $('#slidePhotos').cycle({
        fx:     'fade',
        speed:  'slow',
        timeout: 5000
    });
    
	$("#caseStudySlider").jCarouselLite({
	    btnNext: "button.next",
	    btnPrev: "button.previous",
		easing: "easeOutSine",
		circular: true,
		visible: 3,
		speed: 800
		
	});

	$('ul.clients').find('a').each(function(index) {
		var $title = $(this).find('img').attr('alt');
		var $img = $(this).html();
		$(this).after('<h6>'+$title+'</h6>');
		$(this).after($img);
		$(this).remove();
		
	});

	$('a.commentTrigger').click(function() {
		$('#respond').fadeIn("slow");
		return false;
	});


	//fix stupid ie bug
	if ($.browser.msie) {
		$('hr').each(function(index) {
			var $hrClasses = $(this).attr('class');
			$(this).wrap('<div class="hr '+ $hrClasses +'"></div>')
		});
		$('div.featured').next('p').css("clear","both");
		$('input#newsletter_submit').attr("value","");
		
	}
	
	$('a[rel="external"]').click( function() {
        window.open( $(this).attr('href') );
        return false;
    });
	
/*	//ie7 only
	$.each($.browser, function(i, val) {
	  if(i=="msie" && jQuery.browser.version.substr()=="7.0")
	});
*/	
	//fix ie6 nonsense
	
	var version = jQuery.browser.version;
	if (version instanceof Object)
	    version=version.number();
	if ( jQuery.browser.msie && version < 7 ) {
		$('').ifixpng();
		
	}
	
	
	
});