// JQUERY INIT ONLOAD
//Initialise jQuery/js items; also show items which are hidden with js turned off
    $(document).ready(function(){
        $('#category, #prodType').sSelect();
        $('ul.community-tabs-nav').css("display", "block");
        $('.community-tabs-panel > h4').css("display", "none");
        $('.community-tabs-panel').css("background-position", "0px 0px");
        $('#community-container > ul').tabs();
        $('#productbox-base').removeClass('jshide');
        
        $('#advert-pod').removeClass('advert-noscript');
        $('#news-pod').removeClass('news-noscript');
        $('#hp-banner-rhs').removeClass('hp-banner-rhs-noscript');
        $('#hp-banner-foot').removeClass('hp-banner-foot-noscript');
        $('#hp-container').removeClass('hp-container-noscript');
        
        $('#advert-pod').innerfade({
                        speed: 1000,
                        timeout: 8000,
                        type: 'random_start',
                        containerheight: '200px'
                    });
    if($.browser.msie && $.browser.version=="6.0") {
    
    } else {
    initResize();
    doResize();
}
        
    });    
    
// MT FUNCTIONS
function setProdType(){
   var divCollection = document.getElementsByTagName("li");
                foundme = "0";
        for (var i=0; i<divCollection.length; i++) {
            if(divCollection[i].getAttribute("class") == "hiLite" || divCollection[i].getAttribute("className") == "hiLite") {
                findMeText = divCollection[i].innerHTML;
                foundme = "1";
            } 
        }
                for (i=0; i <= document.getElementById('prodType').options.length - 1; i++)
{
  if(document.getElementById('prodType').options[i].text == findMeText){
             document.getElementById('prodType').selectedIndex=i; 
  }
}
}
// JQUERY FUNCTIONS
function initResize(){
    $(window).resize(function(){
        doResize();
    });
}
function doResize(){
    if ( $("#hp-container").width() <1090 ){
        
       if($.browser.msie && $.browser.version=="9.0") {
              $("#advert-pod").css({
        top: "-255px",
        marginLeft: "5px",
        width: "435px"
        });
            } else {
        $("#advert-pod").css({
        top: "-270px",
        marginLeft: "5px",
        width: "435px"
        });
                
                }
        $("#news-pod").css({
    clear: "both",
        top: "0",
        marginLeft: "463px",
        width: "363px"
        });
        
        $("#hp-banner-foot").css({
        display: "none"
            
        });
        
        $("#hp-banner-rhs").css({
        display: "block"
            
        });
        
        $("#hp-container").css({
        height: "1030px"
            
        });
    
    }else{
        if($.browser.msie && $.browser.version=="9.0") {
                  $("#advert-pod").css({
          top: "-260px",
          marginLeft: "835px",
          left: "0",
          width: "auto"
          });
                } else {
          $("#advert-pod").css({
          top: "-275px",
          marginLeft: "835px",
          left: "0",
          width: "auto"
          });
        }
        
        $("#news-pod").css({
            clear: "none",
        top: "-275px",
        marginLeft: "835px",
        width: "auto"
        });
        
    $("#hp-banner-rhs").css({
        display: "none"
            
        });
                $("#hp-banner-foot").css({
        display: "block"
            
        });
        $("#hp-container").css({
        height: "auto"
            
        });
    
        }
    }
// Product box
 
$(function(){
   var div = $('div.productbox-menu'),
               ul = $('ul.productbox-menu'),
               ulPadding = 15;
  var divWidth = div.width();
  div.css({overflow: 'hidden'});
  var lastLi = ul.find('li:last-child');
  div.mousemove(function(e){
    var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;
    var left = (e.pageX - div.offset().left) * (ulWidth-divWidth) / divWidth;
    div.scrollLeft(left);
  });
  
  $(".productbox-menu a").click(function(){
        $("#productbox-image img").hide().attr({"src": $(this).attr("title")});
                
                $("#productbox-text").html($(this).attr("rel"));
                                document.getElementById("productbox-link").href = $(this).attr("href");
        
            return false;
    });
    $("#productbox-image>img").load(function(){$("#productbox-image>img:hidden").fadeIn("slow")});
        
});
// Select box styling
(function($){
    //add class of js to html tag
    $('html').addClass('js');
    //create cross-browser indexOf
    Array.prototype.indexOf = function (obj, start) {
        for (var i = (start || 0); i < this.length; i++) {
            if (this[i] == obj) {
                return i;
            }
        }
    }
    
    //utility methods
    $.fn.extend({
        getSetSSValue: function(value){
                        if (value){
                            //set value and trigger change event
                            $(this).val(value).change();
                            return this;
                        } else {
                            return selText = $(this).find(':selected').text();
                        }
                    },
        resetSS: function(){
                        $this = $(this);
                        $this.next().remove();
                        //unbind all events and redraw
                        $this.unbind().sSelect();
                    }
    });
    $.fn.sSelect = function(options) {
        return this.each(function(){
             var defaults = {
                defaultText: 'Please select',
                animationSpeed: 0, //set speed of dropdown
                ddMaxHeight: '' //set css max-height value of dropdown
            };
            //initial variables
                       if($(this).text().indexOf('All Product Types') != -1){
                        productid = " id='jqproducttypes'";
                        } else {
                        productid = "";
                        }
                        
            var opts = $.extend(defaults, options),
                $input = $(this),                                
                $containerDivText = $('<div class="selectedTxt"></div>'),
                $containerDiv = $('<div class="newListSelected" tabindex="0"' + productid + '></div>'),
                $newUl = $('<ul class="newList"></ul>'),
                itemIndex = -1,
                currentIndex = -1,
                keys = [],
                prevKey = false,
                newListItems = '',
                prevented = false;
                
            //build new list
            $containerDiv.insertAfter($input);
            $containerDivText.prependTo($containerDiv);
            $newUl.appendTo($containerDiv);
            $input.hide();
        
            //test for optgroup
            if ($input.children('optgroup').length == 0){
                $input.children().each(function(i){
                    var option = $(this).text();
                    //add first letter of each word to array
                    keys.push(option.charAt(0).toLowerCase());
                    if ($(this).attr('selected') == true){
                        opts.defaultText = option;
                        currentIndex = i;
                    }
                    newListItems += '<li>'+option+'</li>';
                });
                //add new list items to ul
                $newUl.html(newListItems);
                newListItems = '';
                //cache list items object
                var $newLi = $newUl.children();
                                
            } else { //optgroup
                $input.children('optgroup').each(function(i){
                
                    var optionTitle = $(this).attr('label'),
                        $optGroup = $('<li class="newListOptionTitle">'+optionTitle+'</li>');
                        
                    $optGroup.appendTo($newUl);
                    var $optGroupList = $('<ul></ul>');
                    $optGroupList.appendTo($optGroup);
                    $(this).children().each(function(){
                        ++itemIndex;
                        var option = $(this).text();
                        //add first letter of each word to array
                        keys.push(option.charAt(0).toLowerCase());
                        if ($(this).attr('selected') == true){
                            opts.defaultText = option;
                            currentIndex = itemIndex;
                        }
                        newListItems += '<li>'+option+'</li>';
                    })
                    //add new list items to ul
                    $optGroupList.html(newListItems);
                    newListItems = '';
                });
                //cache list items object
                var $newLi = $newUl.find('ul li');
            
            }
            
            //get heights of new elements for use later
            var newUlHeight = $newUl.height()+3,
                containerHeight = $containerDiv.height()+3,
                newLiLength = $newLi.length;
        
            //check if a value is selected
            if (currentIndex != -1){
                navigateList(currentIndex, true);
            } else {
                //set placeholder text
                $containerDivText.text(opts.defaultText);
            }
            //decide if to place the new list above or below the drop-down
            function newUlPos(){
                var containerPosY = $containerDiv.offset().top,
                    docHeight = jQuery(window).height(),
                    scrollTop = jQuery(window).scrollTop();
                    //if height of list is greater then max height, set list height to max height value
                    if (newUlHeight > parseInt(opts.ddMaxHeight)) {
                        newUlHeight = parseInt(opts.ddMaxHeight);
                    }    
                containerPosY = containerPosY-scrollTop;
                if (containerPosY+newUlHeight >= docHeight){
                    $newUl.css({top: '-'+newUlHeight+'px', height: newUlHeight});
                    $input.onTop = true;
                } else {
                    $newUl.css({top: containerHeight+'px', height: newUlHeight});
                    $input.onTop = false;
                }
            }
            //run function on page load
            newUlPos();
            
            //run function on browser window resize
            $(window).resize(function(){
                newUlPos();
            });
            
            $(window).scroll(function(){
                newUlPos();
            });
            //positioning
            function positionFix(){
                $containerDiv.css('position','relative');
            }
            function positionHideFix(){
                $containerDiv.css('position','static');
            }
            
            $containerDivText.click(function(){
            
                if ($newUl.is(':visible')){
                    $newUl.hide();
                    positionHideFix()
                    return false;
                }
                $containerDiv.focus();
                //show list
                $newUl.slideDown(opts.animationSpeed);
                positionFix();
                //scroll list to selected item
                $newUl.scrollTop($input.liOffsetTop);
            });
            
            $newLi.hover(
              function (e) {
                var $hoveredLi = $(e.target);
                $hoveredLi.addClass('newListHover');
              },
              function (e) {
                var $hoveredLi = $(e.target);
                $hoveredLi.removeClass('newListHover');
              }
            );
            $newLi.click(function(e){
                var $clickedLi = $(e.target);
                //update counter
                currentIndex = $newLi.index($clickedLi);
                //remove all hilites, then add hilite to selected item
                prevented = true;
                navigateList(currentIndex);
                $newUl.hide();
                $containerDiv.css('position','static');//ie
            });
            function navigateList(currentIndex, init){
                //get offsets
                var containerOffsetTop = $containerDiv.offset().top,
                    liOffsetTop = $newLi.eq(currentIndex).offset().top,
                    ulScrollTop = $newUl.scrollTop();
                
                //get distance of current li from top of list                
                if ($input.onTop == true){
                    //if list is above select box, add max height value
                    $input.liOffsetTop = (((liOffsetTop-containerOffsetTop)-containerHeight)+ulScrollTop)+parseInt(opts.ddMaxHeight);
                } else {
                    $input.liOffsetTop = ((liOffsetTop-containerOffsetTop)-containerHeight)+ulScrollTop;
                }
                
                //scroll list to focus on current item
                $newUl.scrollTop($input.liOffsetTop);
                
                $newLi.removeClass('hiLite')
                    .eq(currentIndex)
                    .addClass('hiLite');
                var text = $newLi.eq(currentIndex).text();
                //page load
                if (init == true){
                    $input.val(text);
                    $containerDivText.text(text);
                    return false;
                }
                $input.val(text).change();
                $containerDivText.text(text);
            };
            $input.change(function(event){
                    $targetInput = $(event.target);
                    //stop change function from firing 
                    if (prevented == true){
                        prevented = false;
                        return false;
                    }
                    $currentOpt = $targetInput.find(':selected');
                    currentIndex = $targetInput.find('option').index($currentOpt);
                    navigateList(currentIndex, true);
                }
            );
            
            //handle up and down keys
            function keyPress(element) {
                //when keys are pressed
                element.onkeydown = function(e){
                    if (e == null) { //ie
                        var keycode = event.keyCode;
                    } else { //everything else
                        var keycode = e.which;
                    }
                    
                    //prevent change function from firing
                    prevented = true;
                    switch(keycode)
                    {
                    case 40: //down
                    case 39: //right
                        incrementList();
                        return false;
                        break;
                    case 38: //up
                    case 37: //left
                        decrementList();
                        return false;
                        break;
                    case 33: //page up
                    case 36: //home
                        gotoFirst();
                        return false;
                        break;
                    case 34: //page down
                    case 35: //end
                        gotoLast();
                        return false;
                        break;
                    case 13:
                    case 27:
                        $newUl.hide();
                        positionHideFix();
                        return false;
                        break;
                    }
                    //check for keyboard shortcuts
                    keyPressed = String.fromCharCode(keycode).toLowerCase();
                    var currentKeyIndex = keys.indexOf(keyPressed);
                    if (typeof currentKeyIndex != 'undefined') { //if key code found in array
                        ++currentIndex;
                        currentIndex = keys.indexOf(keyPressed, currentIndex); //search array from current index
                        if (currentIndex == -1 || currentIndex == null || prevKey != keyPressed) currentIndex = keys.indexOf(keyPressed); //if no entry was found or new key pressed search from start of array
                        navigateList(currentIndex);
                        //store last key pressed
                        prevKey = keyPressed;
                        return false;
                    }
                }
            }
            function incrementList(){
                if (currentIndex < (newLiLength-1)) {
                    ++currentIndex;
                    navigateList(currentIndex);
                }
            }
            function decrementList(){
                if (currentIndex > 0) {
                    --currentIndex;
                    navigateList(currentIndex);
                }
            }
            function gotoFirst(){
                currentIndex = 0;
                navigateList(currentIndex);
            }
            
            function gotoLast(){
                currentIndex = newLiLength-1;
                navigateList(currentIndex);
            }
            $containerDiv.click(function(){
                keyPress(this);
            });
            $containerDiv.focus(function(){
                $(this).addClass('newListSelFocus');
                keyPress(this);
            });
            
            //hide list on blur
            $containerDiv.blur(function(){
               $(this).removeClass('newListSelFocus');
               $newUl.hide();
               positionHideFix();
            });
            //add classes on hover
            $containerDivText.hover(function(e) {
                var $hoveredTxt = $(e.target);
                $hoveredTxt.parent().addClass('newListSelHover');
              }, 
              function(e) {
                var $hoveredTxt = $(e.target);
                $hoveredTxt.parent().removeClass('newListSelHover');
              }
            );
            //reset left property and hide
            $newUl.css('left','0').hide();
            
        });
      
    };
})(jQuery);
/*
 * jQuery UI - ABRIDGED
 *
 */
;(function($) {
function getter(namespace, plugin, method, args) {
    function getMethods(type) {
        var methods = $[namespace][plugin][type] || [];
        return (typeof methods == 'string' ? methods.split(/,?\s+/) : methods);
    }
    
    var methods = getMethods('getter');
    if (args.length == 1 && typeof args[0] == 'string') {
        methods = methods.concat(getMethods('getterSetter'));
    }
    return ($.inArray(method, methods) != -1);
}
$.widget = function(name, prototype) {
    var namespace = name.split(".")[0];
    name = name.split(".")[1];
    
    // create plugin method
    $.fn[name] = function(options) {
        var isMethodCall = (typeof options == 'string'),
            args = Array.prototype.slice.call(arguments, 1);
        
        // prevent calls to internal methods
        if (isMethodCall && options.substring(0, 1) == '_') {
            return this;
        }
        
        // handle getter methods
        if (isMethodCall && getter(namespace, name, options, args)) {
            var instance = $.data(this[0], name);
            return (instance ? instance[options].apply(instance, args)
                : undefined);
        }
        
        // handle initialization and non-getter methods
        return this.each(function() {
            var instance = $.data(this, name);
            
            // constructor
            (!instance && !isMethodCall &&
                $.data(this, name, new $[namespace][name](this, options)));
            
            // method call
            (instance && isMethodCall && $.isFunction(instance[options]) &&
                instance[options].apply(instance, args));
        });
    };
    
    // create widget constructor
    $[namespace] = $[namespace] || {};
    $[namespace][name] = function(element, options) {
        var self = this;
        
        this.widgetName = name;
        this.widgetEventPrefix = $[namespace][name].eventPrefix || name;
        this.widgetBaseClass = namespace + '-' + name;
        
        this.options = $.extend({},
            $.widget.defaults,
            $[namespace][name].defaults,
            $.metadata && $.metadata.get(element)[name],
            options);
        
        this.element = $(element)
            .bind('setData.' + name, function(e, key, value) {
                return self._setData(key, value);
            })
            .bind('getData.' + name, function(e, key) {
                return self._getData(key);
            })
            .bind('remove', function() {
                return self.destroy();
            });
        
        this._init();
    };
    
    // add widget prototype
    $[namespace][name].prototype = $.extend({}, $.widget.prototype, prototype);
    
    // TODO: merge getter and getterSetter properties from widget prototype
    // and plugin prototype
    $[namespace][name].getterSetter = 'option';
};
$.widget.prototype = {
    _init: function() {},
    destroy: function() {
        this.element.removeData(this.widgetName);
    },
    
    option: function(key, value) {
        var options = key,
            self = this;
        
        if (typeof key == "string") {
            if (value === undefined) {
                return this._getData(key);
            }
            options = {};
            options[key] = value;
        }
        
        $.each(options, function(key, value) {
            self._setData(key, value);
        });
    },
    _getData: function(key) {
        return this.options[key];
    },
    _setData: function(key, value) {
        this.options[key] = value;
        
        if (key == 'disabled') {
            this.element[value ? 'addClass' : 'removeClass'](
                this.widgetBaseClass + '-disabled');
        }
    },
    
    enable: function() {
        this._setData('disabled', false);
    },
    disable: function() {
        this._setData('disabled', true);
    },
    
    _trigger: function(type, e, data) {
        var eventName = (type == this.widgetEventPrefix
            ? type : this.widgetEventPrefix + type);
        e = e  || $.event.fix({ type: eventName, target: this.element[0] });
        return this.element.triggerHandler(eventName, [e, data], this.options[type]);
    }
};
$.widget.defaults = {
    disabled: false
};
})(jQuery);
/*
 * jQuery UI Tabs @VERSION
 *
 * Copyright (c) 2007, 2008 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 * http://docs.jquery.com/UI/Tabs
 *
 * Depends:
 *    ui.core.js
 */
(function($) {
$.widget("ui.tabs", {
    _init: function() {
        // create tabs
        this._tabify(true);
    },
    _setData: function(key, value) {
        if ((/^selected/).test(key))
            this.select(value);
        else {
            this.options[key] = value;
            this._tabify();
        }
    },
    length: function() {
        return this.$tabs.length;
    },
    _tabId: function(a) {
        return a.title && a.title.replace(/\s/g, '_').replace(/[^A-Za-z0-9\-_:\.]/g, '')
            || this.options.idPrefix + $.data(a);
    },
    ui: function(tab, panel) {
        return {
            options: this.options,
            tab: tab,
            panel: panel,
            index: this.$tabs.index(tab)
        };
    },
    _sanitizeSelector: function(hash) {
        return hash.replace(/:/g, '\\:'); // we need this because an id may contain a ":"
    },
    _cookie: function() {
        var cookie = this.cookie || (this.cookie = 'community-tabs-' + $.data(this.element[0]));
        return $.cookie.apply(null, [cookie].concat($.makeArray(arguments)));
    },
    _tabify: function(init) {
        
        this.$lis = $('li:has(a[href])', this.element);
        this.$tabs = this.$lis.map(function() { return $('a', this)[0]; });
        this.$panels = $([]);
        
        var self = this, o = this.options;
        
        this.$tabs.each(function(i, a) {
            // inline tab
            if (a.hash && a.hash.replace('#', '')) // Safari 2 reports '#' for an empty hash
                self.$panels = self.$panels.add(self._sanitizeSelector(a.hash));
            // remote tab
            else if ($(a).attr('href') != '#') { // prevent loading the page itself if href is just "#"
                $.data(a, 'href.tabs', a.href); // required for restore on destroy
                $.data(a, 'load.tabs', a.href); // mutable
                var id = self._tabId(a);
                a.href = '#' + id;
                var $panel = $('#' + id);
                if (!$panel.length) {
                    $panel = $(o.panelTemplate).attr('id', id).addClass(o.panelClass)
                        .insertAfter(self.$panels[i - 1] || self.element);
                    $panel.data('destroy.tabs', true);
                }
                self.$panels = self.$panels.add($panel);
            }
            // invalid tab href
            else
                o.disabled.push(i + 1);
        });
        
        // initialization from scratch
        if (init) {
            
            // attach necessary classes for styling if not present
            this.element.addClass(o.navClass);
            this.$panels.addClass(o.panelClass);
            
            // Selected tab
            // use "selected" option or try to retrieve:
            // 1. from fragment identifier in url
            // 2. from cookie
            // 3. from selected class attribute on <li>
            if (o.selected === undefined) {
                if (location.hash) {
                    this.$tabs.each(function(i, a) {
                        if (a.hash == location.hash) {
                            o.selected = i;
                            return false; // break
                        }
                    });
                }
                else if (o.cookie) {
                    var index = parseInt(self._cookie(), 10);
                    if (index && self.$tabs[index]) o.selected = index;
                }
                else if (self.$lis.filter('.' + o.selectedClass).length)
                    o.selected = self.$lis.index( self.$lis.filter('.' + o.selectedClass)[0] );
            }
            o.selected = o.selected === null || o.selected !== undefined ? o.selected : 0; // first tab selected by default
            
            // Take disabling tabs via class attribute from HTML
            // into account and update option properly.
            // A selected tab cannot become disabled.
            o.disabled = $.unique(o.disabled.concat(
                $.map(this.$lis.filter('.' + o.disabledClass),
                    function(n, i) { return self.$lis.index(n); } )
            )).sort();
            if ($.inArray(o.selected, o.disabled) != -1)
                o.disabled.splice($.inArray(o.selected, o.disabled), 1);
            
            // highlight selected tab
            this.$panels.addClass(o.hideClass);
            this.$lis.removeClass(o.selectedClass);
            if (o.selected !== null) {
                this.$panels.eq(o.selected).removeClass(o.hideClass);
                var classes = [o.selectedClass];
                if (o.deselectable) classes.push(o.deselectableClass);
                this.$lis.eq(o.selected).addClass(classes.join(' '));
                
                // seems to be expected behavior that the show callback is fired
                var onShow = function() {
                    self._trigger('show', null,
                        self.ui(self.$tabs[o.selected], self.$panels[o.selected]));
                };
                
                // load if remote tab
                if ($.data(this.$tabs[o.selected], 'load.tabs'))
                    this.load(o.selected, onShow);
                // just trigger show event
                else onShow();
            }
            
            // clean up to avoid memory leaks in certain versions of IE 6
            $(window).bind('unload', function() {
                self.$tabs.unbind('.tabs');
                self.$lis = self.$tabs = self.$panels = null;
            });
            //randomize communty tabs 
            var comtab = new Array ();
            comtab[0] = "community-Embedded";
            comtab[1] = "community-Multimedia";
            comtab[2] = "community-Smart-Connected-Devices";
            comtab[3] = "community-Software-Enablement";
            comtab[4] = "community-Connected-Community";
            var r = Math.floor(5*Math.random())
               
            for(i=0;i<comtab.length;i++) {     
                if (r == i){
                    document.getElementById(comtab[i]).className = "community-tabs-panel";
                } else {
                    document.getElementById(comtab[i]).className = "community-tabs-panel community-tabs-hide";
                }
            }            
            var tabs, arow;
            var ul = document.getElementById("community-tabs-nav");
            lis = ul.getElementsByTagName("li");
            for(var i=0;i<lis.length;i++) {
                li = lis.item(i);
                liNodeName = li.nodeName;
                if(liNodeName.toLowerCase() == "li") {
                    if(r == i) {
                        li.className = "community-tabs-selected";
                    } else {
                    li.className = "";
                    }
                }
            }
            
        }
        // update selected after add/remove
        else
            o.selected = this.$lis.index( this.$lis.filter('.' + o.selectedClass)[0] );
        
        // set or update cookie after init and add/remove respectively
        if (o.cookie) this._cookie(o.selected, o.cookie);
        
        // disable tabs
        for (var i = 0, li; li = this.$lis[i]; i++)
            $(li)[$.inArray(i, o.disabled) != -1 && !$(li).hasClass(o.selectedClass) ? 'addClass' : 'removeClass'](o.disabledClass);
        
        // reset cache if switching from cached to not cached
        if (o.cache === false) this.$tabs.removeData('cache.tabs');
        
        // set up animations
        var hideFx, showFx;
        if (o.fx) {
            if (o.fx.constructor == Array) {
                hideFx = o.fx[0];
                showFx = o.fx[1];
            }
            else hideFx = showFx = o.fx;
        }
        
        // Reset certain styles left over from animation
        // and prevent IE's ClearType bug...
        function resetStyle($el, fx) {
            $el.css({ display: '' });
            if ($.browser.msie && fx.opacity) $el[0].style.removeAttribute('filter');
        }
        // Show a tab...
        var showTab = showFx ?
            function(clicked, $show) {
                $show.animate(showFx, showFx.duration || 'normal', function() {
                    $show.removeClass(o.hideClass);
                    resetStyle($show, showFx);
                    self._trigger('show', null, self.ui(clicked, $show[0]));
                });
            } :
            function(clicked, $show) {
                $show.removeClass(o.hideClass);
                self._trigger('show', null, self.ui(clicked, $show[0]));
            };
        
        // Hide a tab, $show is optional...
        var hideTab = hideFx ? 
            function(clicked, $hide, $show) {
                $hide.animate(hideFx, hideFx.duration || 'normal', function() {
                    $hide.addClass(o.hideClass);
                    resetStyle($hide, hideFx);
                    if ($show) showTab(clicked, $show, $hide);
                });
            } :
            function(clicked, $hide, $show) {
                $hide.addClass(o.hideClass);
                if ($show) showTab(clicked, $show);
            };
        
        // Switch a tab...
        function switchTab(clicked, $li, $hide, $show) {
            var classes = [o.selectedClass];
            if (o.deselectable) classes.push(o.deselectableClass);
            $li.addClass(classes.join(' ')).siblings().removeClass(classes.join(' '));
            hideTab(clicked, $hide, $show);
        }
        
        // attach tab event handler, unbind to avoid duplicates from former tabifying...
        this.$tabs.unbind('.tabs').bind(o.event + '.tabs', function() {
            
            //var trueClick = e.clientX; // add to history only if true click occured, not a triggered click
            var $li = $(this).parents('li:eq(0)'),
                $hide = self.$panels.filter(':visible'),
                $show = $(self._sanitizeSelector(this.hash));
            
            // If tab is already selected and not deselectable or tab disabled or 
            // or is already loading or click callback returns false stop here.
            // Check if click handler returns false last so that it is not executed
            // for a disabled or loading tab!
            if (($li.hasClass(o.selectedClass) && !o.deselectable)
                || $li.hasClass(o.disabledClass)
                || $(this).hasClass(o.loadingClass)
                || self._trigger('select', null, self.ui(this, $show[0])) === false
                ) {
                this.blur();
                return false;
            }
            
            o.selected = self.$tabs.index(this);
            
            // if tab may be closed
            if (o.deselectable) {
                if ($li.hasClass(o.selectedClass)) {
                    self.options.selected = null;
                    $li.removeClass([o.selectedClass, o.deselectableClass].join(' '));
                    self.$panels.stop();
                    hideTab(this, $hide);
                    this.blur();
                    return false;
                } else if (!$hide.length) {
                    self.$panels.stop();
                    var a = this;
                    self.load(self.$tabs.index(this), function() {
                        $li.addClass([o.selectedClass, o.deselectableClass].join(' '));
                        showTab(a, $show);
                    });
                    this.blur();
                    return false;
                }
            }
            
            if (o.cookie) self._cookie(o.selected, o.cookie);
            
            // stop possibly running animations
            self.$panels.stop();
            
            // show new tab
            if ($show.length) {
                var a = this;
                self.load(self.$tabs.index(this), $hide.length ? 
                    function() {
                        switchTab(a, $li, $hide, $show);
                    } :
                    function() {
                        $li.addClass(o.selectedClass);
                        showTab(a, $show);
                    }
                );
            } else
                throw 'jQuery UI Tabs: Mismatching fragment identifier.';
                
            // Prevent IE from keeping other link focussed when using the back button
            // and remove dotted border from clicked link. This is controlled via CSS
            // in modern browsers; blur() removes focus from address bar in Firefox
            // which can become a usability and annoying problem with tabs('rotate').
            if ($.browser.msie) this.blur();
            
            return false;
            
        });
        
        // disable click if event is configured to something else
        if (o.event != 'click') this.$tabs.bind('click.tabs', function(){return false;});
        
    },
    add: function(url, label, index) {
        if (index == undefined)
            index = this.$tabs.length; // append by default
        
        var o = this.options;
        var $li = $(o.tabTemplate.replace(/#\{href\}/g, url).replace(/#\{label\}/g, label));
        $li.data('destroy.tabs', true);
        
        var id = url.indexOf('#') == 0 ? url.replace('#', '') : this._tabId( $('a:first-child', $li)[0] );
        
        // try to find an existing element before creating a new one
        var $panel = $('#' + id);
        if (!$panel.length) {
            $panel = $(o.panelTemplate).attr('id', id)
                .addClass(o.hideClass)
                .data('destroy.tabs', true);
        }
        $panel.addClass(o.panelClass);
        if (index >= this.$lis.length) {
            $li.appendTo(this.element);
            $panel.appendTo(this.element[0].parentNode);
        } else {
            $li.insertBefore(this.$lis[index]);
            $panel.insertBefore(this.$panels[index]);
        }
        
        o.disabled = $.map(o.disabled,
            function(n, i) { return n >= index ? ++n : n });
        
        this._tabify();
        
        if (this.$tabs.length == 1) {
            $li.addClass(o.selectedClass);
            $panel.removeClass(o.hideClass);
            var href = $.data(this.$tabs[0], 'load.tabs');
            if (href)
                this.load(index, href);
        }
        
        // callback
        this._trigger('add', null, this.ui(this.$tabs[index], this.$panels[index]));
    },
    remove: function(index) {
        var o = this.options, $li = this.$lis.eq(index).remove(),
            $panel = this.$panels.eq(index).remove();
        
        // If selected tab was removed focus tab to the right or
        // in case the last tab was removed the tab to the left.
        if ($li.hasClass(o.selectedClass) && this.$tabs.length > 1)
            this.select(index + (index + 1 < this.$tabs.length ? 1 : -1));
        
        o.disabled = $.map($.grep(o.disabled, function(n, i) { return n != index; }),
            function(n, i) { return n >= index ? --n : n });
        
        this._tabify();
        
        // callback
        this._trigger('remove', null, this.ui($li.find('a')[0], $panel[0]));
    },
    enable: function(index) {
        var o = this.options;
        if ($.inArray(index, o.disabled) == -1)
            return;
        
        var $li = this.$lis.eq(index).removeClass(o.disabledClass);
        if ($.browser.safari) { // fix disappearing tab (that used opacity indicating disabling) after enabling in Safari 2...
            $li.css('display', 'inline-block');
            setTimeout(function() {
                $li.css('display', 'block');
            }, 0);
        }
        
        o.disabled = $.grep(o.disabled, function(n, i) { return n != index; });
        
        // callback
        this._trigger('enable', null, this.ui(this.$tabs[index], this.$panels[index]));
    },
    disable: function(index) {
        var self = this, o = this.options;
        if (index != o.selected) { // cannot disable already selected tab
            this.$lis.eq(index).addClass(o.disabledClass);
            
            o.disabled.push(index);
            o.disabled.sort();
            
            // callback
            this._trigger('disable', null, this.ui(this.$tabs[index], this.$panels[index]));
        }
    },
    select: function(index) {
        // TODO make null as argument work
        if (typeof index == 'string')
            index = this.$tabs.index( this.$tabs.filter('[href$=' + index + ']')[0] );
        this.$tabs.eq(index).trigger(this.options.event + '.tabs');
    },
    load: function(index, callback) { // callback is for internal usage only
        
        var self = this, o = this.options, $a = this.$tabs.eq(index), a = $a[0],
                bypassCache = callback == undefined || callback === false, url = $a.data('load.tabs');
        
        callback = callback || function() {};
        
        // no remote or from cache - just finish with callback
        if (!url || !bypassCache && $.data(a, 'cache.tabs')) {
            callback();
            return;
        }
        
        // load remote from here on
        
        var inner = function(parent) {
            var $parent = $(parent), $inner = $parent.find('*:last');
            return $inner.length && $inner.is(':not(img)') && $inner || $parent;
        };
        var cleanup = function() {
            self.$tabs.filter('.' + o.loadingClass).removeClass(o.loadingClass)
                    .each(function() {
                        if (o.spinner)
                            inner(this).parent().html(inner(this).data('label.tabs'));
                    });
            self.xhr = null;
        };
        
        if (o.spinner) {
            var label = inner(a).html();
            inner(a).wrapInner('<em></em>')
                .find('em').data('label.tabs', label).html(o.spinner);
        }
        
        var ajaxOptions = $.extend({}, o.ajaxOptions, {
            url: url,
            success: function(r, s) {
                $(self._sanitizeSelector(a.hash)).html(r);
                cleanup();
                
                if (o.cache)
                    $.data(a, 'cache.tabs', true); // if loaded once do not load them again
                
                // callbacks
                self._trigger('load', null, self.ui(self.$tabs[index], self.$panels[index]));
                try {
                    o.ajaxOptions.success(r, s);
                }
                catch (e) {}
                
                // This callback is required because the switch has to take
                // place after loading has completed. Call last in order to 
                // fire load before show callback...
                callback();
            }
        });
        if (this.xhr) {
            // terminate pending requests from other tabs and restore tab label
            this.xhr.abort();
            cleanup();
        }
        $a.addClass(o.loadingClass);
        self.xhr = $.ajax(ajaxOptions);
    },
    url: function(index, url) {
        this.$tabs.eq(index).removeData('cache.tabs').data('load.tabs', url);
    },
    destroy: function() {
        var o = this.options;
        this.element.unbind('.tabs')
            .removeClass(o.navClass).removeData('tabs');
        this.$tabs.each(function() {
            var href = $.data(this, 'href.tabs');
            if (href)
                this.href = href;
            var $this = $(this).unbind('.tabs');
            $.each(['href', 'load', 'cache'], function(i, prefix) {
                $this.removeData(prefix + '.tabs');
            });
        });
        this.$lis.add(this.$panels).each(function() {
            if ($.data(this, 'destroy.tabs'))
                $(this).remove();
            else
                $(this).removeClass([o.selectedClass, o.deselectableClass,
                    o.disabledClass, o.panelClass, o.hideClass].join(' '));
        });
        if (o.cookie)
            this._cookie(null, o.cookie);
    }
});
$.extend($.ui.tabs, {
    version: '@VERSION',
    getter: 'length',
    defaults: {
        // basic setup
        deselectable: false,
        event: 'click',
        disabled: [],
        cookie: null, // e.g. { expires: 7, path: '/', domain: 'jquery.com', secure: true }
        // Ajax
        spinner: 'Loading&#8230;',
        cache: false,
        idPrefix: 'community-tabs-',
        ajaxOptions: null,
        // animations
        fx: null, // e.g. { height: 'toggle', opacity: 'toggle', duration: 200 }
        // templates
        tabTemplate: '<li><a href="#{href}"><span>#{label}</span></a></li>',
        panelTemplate: '<div></div>',
        // CSS class names
        navClass: 'community-tabs-nav',
        selectedClass: 'community-tabs-selected',
        deselectableClass: 'community-tabs-deselectable',
        disabledClass: 'community-tabs-disabled',
        panelClass: 'community-tabs-panel',
        hideClass: 'community-tabs-hide',
        loadingClass: 'community-tabs-loading'
    }
});
/*
 * Tabs Extensions
 */
/*
 * Rotate
 */
$.extend($.ui.tabs.prototype, {
    rotation: null,
    rotate: function(ms, continuing) {
        
        continuing = continuing || false;
        
        var self = this, t = this.options.selected;
        
        function start() {
            self.rotation = setInterval(function() {
                t = ++t < self.$tabs.length ? t : 0;
                self.select(t);
            }, ms);
        }
        
        function stop(e) {
            if (!e || e.clientX) { // only in case of a true click
                clearInterval(self.rotation);
            }
        }
        
        // start interval
        if (ms) {
            start();
            if (!continuing)
                this.$tabs.bind(this.options.event + '.tabs', stop);
            else
                this.$tabs.bind(this.options.event + '.tabs', function() {
                    stop();
                    t = self.options.selected;
                    start();
                });
        }
        // stop interval
        else {
            stop();
            this.$tabs.unbind(this.options.event + '.tabs', stop);
        }
    }
});
})(jQuery);
/* =========================================================
// jquery.innerfade.js
// Rotating adverts w/ fade
// ========================================================= */
(function($) {
    $.fn.innerfade = function(options) {
        return this.each(function() {   
            $.innerfade(this, options);
        });
    };
    $.innerfade = function(container, options) {
        var settings = {
            'animationtype':    'fade',
            'speed':            'normal',
            'type':             'sequence',
            'timeout':          2000,
            'containerheight':  'auto',
            'runningclass':     'innerfade',
            'children':         null
        };
        if (options)
            $.extend(settings, options);
        if (settings.children === null)
            var elements = $(container).children();
        else
            var elements = $(container).children(settings.children);
        if (elements.length > 1) {
            $(container).css('position', 'relative').css('height', settings.containerheight).addClass(settings.runningclass);
            for (var i = 0; i < elements.length; i++) {
                $(elements[i]).css('z-index', String(elements.length-i)).css('position', 'absolute').hide();
            };
            if (settings.type == "sequence") {
                setTimeout(function() {
                    $.innerfade.next(elements, settings, 1, 0);
                }, settings.timeout);
                $(elements[0]).show();
            } else if (settings.type == "random") {
                    var last = Math.floor ( Math.random () * ( elements.length ) );
                setTimeout(function() {
                    do { 
                                                current = Math.floor ( Math.random ( ) * ( elements.length ) );
                                        } while (last == current );             
                                        $.innerfade.next(elements, settings, current, last);
                }, settings.timeout);
                                  $(elements[last]).show();
                        } else if ( settings.type == 'random_start' ) {
                                settings.type = 'sequence';
                                var current = Math.floor ( Math.random () * ( elements.length ) );
                                                                document.getElementById("adlink").href = $(elements[current]).attr("class");    
                                setTimeout(function(){
                                    $.innerfade.next(elements, settings, (current + 1) %  elements.length, current);
                                }, settings.timeout);
                                $(elements[current]).show();
                        }    else {
                            alert('Innerfade-Type must either be \'sequence\', \'random\' or \'random_start\'');
                        }
                }
    };
    $.innerfade.next = function(elements, settings, current, last) {
        if (settings.animationtype == 'slide') {
            $(elements[last]).slideUp(settings.speed);
            $(elements[current]).slideDown(settings.speed);
        } else if (settings.animationtype == 'fade') {
            $(elements[last]).fadeOut(settings.speed);
                        document.getElementById("adlink").href = $(elements[current]).attr("class");
            $(elements[current]).fadeIn(settings.speed, function() {
                            removeFilter($(this)[0]);
                        });
        } else
            alert('Innerfade-animationtype must either be \'slide\' or \'fade\'');
        if (settings.type == "sequence") {
            if ((current + 1) < elements.length) {
                current = current + 1;
                last = current - 1;
            } else {
                current = 0;
                last = elements.length - 1;
            }
        } else if (settings.type == "random") {
            last = current;
            while (current == last)
                current = Math.floor(Math.random() * elements.length);
        } else
            alert('Innerfade-Type must either be \'sequence\', \'random\' or \'random_start\'');
        setTimeout((function() {
            $.innerfade.next(elements, settings, current, last);
        }), settings.timeout);
    };
})(jQuery);
// **** remove Opacity-Filter in ie ****
function removeFilter(element) {
    if(element.style.removeAttribute){
        element.style.removeAttribute('filter');
    }
}
