
var skin = 
{
	sidebars : function() 
	{
		if ($("#content .sidebar-left").html().length > 10) {
			$("body").addClass("sidebar-l");
		}
		if ($("#content .sidebar-right").html().length > 10) {
			$("body").addClass("sidebar-r");
		}
		if (!$("body").hasClass("sidebar-r") && !$("body").hasClass("sidebar-l")) {
			$("body").addClass("no-sidebars");
		}
	}		
};


(function($)
{
	
	
$(document).ready(function() 
{
	var t = $("#menu ul").text();
	
	if (t.match("Admin") || t.match("Host")) 
	{
		$("#menu menu > ul").css("margin-left", "35px");
	};

	$("a.tooltip").each(function() 
	{
		var tt = $(this).parent().next();
		
		$(this).hover
		(
			function()
			{
				tt.stop(true, true).fadeIn(550);
				
				if ($.browser.msie)
				{
					tt.show();
				};
			},
			function()
			{
				tt.stop(true, true).fadeOut(350);
			}
		);

	});

	
});


PhotoFrame = (function($)
{	
	var init = function()
	{
		$("#photo-frames .frame img").click(function()
		{
			var size = ($(this).attr("size") ? $(this).attr("size") : "large");
			$(this).before("<div class=\"frame-overlay " + size + "\" style=\"display:none;background-image: url('" + $(this).attr("src").replace(/small/gi, size) + "');\"></div>");	
			$(this).parent().find(".frame-overlay").fadeIn(750).click(function()
			{
				$(this).fadeOut(250, function()
				{
					$(this).remove();
				}).unbind();
			}).mouseout(function()
			{
				$(this).fadeOut(250, function()
				{
					$(this).remove();
				}).unbind();
			});
		});
	};

	return {
		init: init
	}
})(jQuery);

$(document).ready(function()
{
	PhotoFrame.init();	
});





var Slider = (function($)
{
	var img;
	var imgTop;
	var index = 0;
	var skipNext = false; // skip next transition - invoked if user manually changes a slide
	var transitionSpeed = 550;
	var basePath = "/Portals/0/";
	
	
	var slides =
	[
		{
			image : basePath + "home-0.jpg"
		},
		{
			image : basePath + "home-1.jpg"
		},
		{
			image : basePath + "home-3.jpg"
		},
		{
			image : basePath + "home-4.jpg"
		},		
		{
			image : basePath + "home-5.jpg"
		}
	];
	
	// loads next slide
	var next = function()
	{
		if (!skipNext)
		{
			skipNext = true;	// used to lock widget during animation			
			img.css("background-image", "url(" + slides[index].image + ")");
			
			imgTop.stop(true, false).animate(
			{
				"margin-left": "-" + img.outerWidth()
			}, transitionSpeed, function() 
			{
				imgTop.css(
				{
					"background-image": img.css("background-image"),
					"margin-left" : "0"
				});
				
				skipNext = false;
			});	
			
			
			incIndex();	
		};
	};
	
	//jump to specified slide
	var jumpTo = function(i)
	{
		if (i < slides.length && i > -1)
		{
			skipNext = false;
			index = i;
			next();
			skipNext = true;
		};
	};
	
	var incIndex = function()
	{
		index++;		
		if (index == slides.length) { index = 0 }		
	};
	
	var decIndex = function()
	{
		index--;
		if (index == 0) { index = slides.length }			
	};
	
	var prevIndex = function()
	{
		if (index == 0) { return slides.length-1 }
		return index-1;
	};
	
	// make sure all images are cached
	var cache = function()
	{
		$.each(slides, function(i, slide)
		{
			var img = new Image();
			img.src = slide.image;
		});
	};
	
	var init = function()
	{
		img = $("#services-viewer .image-area");
		imgTop = $("#services-viewer .image-area-top");
		
		// set initial slide
		imgTop.css("background-image", "url(" + slides[index].image + ")");
		//syncFrames();
		incIndex();		
		cache();
		
		$("#services-viewer").click(function()
		{
			next();
		});
		
		setInterval(function() { next() }, 9000);
	};
	
	return {
		init : init,
		next : next,
		jumpTo : jumpTo
	};
})(jQuery);



$(document).ready(function()
{
	Slider.init();	
});




$(document).ready(function()
{
	$("#the-board").tabs();
	$("#the-management").tabs();
});


})(jQuery);
