$(document).ready(function () {
	// changes the search label on click
	(function searchlabel() {
		var searchb = $('#CAT_Search');
		var defaultText = "search";
		searchb.onblur = function () { 
			if (this.value == '') { this.value = defaultText; }
		}
		searchb.onfocus = function () {
			if (this.value == defaultText) { this.value = ''; }
		}
		if (searchb.value == "") {
			searchb.value = defaultText;
		}
	}) ();
	
	$('.toolTip').hover(
		function() {
			ob = $(this);
        	this.tip = this.title;
            
			ob.append(
			 '<div class="toolTipWrapper">'
				+'<div class="toolTipTop" />'
				+'<div class="toolTipMid">'
				  +this.tip
				+'</div>'
				+'<div class="toolTipBtm" />'
			  +'</div>'
			);
			this.title = "";
			this.width = ob.width();
			ob.find('.toolTipWrapper').css({left:this.width-162});
			
			if ($.browser.chrome || $.browser.msie) {
				$('.toolTipWrapper').show();
			} else {
				$('.toolTipWrapper').fadeIn(300);
			}
		},
		function() {
			if ($.browser.chrome || $.browser.msie) {
				$('.toolTipWrapper').hide();
			} else {
				$('.toolTipWrapper').fadeOut(600);
			}
			$(this).children().remove();
			this.title = this.tip;
		}
	);

});

// remove bc base mouse events
$(window).load(function () {
	$('.decorate ul li').each(function () {
		this.onmouseover = null;
		this.onmouseout  = null;
		
		var ob = $(this);
	
		ob.hover(
			function () { ob.addClass('hover') },
			function () { ob.removeClass('hover') }
		);
	});
});


$slideshow = {
    context: false,
    tabs: false,
    timeout: 6000,      // time before next slide appears (in ms)
    slideSpeed: 1000,   // time it takes to slide in each slide (in ms)
    tabSpeed: 300,      // time it takes to slide in each slide (in ms) when clicking through tabs
    fx: 'fade',   // the slide effect to use
    
    init: function() {
        // set the context to help speed up selectors/improve performance
        this.context = $('#testimonial-scroller');
        
        // set tabs to current hard coded navigation items
        this.tabs = $('li.ctrl-item', this.context); //$('ul.controls li', this.context);
        // remove hard coded navigation items from DOM 
        // because they aren't hooked up to jQuery cycle
        this.tabs.remove();
		$('ul.controls', this.context).append(this.tabs);
		
        // prepare slideshow and jQuery cycle tabs
        this.prepareSlideshow();
    },
    
    prepareSlideshow: function() {
        // initialise the jquery cycle plugin -
        // for information on the options set below go to: 
        // http://malsup.com/jquery/cycle/options.html
        $('div.testimonial-items > ul', $slideshow.context).cycle({
            fx: $slideshow.fx,
            timeout: $slideshow.timeout,
            speed: $slideshow.slideSpeed,
            fastOnEvent: $slideshow.tabSpeed,
            pager: $('ul.controls', $slideshow.context),
            pagerAnchorBuilder: $slideshow.prepareTabs,
            before: $slideshow.activateTab,
            pauseOnPagerHover: true,
            pause: true
        });            
    },
    
    prepareTabs: function(i, slide) {
        // return markup from hardcoded tabs for use as jQuery cycle tabs
        // (attaches necessary jQuery cycle events to tabs)
        return $slideshow.tabs.eq(i);
    },

    activateTab: function(currentSlide, nextSlide) {
        // get the active tab
        var activeTab = $('a[href="#' + nextSlide.id + '"]', $slideshow.context);
        
        // if there is an active tab
        if(activeTab.length) {
            // remove active styling from all other tabs
            $slideshow.tabs.removeClass('on');
            
            // add active styling to active button
            activeTab.parent().addClass('on');
        }            
    }            
};


$(function() {
    // add a 'js' class to the body
    $('body').addClass('js');
    
    // initialise the slideshow when the DOM is ready
    $slideshow.init();
});


