$(function(){
		
	//add js class to the body
    $('body').addClass('hasJS');
	
	/*$('#screenFades .inner').innerfade({ 
		speed: 'fast', 
		timeout: 2000, 
		type: 'sequence', 
		containerheight: '516px' 
	});*/
	 $('#screenFades .inner').cycle({
		fx: 'fade',
    	speed:    1500, 
    	timeout:  3000 
	});
	//synchronise behaviours to certain links on products page
	function hoverSynch(element){
		$(element).hover(function() {
		// flip background position 
		$$ = $(this);
		$rel = $$.attr('rel');	
		if($rel != 'sRoom'){
			$('#dealerWebsite').css('backgroundPosition', '0px -544px');	
			$('#dealerWebsite a').hide();
		}
			$(element).each(function(){
				$ethis = $(this);
				if($ethis.attr('rel') == $rel){
					$ethis.addClass('synchHover');
					$ethis.show();
				}
			});
		},function(){
			$('#dealerWebsite').css('backgroundPosition', '0px 0px');		
			$(element).removeClass('synchHover');
			$('#dealerWebsite a').show();
		});
	}
	//call	
	hoverSynch('body.home-index #homepageLower a');
	
	// what link is to be shown at the bottom
	//
	// bound to the window load
	if ($(window).scrollTop() >= 425 && window.location.pathname == '/codeweavers/') {
		$('a#footerLink').removeClass('scrollLink');
					$('a#footerLink').addClass('scrollLinkUp');
					$('a#footerLink').attr('href','#bg');
						if(window.location.pathname == '/codeweavers/'){
							$('#nav li#l1 a').addClass('active');
						}
	}
	
	// bound to the scroll event	
	$(window).scroll(
		$.throttle(1000, // throttle to stop the scroll listener smashing IE
			function() {
				if ($(window).scrollTop() >= 425) {
					$('a#footerLink').removeClass('scrollLink');
					$('a#footerLink').addClass('scrollLinkUp');
					$('a#footerLink').attr('href','#bg');
						if(window.location.pathname == '/codeweavers/'){
							$('#nav li#l1 a').addClass('active');
						}
				}else if($(window).scrollTop() <= 425){
					$('a#footerLink').removeClass('scrollLinkUp');
					$('a#footerLink').addClass('scrollLink');
					$('a#footerLink').attr('href','#homepageLower');
						if(window.location.pathname == '/codeweavers/'){
							$('#nav li#l1 a').removeClass('active');
						}
				}
			}
	    )
	);
	// vertical scrolling
	$('a#footerLink, a.imageOverlayAnchor').click(function(e){
		e.preventDefault();
			$.scrollTo(
			$(this).attr('href'), 
			{
				duration: 1000,
				easing:'easeInOutCirc',
				offset:-112
			} //heel the top to the edge of the white area
		);
	});
	

	// detect user interaction to prevent scrollTo
		// mousewheel	
		$(window).mousewheel(function(event, delta) {
			$.scrollTo.window().queue([]).stop();					
		});
		// keys	
		if ($.browser.mozilla) {
			$(window).keypress(function(){
				$.scrollTo.window().queue([]).stop();								
			});
		} else {
			$(window).keydown(function(){
				$.scrollTo.window().queue([]).stop();								
			});
		}
		
	// animated previous and next links
	if(navigator.platform != 'iPad' || navigator.platform != 'iPhone' || navigator.platform != 'iPod'){
	//	prev
		$('a.previous').hover(function(){
			$(this).animate({
				'left' : '-230px'		
			});
		},function(){
			$(this).animate({
				'left' : '-201px'		
			});
		});
	//	next
		$('a.next').hover(function(){
			$(this).animate({
				'right' : '-239px'		
			});
		},function(){
			$(this).animate({
				'right' : '-210px'		
			});
		});
	}
	//if we have JS then remove the static map build the jquery map
    if ($('body').hasClass('hasJS')) {
        //$('div').remove('#staticMap');
        $('body.home-contact #wrapper').prepend('<div id="map"></div>');
            
		function mapDefault(){
				$("#map").gMap({ 
				markers: [{ 
                latitude:   52.746537,
                longitude:  -2.107562
                }],
				zoom: 12,
				controls: false
            });
		}

		mapDefault();
		$('a#refresh').click(function(){
			mapDefault();   
		})
	
	// video pane
	$('.videoPaneLink').append('<a id="viewVideo" href="#">Click here to see our free client video\'s</a>');
	
	}// hasJs
	
	// video pane function
	$('#viewVideo').live('click', function(e){
		e.preventDefault();
		if(!$('#viewVideo').hasClass('open')){
			$('#videoPane').slideDown('slow','easeInOutQuart');
			
			$(this).addClass('open');
		} else if($('#viewVideo').hasClass('open')) {
			$('#videoPane').slideUp('slow','easeInOutQuart');
			$(this).removeClass('open');
		}
	});
	
})
