//Override jquery fade functions

jQuery.fn.fadeIn = function(speed, callback) { 
    return this.animate({opacity: 'show'}, speed, function() { 
        if (jQuery.browser.msie)  
            this.style.removeAttribute('filter');  
        if (jQuery.isFunction(callback)) 
            callback();  
    }); 
}; 
 
jQuery.fn.fadeOut = function(speed, callback) { 
    return this.animate({opacity: 'hide'}, speed, function() { 
        if (jQuery.browser.msie)  
            this.style.removeAttribute('filter');  
        if (jQuery.isFunction(callback)) 
            callback();  
    }); 
}; 
 
jQuery.fn.fadeTo = function(speed,to,callback) { 
    return this.animate({opacity: to}, speed, function() { 
        if (to == 1 && jQuery.browser.msie)  
            this.style.removeAttribute('filter');  
        if (jQuery.isFunction(callback)) 
            callback();  
    }); 
}; 
  


$(document).ready(function()
{
    if ($.browser.msie) 
    {
        fixIEHover();
    }
    fixInputClasses();
    
    //Markets Teaser on most pages
    $('#marketSlider').loopedSlider(
    {
        container: '.marketContainer',
        slides: '.slides',
        pagination: '.pagination',
        containerClick: false, // Click container for next slide
        autoStart: 6000, // Set to positive number for auto interval and interval time
        slidespeed: 600, // Speed of slide animation
        fadespeed: 600, // Speed of fade animation
        autoHeight: false // Set to positive number for auto height and animation speed
    });
    $('.executiveTeam a').each(function()
    {
        $(this).next('p').height($(this).next('p').height()).css('display', 'none')
        $(this).toggle(function()
        {
        
            $(this).removeClass('closed');
            $(this).addClass('open');
            $(this).next('p').slideDown(500);
            return false;
        }, function()
        {
            $(this).removeClass('open');
            $(this).addClass('closed');
            $(this).next('p').slideUp(500);
            return false;
        })
    })
    $('.executiveTeam').fadeTo(500, 1);
	
    
    
    $('#marketsSection').tabs(
    {
        fxFade: true,
        fxSpeed: 500
    });
    $('#marketsSection .tabEnable').each(function()
    {
        $(this).click(function()
        {
			activateTab('#marketsSection', Number($(this).attr('rel')))
			return false;
        })
    });
	$('#productsOffered').tabs({
        fxFade: true,
        fxSpeed: 500
    });  
})

function activateTab(container, number)
{
	$(container).triggerTab(number)
}

function fixIEHover()
{
    $('input[type=button]').hover(function()
    {
        $(this).addClass('hover');
    }, function()
    {
        $(this).removeClass('hover');
        $(this).removeClass('active');
    })
    $('input[type=button]').mousedown(function()
    {
        $(this).addClass('active');
    })
    $('input[type=button]').mouseup(function()
    {
        $(this).removeClass('active');
    })
    
}

//Temporary fix
function fixInputClasses()
{
    $('input[type=text]').addClass('textbox');
    $('select').addClass('dropdownList');
}
