/*******************************
FOR USE ON TABS MODULE
- also in use with jquery-ui.js
*******************************/

"use strict";
// global window: true, document: true, jQuery: true, swfobject: true, Intel: true 

(function ($) {

	// Initializes Tab Modules having CSS class:
	// - tab-wrapper
	Intel.mod.tabsMod = function () {
		$('.mod-tabs .tab-wrapper').each(function () {
		    var oTabs,
		    $tabs = $('.mod-tabs .tab-wrapper');
		    
		    // Initialize address plugin to update tab href with tab rel; execute tabs()
		    $.address.init(function (event) {
		        if (!$.support.opacity) {
		            oTabs = $tabs.tabs({
		            	selected: $tabs.find('ul:first a').index($('a[rel=address:' + event.value + ']'))
		            }).css('display', 'block');
		        } else {
		            oTabs = $tabs.tabs({
		            	selected: 	$tabs.find('ul:first a').index($('a[rel=address:' + event.value + ']')),
		                fx: {
		                    opacity: 'toggle'
		                }
		            }).css('display', 'block');
		        }	
		        
		   	// Executed when address is changed from inside the page that uses the plugin
		    }).change(function (event) {
		
		        $.address.title($.address.title().split(' | ')[0] + ' | ' + $('a[rel=address:' + event.value + ']').text());
		        
			// Executed when address is changed from browser or using the back & forward buttons
		    }).externalChange(function (event) {
		
		        $tabs.tabs('select', $('a[rel=address:' + event.value + ']').attr('href'));
		
		    });
		    
		    // Style tab contents
		    $(this).find('.tab-contents').each(function () {
		        $(this).find('.two-columns:last').css({
		            'padding-right': '0',
		            'margin-right': '0',
		            'border-right': 'none'
		        });
		        $(this).find('.three-columns:last').css({
		            'padding-right': '0',
		            'margin-right': '0',
		            'border-right': 'none'
		        });
		
		        if ($.browser.msie && $.browser.version === '6.0') {
		            $(this).find('.two-columns:last').css({
		                'float': 'none'
		            });
		            $(this).find('.three-columns:last').css({
		                'float': 'none'
		            });
		        }
		    });
		});
		$('.mod-tabs').css('visibility', 'visible');
	};
}(jQuery));

// Append to Global JS Initializations using jQuery
jQuery(document).ready(function () {
	Intel.mod.tabsMod();
});
