// Opus Javascript library
(function($) {
	$.opus = {
		init: function() {
			var $link, $solutionWidget,
				$body = $("body"),
				$nav = $("#nav"), $navFirstLevel = $nav.children(), $navItem;
				
			//nav
			$navFirstLevel.each(function(idx) {
				$navItem = $(this);
				if ($navItem.hasClass("current_page_item")) {
					$navItem.addClass("selected");	
				}
				if (idx === $navFirstLevel.length-1) {
					$navItem.addClass("last");
				}
			});
			
			
			//screenshot
			$.setClassToNthPosition($("ul.screenshots li"), 3, "last");
			
			//more
			$("a.more, a.more_inline").each(function() {
				$link = $(this);
				$link.text($link.text()+" >")						  
			});

			// homepage
			if ($body.hasClass("homepage")) {
				$solutionWidget = $("#solutionsWidget");
				if ($.trim($solutionWidget.text()) === "") {
					$solutionWidget.remove();
					$body.addClass("noSolutions");
				}
			}
			
			if ($.browser.webkit) {
				$body.addClass("webkit");		
			}

			// videos
			$("a.videoJs").colorbox({
				iframe:true,
				innerWidth:640,
				innerHeight:385
			});
		}
	}
	
	// Dom ready
	$(function() { $.opus.init(); });




	/***************************************************/
	//	Function: $.setClassToNthChild()
	//
	//	Developped by: Son Pham
	//
	//	description: Set a className to a nth-position of a selector
	//
	//	requirement: 1) jQuery 1.3.2+
	//
	//	usage:	1) $.setClassToNthPosition("ul li",3,"colLast");
	//			2) $.setClassToNthPosition($("ul>li"),5,"endOfRow");
	//
	// params : 
	//	@selector : (string/object) list of html elements to apply className
	//	@nTh : (number) nth number for each to apply the className
	//	@className: (string) css className to apply when nth-child is founded
	/**********************************************************/
	jQuery.setClassToNthPosition = function(selector, nTh, className) {
		var $element;
		if (selector && !isNaN(nTh)) {		
			$(selector).each(function(idx) {
				$element = $(this);
				$element.removeClass(className);
				if (idx!==0 && (idx+1)%nTh===0) {
					$element.addClass(className);
				}
			});
		}
	};
})(jQuery);
