/* 
Optimal Jobs Javascript Interface functions library
Author: Dan Sunderland
No reason these are inline- It's just tidier this way! 
*/

$j = jQuery.noConflict(); 

$j(document).ready(function() {

	//dropdown navigation code
	$j(".top_nav").each(function(){
		$j("li:has(ul)",this).hover(function(){
			$j(this).addClass("noBottomRadius");
			$j("ul:eq(0)",this).show();
		}, function(){
			$j("ul:eq(0)",this).hide();
		});
	});

	// Initial Fancybox for all links with the class.
	$j('.fancybox').fancybox();
	
	$j('.to_top').click(function(){
		$j( 'html, body' ).animate( { scrollTop: 0 }, 'slow' );
		return false;
	});
	
	$j(".user_menu li:has(ul)").hover(function(){
		$j("ul:eq(0)",this).slideDown(100);
	}, function(){
		$j("ul:eq(0)",this).slideUp(100);	
	});
	
	$j(".tabbed").miniTabs();
	$j(".profile_tabbed").miniTabs({
		desc: true
	});
	
	function clock() {
		var time = new Date();
		var hour = time.getHours();
		var mins = time.getMinutes();
		var secs = time.getSeconds();
		var day = time.getDate();
		var month = time.getMonth();
		var year = time.getFullYear();
		mins = ( mins < 10 ? "0" : "" ) + mins;
		secs = ( secs < 10 ? "0" : "" ) + secs;
		var timeOfDay = ( hour < 12 ) ? "AM" : "PM";
		hour = ( hour > 12 ) ? hour - 12 : hour;
		hour = ( hour == 0 ) ? 12 : hour;
		var currentTime = hour + ":" + mins + ":" + secs + " " + timeOfDay;
		var months = new Array(
			"January","Febuary", "March","Apirl","May","June","July","August","September","October","November","December"
		)
		var fullDate = day+" "+months[month]+" "+year;
		document.getElementById("time").firstChild.nodeValue = currentTime;
		document.getElementById("date").firstChild.nodeValue = fullDate;
	}
	clock();
	setInterval(function(){
		clock();
	},1000);
	
});

// Tabbs plugin - this allows multiple tabbed areas on each page
(function($){
	$.fn.miniTabs = function(options) {
		var defaults = {
			desc: false
		}
		
		var opts = $.extend(defaults,options);
		
		var $this = $(this);	// store the parent element
		$(".tab",$this).hide();	// hide all tabs
		$(".tab:eq(0)",$this).show();	// show only the first tab
		
		if(opts.desc == true) {
			$(".desc",$this).hide();	// hide all descriptions
			$(".desc:eq(0)",$this).show();	// show only the first description
		}
		$(".tab_nav a:eq(0)",$this).addClass("activeTab");	// add active state to first tab
		$(".tab_nav a",$this).click(function() {
			var page = $j(this).attr("href");	// store the clicked link href
			$(".tab_nav a",$this).removeClass("activeTab");	// remove the active state off links
			$(this).addClass("activeTab");	// add the active state to the clicked link
			$(".tab",$this).hide();	// hide all tabs
			$(page).show();	// show the target tab
			if(opts.desc == true) {
				$(".desc").hide();
				$(page+"-desc").show();
			}
			return false;	// prevent the default action
		});
	}	
})(jQuery);


