/* 
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() {
	// Initial Fancybox for all links with the class.
	$j('.fancybox').fancybox();
	// start the slider
	$j("#slider").anythingSlider({
		expand              : false,     // If true, the entire slider will expand to fit the parent element
		resizeContents      : true,      // If true, solitary images/objects in the panel will expand to fit the viewport
		showMultiple        : false,     // Set this value to a number and it will show that many slides at once	
		buildArrows         : false,      // If true, builds the forwards and backwards buttons
		buildNavigation     : true,      // If true, builds a list of anchor links to link to each panel
		buildStartStop      : false,      // If true, builds the start/stop button
		hashTags            : true,      // Should links change the hashtag in the URL?
		infiniteSlides      : true,      // if false, the slider will not wrap & not clone any panels
		autoPlay            : true	    // If true, the slideshow will start running; replaces "startStopped" option
	});
	
	// Initiate tabs for sectors 
	$j('#sectors li').first().addClass('active');
	$j('#tabs-1').show();
	$j(".tab").click( function() {
		$j("#sectors li.active").removeClass('active');
		$j(this).parent().addClass('active');
		$j('.tab-content').slideUp('fast');
		var thisid = $j(this).attr('href').slice(1);
		$j('#' + thisid).slideDown('slow');  
	});
	
	// Tabbs
	$j(".tabbed").each(function() {
		$j(".tab",this).hide(); // hide all tabs
		$j(".tab:eq(0)",this).show(); // display first tab
		$j(".tab_nav a:eq(0)",this).addClass("activeTab");
		$j(".tab_nav a",this).click(function() {
			var page = $j(this).attr("href");
			$j(".tab_nav a").removeClass("activeTab");
			$j(this).addClass("activeTab");
			$j(".tab").hide();
			$j(page).show();
			return false;
		});	
	});

});	

(function($)
{
    $.fn.extend({
        bgrotate: function(options)
        {
            var defaults = {
                delay: 1000,
                images: [],
                imagedir: "/images/"
            }

            var o = $.extend(defaults, options);
            var $obj = $(this);
            var cache = [];
            var i = 0;
            var preCache = false;

            return this.each(function()
            {
                setInterval(function() { setBack($obj, o.images, o.imagedir) }, o.delay);
            });

            function setBack(elem, backgrounds, imagedir)
            {
                elem.animate("background-image", "url(" + imagedir + backgrounds[i] + ")");
                i++;
                if (i == backgrounds.length)
                {
                    i = 0;
                    preCache = false;
                }
                if (preCache)
                {
                    var cacheImage = document.createElement('img');
                    cacheImage.src = imagedir + backgrounds[i];
                    cache.push(cacheImage);
                }
            }
        }
    });
})(jQuery);

