$(function() {
	// ajax calls to load content into slider
	var loadTarget = $("div#gallery");
	var tabs = $("ul.tabs a").each(function(index){
		/*if(index===0){
			loadTarget
				.load($(this).attr("href")+" #toLoad",
					function(){
						$(this)
							.removeClass("loading");
							//.CLSlider();
					}
				)
				.addClass("loading");
			$(this).addClass("selected");
		}*/
		$(this).click(function() {
			var me = this;
			$("#toLoad").fadeOut("fast", function() {
				loadTarget
					.addClass("loading")
					.load($(me).attr("href")+" #toLoad",
						function(){
							$(this).removeClass("loading");
							$("a", $(this)).nyroModal();
							tabs.removeClass("selected");
							$(me).addClass("selected");
						}
					);
			});
			return false;
		});
	});
	$("#gallery a").nyroModal();
	
	var bg = $("#bgImage");
	$(window).bind("resize",function() {
		bg.css({
			width : getViewport()[0],
			height : getViewport()[1]
		});
	});
	
	if($.browser.msie && $.browser.version < 7) {
		$("#Content").pngFix();
		$("#gallery .page a img").css("margin-right","26px");
		$("#gallery .page a:last-child img").css("margin-right","0");
	}
});

function getViewport() {
	var viewportwidth;
	var viewportheight;
	var arr = new Array();
	
	// mozilla/netscape/opera/IE7
	if (typeof window.innerWidth != 'undefined')
	{
		viewportwidth = window.innerWidth,
		viewportheight = window.innerHeight
	}
	
	// IE6 in standards compliant mode
	else (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0)
	{
		viewportwidth = document.documentElement.clientWidth,
		viewportheight = document.documentElement.clientHeight
	}
	arr[0] = viewportwidth;
	arr[1] = viewportheight;
	return arr;
}
