/*set the size of the viewport on a container*/

function ReplaceContentInContainer(id, content) {
	var container = document.getElementById(id);
	container.innerHTML = content;
	return false;
}


jQuery(document).ready(function() {
	// handle nav selection
	function selectNav(src) {
		console.log("selected");
		if(!src) {
			src = this;
		}
		$(src).parents('ul:first').find('a').removeClass('there').end().end().addClass("there");
		//.addClass('selected');

	}


	jQuery('#header .navigation').find('a').click(function() {
		selectNav(this)
		window.location.hash = "";

	});

	jQuery('#footer .main').find('a').click(function() {
		selectNav(this)
		window.location.hash = "";

	});

	$('.gallery a').click(function() {
		var linkElement = $(this);
		$('.work-header').animate({
			opacity : 0
		}, 400, function() {
			// <li id="filename1"> ... </li>
			var filename = linkElement.closest('li').attr('id');
			$('.work-header').css('background-image', 'url(../wp-content/uploads/work-' + filename + '.jpg)');
			$('.work-header').animate({
				opacity : 1
			}, 400);
		});
		return false;
	});
	var panelCt = jQuery("div.panel").length;

	function viewportSize() {
		var viewSize = jQuery(document).width();
		jQuery("div.coda-slider-wrapper").css({
			'width' : viewSize
		});
		jQuery("div.panel").css({
			'width' : viewSize
		});
		jQuery("div.scrollContainer").css({
			'width' : viewSize * panelCt
		});
		var el = $('#header .navigation a.there').parent();
		if(el.length == 0) {
			el = $('#header .navigation li:first');
		}
		//el.click();
		var idx = el.index();
		jQuery("div.scroll").scrollLeft(viewSize * idx);
	}

	viewportSize();

	jQuery(window).resize(function() {
		viewportSize();

	});

	jQuery("#content #slider .scrollContainer").show();
	//    jQuery("#content #slider .scrollContainer").fadeIn(250);
	
	var hasThere = false;
	jQuery('#header .navigation a').each(function() {
		if (jQuery(this).hasClass("there")) {
			hasThere = true;
		}
	});
	if (!hasThere) {
		jQuery('#header .navigation ul li:first-child a').addClass("there");
	}
	
	
});

