jQuery(document).ready(function($){
    setup_splash_rotator_fade($);
});

var setup_splash_rotator_fade = function($)
{
    var splash_element = $(".main-body .splash-rotator-fade");
    if (splash_element.length == 0)
    {
        return;
    }
    var splash_nav = $(splash_element).find(".navigation");
    var splash_nav_anchor_list = $(splash_nav).find("ul li a");
    var splash_item_container = $(splash_element).find(".content ul");
    var splash_item_list = $(splash_item_container).find("li");
    var splash_rotator = {
        min_index: 0,
        max_index: 46236453645,
        current_index: null,
        interval_id: null,
        auto_click: false,
        init: function() {
            this.max_index = splash_nav_anchor_list.length;
            if (this.current_index == null)
            {
                this.current_index = this.min_index;
            }
            this.interval_id = this.start_interval();
        },
        start_interval: function() {
            return window.setInterval(function(){
                splash_rotator.render();
            }, 7000);
        },
        increment_index: function() {
            if (++this.current_index == this.max_index)
            {
                this.current_index = this.min_index;
            }
            this.auto_click = true;
			
            return this.current_index;
        },
        get_current_index: function(clicked_element) {
            if (this.auto_click)
            {
                return this.current_index;
            }
			
            return $(splash_nav_anchor_list).index(clicked_element);
        },
        get_previous_index: function(clicked_element) {
            if (this.auto_click)
            {
                var previous_index = this.current_index - 1;
                if (previous_index == -1)
                {
                    previous_index = this.max_index - 1;
                }
                return previous_index;
            }
			
            return this.current_index;
        },
        render: function() {
            var current_index = this.increment_index();
            $(splash_nav_anchor_list).eq(current_index).click();
        }
    };
	
    $(splash_nav_anchor_list).unbind("click").click(function(e){
        e.preventDefault();
        $(this).parent().addClass("active").siblings(".active").removeClass("active");
		
        var current_index = splash_rotator.get_current_index(this),
        previous_index = splash_rotator.get_previous_index(this);
        splash_rotator.auto_click = false;
        splash_rotator.current_index = current_index;
		
        var current_item = $(splash_item_list).eq(current_index),
        previous_item = $(splash_item_list).eq(previous_index);
        $(previous_item).fadeOut(250);
        $(current_item).fadeIn(250);
    });
    splash_rotator.init();
	
    $(splash_element).hover(function(e){
        window.clearInterval(splash_rotator.interval_id);
    }, function(e){
        splash_rotator.interval_id = splash_rotator.start_interval();
    });
}
/*
$(document).ready(function(){
	
	//************************ TOP NAV - SETUP PARENT HOVER ******************************
	$("#main-nav li a").hover(
	function () {
		//$(this).css("background-position", "0 -53px");
	}, 
	function () {
		//$(this).css("background-position", "0 0");
	  }
	);
	
	//************************ TOP NAV - MAINTAIN PARENT HOVER ON CHILD HOVER ******************************
	$("ul.hover").hover(
	function () {
		$(this).parent().find("a").css("background-position", "0 -53px");
	}, 
	function () {
		$(this).parent().find("a").css("background-position", "0 0");
	  }
	);
	
});*/


$(document).ready(function(){

	$('.viewport ul').cycle({ 
		fx:     'scrollHorz', 
		speed:  'slow', 
		timeout: 0, 
		next:   '.previous-button', 
		prev:   '.next-button' 
	});
	
	/*---------------------------------------------------------------------------
	/ Make it so that when the homepage slider is clicked, it goes to the link
	----------------------------------------------------------------------------*/
	$('.splash .content ul li').click(function(){
		var get_link = $(this).find('a').attr('href');
		if(get_link != ''){
			window.location = get_link;	
		}
    });
});

