var imageSizes = [
	[800, 600],
	[1024, 576],
	[1280, 720],
	[1400, 1050],
	[1600, 1200],
	[1680, 1050],
	[1920, 1080],
	[2560, 1600]
];

$(document).ready(function()
{
	setBackgroundImage();
	
	// view more links in the side bar
	$('.view-all').click(function()
	{
		var current = $(this);
		var parent = $(current.parent().parent()); // the container div for both lists
		
		$('.more', parent).slideDown();
		current.slideUp();
		
		return false;
	});
	
	// collapse boxes on view post page
	$('.collapse-box h4').click(function()
	{
		var current = $(this);
		var parent = $(current.parent());
		
		if (current.hasClass('closed'))
		{
			// open the box
			$('div', parent).show('fast');
			current.removeClass('closed').addClass('opened');
		}
		else
		{
			// close the box
			$('div', parent).slideUp();
			current.removeClass('opened').addClass('closed');
		}
	});
	
	// search box
	$('#s').attr('value', 'Search').focus(function() {
		var current = $(this);
		
		if (current.attr('value') == 'Search')
		{
			$(this).attr('value', '');
		}
	}).blur(function() {
		var current = $(this);
		
		if (current.attr('value') == '')
		{
			$(this).attr('value', 'Search');
		}
	});
	
});

function setBackgroundImage() {
	// background
	var size_to_load = "";
	for(var i = 0; i < imageSizes.length; i++) {
		if (imageSizes[i][0] >= $(window).width()) {
			size_to_load = imageSizes[i];
			break;
		}
	}
	$('body').css('background-image', 'url(http://new.axis41.com/public/portfolio/0/original_' + size_to_load[0] + 'x' + size_to_load[1] + '.jpg)');
	
	return;
}

$(window).resize(function() {
	setBackgroundImage();
});