// JavaScript Document

$(document).ready(function(){
	
	//Logo Glow
	$('#logo a span').after('<span class="hover"></span>');
	$('#logo a').hover(function(){
		$('#logo a span').stop().animate({opacity: 1}, 800);						
	},function(){
		$('#logo a span').stop().animate({opacity: 0}, 400);
	});
	
	//Slide-Left Glow
	$('#slide-left span').after('<span class="hover"></span>');
	$('#slide-left').hover(function(){
		$('#slide-left span.hover').stop().animate({opacity: 1}, 800);						
	},function(){
		$('#slide-left span.hover').stop().animate({opacity: 0}, 400);
	});
	
	//Slide-Right Glow
	$('#slide-right span').after('<span class="hover"></span>');
	$('#slide-right').hover(function(){
		$('#slide-right span.hover').stop().animate({opacity: 1}, 800);						
	},function(){
		$('#slide-right span.hover').stop().animate({opacity: 0}, 400);
	});
	
	//Menu items glow
	$('#menu a').hover(function(){
		$(this).stop().animate({color: '#FFF'}, 400);				
	}, function(){
		$(this).stop().animate({color: '#CCC'}, 800);	
	});			
	
	//Hover states for Services page items
	$('.main-service-item-shadow').css({marginTop: -25});
	$('.main-service-item').hover(function(){
		$(this).find('.main-service-item-shadow').stop().animate({marginTop: -5}, 1000);
		$(this).stop().animate({marginTop: 5}, 1000);
	},function(){
		$('.main-service-item-shadow').stop().animate({marginTop: -25}, 600);
		$(this).stop().animate({marginTop: 0}, 600);
	});
	
	//Hover states for Clients page
	$('.client-item-shadow').css({marginTop: -25});
	$('.client-item').hover(function(){
		$(this).find('.client-item-shadow').stop().animate({marginTop: -5}, 800);
		$(this).stop().animate({marginTop: 5}, 800);
	},function(){
		$('.client-item-shadow').stop().animate({marginTop: -25}, 600);
		$(this).stop().animate({marginTop: 0}, 600);
	});
	
/******************************************
Homepage slideshow 
******************************************/
	$slideshow = {
		context: false,
		tabs: false,
		timeout: 5000,      // time before next slide appears (in ms)
		slideSpeed: 800,   // time it takes to slide in each slide (in ms)
		tabSpeed: 1000,      // time it takes to slide in each slide (in ms) when clicking through tabs
		fx: 'scrollLeft',   // the slide effect to use
	
		init: function() {
			// set the context to help speed up selectors/improve performance
			this.context = $('#slide-container');
	
			// set tabs to current hard coded navigation items
			this.tabs = $('ul.slides-nav li');
	
			// remove hard coded navigation items from DOM
			// because they aren't hooked up to jQuery cycle
			this.tabs.remove();
	
			// 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
			$("#slide-wrap", $slideshow.context).cycle({
				fx: $slideshow.fx,
				timeout: $slideshow.timeout,
				speed: $slideshow.slideSpeed,
				fastOnEvent: $slideshow.tabSpeed,
				pager: $("ul.slides-nav", $slideshow.context),
				pagerAnchorBuilder: $slideshow.prepareTabs,
				before: $slideshow.activateTab,
				pauseOnPagerHover: true,
				pause: true,
				next: '#slide-right', 
   			    prev: '#slide-left' 
			});
		},
		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() {
		// initialise the slideshow when the DOM is ready
		$slideshow.init();
	});
	
/************* End Slideshow */
				
	
		
    <!--
    // wrap as a jQuery plugin and pass jQuery in to our anoymous function
    (function ($) {
        $.fn.cross = function (options) {
            return this.each(function (i) { 
                // cache the copy of jQuery(this) - the start image
                var $$ = $(this);
                
                // get the target from the backgroundImage + regexp
                var target = $$.css('backgroundImage').replace(/^url|[\(\)'"]/g, '');

                // nice long chain: wrap img element in span
                $$.wrap('<span style="position: relative;"></span>')
                    // change selector to parent - i.e. newly created span
                    .parent()
                    // prepend a new image inside the span
                    .prepend('<img>')
                    // change the selector to the newly created image
                    .find(':first-child')
                    // set the image to the target
                    .attr('src', target);

                // the CSS styling of the start image needs to be handled
                // differently for different browsers
                if ($.browser.msie || $.browser.mozilla) {
                    $$.css({
                        'position' : 'absolute', 
                        'left' : 0,
                        'background' : '',
                        'top' : this.offsetTop
                    });
                } else if ($.browser.opera && $.browser.version < 9.5) {
                    // Browser sniffing is bad - however opera < 9.5 has a render bug 
                    // so this is required to get around it we can't apply the 'top' : 0 
                    // separately because Mozilla strips the style set originally somehow...                    
                    $$.css({
                        'position' : 'absolute', 
                        'left' : 0,
                        'background' : '',
                        'top' : "0"
                    });
                } else { // Safari
                    $$.css({
                        'position' : 'absolute', 
                        'left' : 0,
                        'background' : ''
                    });
                }

                // similar effect as single image technique, except using .animate 
                // which will handle the fading up from the right opacity for us
                $$.hover(function () {
                    $$.stop().animate({
                        opacity: 0
                    }, 450);
                }, function () {
                    $$.stop().animate({
                        opacity: 1
                    }, 450);
                });
            });
        };
        
    })(jQuery);
    
    // note that this uses the .bind('load') on the window object, rather than $(document).ready() 
    // because .ready() fires before the images have loaded, but we need to fire *after* because
    // our code relies on the dimensions of the images already in place.
    $(window).bind('load', function () {
        $('img.fade').cross();
    });
    
    //-->
			   
						   
						   
});