(function($) {
    $.fn.initTabs = function() {
        removeHref();
        if ($('a[rel=default]').length > 0) {
            $('a[rel=default]').each(function() { toggleTabs($(this).parent().attr('id')); });
        }
        function removeHref() {
            //For the country selector tabs
            $('.tabs li').each(function() {
                UpdateClick(this, 'selected');
            });

            //For the product item tabs
            $('.tab-box-items li').each(function() {
                UpdateClick(this, 'selected');
            });

            //For the campaign item tabs
            $('.newtabs li').each(function() {
                UpdateClick(this, 'active');
            });
        }

        function UpdateClick(obj, s) {
            var id = $(obj).attr('id');
            createClickFunction($(obj), id, s);
            $('a', obj).attr('href', '');
        }

        function createClickFunction(t, id, s) {
            $(t).click(function() {
                toggleTabs(id, s);
                return false;
            }).mouseover(function() {
                $(this).css({ cursor: 'pointer' });
            });
        }

        function toggleTabs(id, s) {

            var parentID = $('#' + id).parent();

            $('li', parentID).each(function() {
                var tabID = $(this).attr('id');
                if (tabID == id) {
                    $(this).addClass(s);
                    $('#' + tabID + '-content').removeClass('hide').addClass('show');
                }
                else {
                    $(this).removeClass(s);
                    $('#' + tabID + '-content').removeClass('show').addClass('hide');
                }
            });

            // Set the height of the rounded corner content blocks
            // to fix the left hand border in IE
            // CSS is set to height 100% but IE doesn't refresh its height
            // when the tab content changes.
            $('.content').each(function() {
                var height = $(this).height();
                $(this).contents().find('.rc_top:eq(0)').height(height);
            });
        }
    };
})(jQuery);
