$(document).ready(function() {
    $('#developedProp tr:even').addClass('grey');
	
    // homepage tooltips
    $('.trigger').tooltip({
        position: ['center', 'center'],
        offset: [0, 100],
        relative: true,
        effect: 'fade',
        events: {
            def: "click, mouseout"
        }
    });

    // if user doesn't have javascript enabled they can still see the nav.
    $pane = $('.productlist .pane');
    $pane.css('display', 'none');
    
    // get the initial index.
    var $initidx = $('.productlist h3').index($('h3.initcat'));
    if ($initidx >= 0)
    {
        $pane.eq($initidx).css('display', 'block');
    }
    else
    {
        $initidx = -1;
    }
    
    // set up the tabs.
    $productlist = $(".productlist");
    if ($productlist.find('h3:not(.nochildren)').length > 0)
    {
        $productlist.tabs(".productlist div.pane", {
            tabs: "h3:not('.nochildren')",
            initialIndex: $initidx,
            effect: 'slide' 
        });
    }
    
    // open links to other sites in a new window
    $("._blank").click(function() { return ! window.open($(this).attr("href")); });
	$('#services').click(function(e){e.preventDefault();});
    
	/*///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	STANDARD SLIDESHOW
	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	arrangeStack();
});
/*///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
STANDARD SLIDESHOW
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
function arrangeStack(){
	var slideshow = $('#standardShow img');
	var numberOfSlides = slideshow.length;
	
	if (numberOfSlides > 1){
		$(slideshow).each(function(i){
			$(this).css({
				'z-index' : 0
			});
		});
		$(slideshow).eq(0).css({'z-index' : 2});
		$(slideshow).eq(1).css({'z-index' : 1});
		setTimeout(function() {standardSlideShow(0);}, 5000);
	}else{
		return;	
	}
	
};
function standardSlideShow (currentSlide){
	var slideshow = $('#standardShow img');
	var numberOfSlides = slideshow.length;
	currentSlide = currentSlide % numberOfSlides;
	
	$(slideshow).eq(currentSlide).fadeOut(function(){
		if(currentSlide == numberOfSlides - 2){
			$(slideshow).eq(currentSlide + 1).css({'z-index': 2});
			$(slideshow).eq(0).css({'z-index': 1});
		}else if(currentSlide == numberOfSlides - 1){
			$(slideshow).eq(0).css({'z-index': 2});
			$(slideshow).eq(1).css({'z-index': 1});
		}else{
			$(slideshow).eq(currentSlide + 1).css({'z-index': 2});
			$(slideshow).eq(currentSlide + 2).css({'z-index': 1});
		}
		
		$(this).show().css({'z-index' : 0});
		setTimeout(function() {standardSlideShow(++currentSlide);}, 5000);
		
	});
};
