;ET.TABS = 
{
    init: function(tabs, position, style)
    {   
        // Verify position of default tab
        position = (typeof position == 'undefined') ? 0 : parseInt(position, 10);
        if(tabs.find('a:eq('+ position +')').length === 0)
        {
            position = 0;
        }
        // check for a custom style (added for VFM implementation so viewer does not reload)
        style = (typeof style == 'undefined') ? 'hide' : style;
        
        // Add class to define currently selected tab
        tabs.find('a:eq('+ position +')').addClass('selectedTab');
        
        // Hide all content except selected
        tabs.find('a').each(function()
        {
			if($(this).attr('href').indexOf('#') === 0 )
            {
			   // IE puts full window location in href if link created dynamically so remove if found.
			   $(this).attr( { 'href' : $(this).attr('href').replace(window.location.href.match(/[^#]*/),'') } );

			   if($(this).hasClass('selectedTab'))
				{
					$($(this).attr('href')).removeClass(style);
				}
				else
				{
					$($(this).attr('href')).addClass(style);
				}
			}
        });
                    
        // Attach tab load functionality
        tabs.find('a').bind('click', function(e)
        {
            
            // Only go to load tab content if href is a hash
            if($(this).attr('href').indexOf('#') === 0 )
            {
                e.preventDefault();
                ET.TABS.tabLoad($(this),style);
            }
        });
        
    },
    
    tabLoad: function(tab, style)
    {
        var currentTab = tab.parent().parent().find('.selectedTab');
        $(currentTab.attr('href')).addClass(style);
        currentTab.removeClass('selectedTab');
        
        $(tab.attr('href')).removeClass(style);
        tab.addClass('selectedTab');
    }
};
