/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

//Hashtable style array
var next_section_bool = new Array();
var main = {
            
    grow_image : function(div, height, width, top, duration) {
        $(div).children('img').stop().animate({ 
                width: height,
                height: width,
                top: top
                }, duration );
    },
    
    /**
     * Tab switching function. Hacky, but documented. :-)
     */
    tabSwitcher : function(section, tab_bool, selected_id, button_type) {  
        //If a bubble button is clicked
        if(selected_id != null && tab_bool == true)
        {
            $('#' + section + '_tabs').tabs('select', selected_id);
        }
        
        //Get the current selected tab
        var selected = $('#' + section + '_tabs').tabs('option', 'selected');
        
        //couple more vars
        var tab_count = 0;
        var next_section;
        
        //Count the number of tabs in the current section
        $('#' + section + '_tabs li').each(function() {
            tab_count++;
        });
        
        
        //If a next button is clicked
        if(tab_bool != true)
        {		
			selected = parseInt(selected_id); 
			$('#' + section + '_bubbles a').removeClass('count_bubble_on');
			$('[' + section + '_bubble_id='+ parseInt(selected + 1) +']').addClass('count_bubble_on');
            $('#' + section + '_tabs').tabs('select', selected);        
        }
          
        //Conditionals for scroll navigation
        if(section == 'who_we_are' )
        {
			if(tab_bool == true) 
			{
				$('#' + section + '_bubbles a').removeClass('count_bubble_on');
				$('#' + selected_id).addClass('count_bubble_on');
			}
            next_section = '#main_menu';

        }
		
        if(section == 'credentials')
        {
			if(tab_bool == true) 
			{
				$('#' + section + '_bubbles a').removeClass('count_bubble_on');
				$('#' + selected_id).addClass('count_bubble_on');  
			}
			next_section = '#who_we_are';
        }
        
        if(section == 'platform')
        {
			if(tab_bool == true) 
			{
				$('#' + section + '_bubbles a').removeClass('count_bubble_on');
				$('#' + selected_id).addClass('count_bubble_on');				 
			}
			next_section = '#credentials';
        }    
        
        //If the next button is clicked AND we have reached the end of the current tab list - scroll to the next tab section
        if(tab_bool != true && next_section_bool[section] == true && button_type == 'next')
        {
			$('html,body').animate({
				scrollTop: $(next_section).offset().top
			}, 2000, function() {

				//Reset the tab states                    
				$('#' + section + '_tabs').tabs('select', 0); 
				$('#' + section + '_bubbles a').removeClass('count_bubble_on');
				$('[' + section + '_bubble_id=1]').addClass('count_bubble_on');
				$('#' + section + '_next').addClass('next_button_current').removeClass('next_section_state');
				$('#' + section + '_next').addClass('next_button_current').removeClass('top_section_state');
				$('#bubble_arrow_prev').addClass('invisible');
				$('#bubble_arrow_next').removeClass('invisible');
			
			});
            
            next_section_bool[section] = false;
            return false;
        }
       

        //Change the next button class to show the user they have reached the end of sections' tabs', 
        //set the next section boolean also.
        if(selected) {
            $('#' + section + '_next').removeClass('next_section_state');
        }
        if(selected + 1 >= tab_count)
        {
            if(section == 'who_we_are')
            {
                $('#' + section + '_next').addClass('top_section_state').removeClass('next_button_current');
            }
            else 
            {
                $('#' + section + '_next').addClass('next_section_state').removeClass('next_button_current'); 
				
				if(section == 'platform') 
				{
					$('#bubble_arrow_next').addClass('invisible'); 	
					$('#bubble_arrow_prev').removeClass('invisible'); 	
				}
                
            }
            
            next_section_bool[section] = true;
        }
        else 
        {
            if(section == 'who_we_are')
            {
                $('#' + section + '_next').addClass('next_button_current').removeClass('top_section_state');
            }
            else 
            {
                $('#' + section + '_next').addClass('next_button_current').removeClass('next_section_state');
            }
			
			if(section == 'platform') 
			{
				$('#bubble_arrow_next').removeClass('invisible');
				if(selected <= 0) 
				{
					$('#bubble_arrow_prev').addClass('invisible');
				}
				else
				{
					$('#bubble_arrow_prev').removeClass('invisible');
				}
			}
            
            next_section_bool[section] = false;
        }       
        
        return false;
    },
    
    
    //Trial
    timed_event : function(duration, callback) {
        return setInterval(function() {
                    main.callback();
            }, duration);
    },
    
    switch_image : function(div, new_image) {
        if($.browser.webkit) { $(div).stop().fadeOut('slow'); }
        else { $(div + ' img').stop().hide('puff', { percent: 110}, 500); }
             
            setTimeout(function() {
                $(div + ' img').attr('src', new_image);
                if($.browser.webkit) { $(div).stop().fadeIn('slow'); }
                else { $(div + ' img').stop().show('puff', { percent: 110}, 500); }
                return false;
            }, 1000);
            

    },
    
    //Slogan sliding - not used in EE version
    slide_in : function(div_id, distance) {
        $(div_id).css('left', '-1000px');
        //If no distance to slide has been set, center the div on the page.
        
        if (distance == null || distance == '') {       
            distance = (($('#wrapper').width()/2) - ($(div_id).width()/2));
        }
        
        $(div_id).css('position', 'relative');
        $(div_id).animate({
           left: distance,
           opacity: 1.00,
           easing: "easeInBounce"
        }, 
        {
        duration: 3500
        });

    },
    
    scrollWin : function(div)
    {
        $('html,body').animate({
        scrollTop: $(div).offset().top
        }, 2000);
    }

    
}

  

