if (typeof(log) === "undefined"){
	function log(s) {
		try { console.log(s); } catch (e) {}
	}
}

var screensize = $('body').width();

// Contact bar
var showHelloBar = false;
$('#toggleHelloBar').click(function(){
	if (showHelloBar===true){
		//alert('True');
		if (screensize > 768) {
			$('.contact').slideUp();
		} else {
			$('.contact').hide();
		}
		$(this).parent('li').removeClass('selected');
		showHelloBar = false;
	} else {
		$(this).parent('li').addClass('selected');
		if (screensize > 768) {
			$('.contact').slideDown();
		} else {
			$('.contact').show();
		}
		
		showHelloBar = true;
		clicky.log('/#contact','Hello Bar','click');
	}
});

// Let's get device appropriate sizes. Be nice to cell phones.
$('img.respond').each(function(){
	var use;
	if (screensize > 900) {
		use = $(this).attr('data-img-full');
	} else if(screensize > 480) {
		use = $(this).attr('data-img-tablet');
	} else {
		use = $(this).attr('data-img-mobile');
	}
	// alert(use);
	$(this).attr('src',use);
});

// Also, mark bigger screens as tablets so we can use CSS gradients when the processing power is there.
if (screensize > 640){
	$('html').addClass('tablet');
}

$(document).ready(function() {
	// Stuff to do as soon as the DOM is ready;
	$('.viewnav li').click(function(){
		var whatSite, siteName;
		whatSite = $(this).attr('class');
		siteName = $(this).attr('data-site');

		var whatEntry;
		whatEntry = $(this).parents('.entry').attr('id');
		// Now we know what site inside which entry we want
		// clicky.log('/#'+whatEntry+'+'+whatSite,'Portfolio Click','click');
		// Tell clicky
		if($(this).hasClass('selected')){
			return false;
			//If this website is already showing, kill the function.
		}
		// Fade the current site out, fade the new site in, and switch the class when they're done so it looks like a single animation
		$('#'+whatEntry+' .websites li.current').animate({opacity: 0}, 250).removeClass('current');
		$('#'+whatEntry+' .websites li.'+whatSite).animate({opacity: 1.0}, 250).addClass('current');
		// Change the button selection, then we're done
		$('#'+whatEntry+' .viewnav li.selected').removeClass('selected');
		$(this).addClass('selected');

		log(siteName);
		clicky.log('/portfolio', 'Selected: '+siteName,'click');

		return true; // Makes Lint happy
	});
});
