/* Author: 

*/
  jQuery(function($){


  	if ($('#slider-inner').size()>0) {
		$('#slider-inner').width($('#slider-inner ul').size() * $('#slider-inner ul').width());
		$('.move-right').live('click', function(e){
			e.preventDefault();
			if ($('#slider-inner').is(":not(':animated')")) {
				if ($('#slider-inner').css('margin-left').replace('px','') == -($('#slider-inner').width() - $('#slider-inner ul:first').width())) {
					$('#slider-inner').animate({'marginLeft':0})
				} else {
					$('#slider-inner').animate({'marginLeft':'-='+$('#slider-inner ul').width()})
				}
			};
		})
		$('.move-left').live('click', function(e){
			e.preventDefault();
			if ($('#slider-inner').is(":not(':animated')")) {
				if ($('#slider-inner').css('margin-left').replace('px','') == 0) {
					$('#slider-inner').animate({'marginLeft':'-='+($('#slider-inner').width() - $('#slider-inner ul:first').width())})
				} else {
					$('#slider-inner').animate({'marginLeft':'+='+$('#slider-inner ul').width()})
				};
			};
		})
	};
	
	$('#landing img').hide();
	$('#landing img:first').fadeIn(1000, function(){
		$('#landing img:first').next('img').fadeIn(1000, function(){
			$('#landing img:last').fadeIn(1000);
			setTimeout(function() {
			  window.location.href = "home.php";
			}, 2000);
		});									
	});
	
	/* footer - position bottom */
	$(window).load(function(){
		checkSize();
		checkWidth();
		checkHeight();

	})
	
	
	$(window).bind('resize',checkWidth);
		function checkWidth() {
		if($(window).width() < 960)
		{
			console.log('less');
			$('#wrapper-top, #wrapper-footer, #googlemap,').css('width', '960px' );
			/*alert($(document).height());
			alert($(window).height());
			alert($(document).width());
			alert($(window).width());*/
			$('#full-screen-image').width($(document).width());
		}
		else
		{
			$('#wrapper-top, #wrapper-footer, #googlemap,').css('width', '100%' );
			//do something else
		}

	}


	$(window).bind('resize',checkSize);
		function checkSize() {
		if($(window).height()> ($('#wrapper-top').height() +  $('#wrapper-middle').height()+ 20 +  $('#wrapper-footer').height())) {
			$('#wrapper-footer').css({
				'bottom':0, 
				'left':0, 
				'position':'absolute'
			});
			
		} else {
			$('#wrapper-footer').css({
				'bottom':0, 
				'left':0, 
				'position':'relative',
				'float' : 'left'
			})
		}
	}

	var isiPad = navigator.userAgent.match(/iPad/i) != null;

	$(window).bind('orientationchange', function(event) {
  		if($('#google-map-container').size() > 0)
		{
			$('#google-map-container').height($(document).height());

		}
		else
		{
			checkSize();
			checkWidth();
			checkHeight();
		}
  		
	});

	$(window).bind('resize',checkHeight);
		
		
		function checkHeight() {
			if(isiPad == true)
			{
				if($(document).height() > $(window).height()) {
					if($('#google-map-container').size() > 0)
					{
						$('#google-map-container').height($(document).height());

					}
					else
					{
						//alert($(document).height());
						$('#full-screen-image, #full-screen-image img').height($(document).height());
						
						//alert($('#full-screen-image').height());
					}
				} 
				else {
				
				}
				
			}
		
		}
				  
	
	/* full screen image position */
	
	$('#full-screen-image').css('position','absolute');
 
	
	$('#full-screen-image').fullSizeImage({
		repositionImage : true,
		overlayLine:true,
		offset : null,
		position : 'fixed'
	});
	
		//image transition
	$('#full-screen-image img:not(":first")').hide();
		var count=0;
		var countImages = $('#full-screen-image img').size();

    if(countImages>1){
        setInterval(nextImage,4000); //The number here dictates the length of time between the animation
    }

    function nextImage() {
        $('#full-screen-image img:eq('+count+')').fadeOut(1500); //Length of FadeOut transition
        if(count<countImages-1){
            count++;
        } else {
           	count=0;
        }
       $('#full-screen-image img:eq('+count+')').fadeIn(1500); //Length of FadeIn transition
    }
	
	$('#close a').click(function(e){
		e.preventDefault();
		$('#map-titles a').removeClass('on');
		$('#map-overs img:visible').hide();
		$('#map-overlay img:visible').hide();
		$(this).parent().parent('#main-content').fadeOut(1000, function() {
			$('#open').fadeIn(500); 
			checkSize();
		});
		$('#map-content div:visible').fadeOut();
		
		
									 
	});
	
	$('#open a').click(function(e){
		e.preventDefault();
		$(this).parent('#open').fadeOut(1000, function() { 
			$('#main-content').fadeIn(500); 
			checkSize();
		});							 
	});
	
	$('div.profile-conent').hide();
	$('#services div.profile-conent:first').show();
	
	//Services Page - DISPLAYS THE BUYING SECTION ON PAGE LOAD & HIDES
	
	
	// ***END***
	
	$('a.read-more').click(function (e){
		e.preventDefault();
		$(this).fadeOut(100, function() {
			$(this).next('.profile-conent').slideDown(100, function(){ 
				checkSize(); 
			});	
		});
		
	});
	
	$('a.read-less').click(function (e){
		e.preventDefault();
		$(this).parent('.profile-conent').slideUp(100, function(){
			$('a.read-more').fadeIn();
			checkSize();
		});
		
	});

	
  })
  
	$('#map-content .location-content').hide();
	$('#map-overs img').hide();
  
	var hover_class = null;
  
	$('#map-titles a').mouseenter(function(e){
	  	e.preventDefault();
		$('.on').removeClass('on');
		hover_class = $(this).attr('class');
		
		if(hover_class!=$('#map-content div:visible').attr('id')){
			$(this).addClass('on');
			
			if	( $('#map-content div').is(":visible")) {
				$('#map-content div:visible').hide();
				$('#map-content #'+hover_class).fadeIn();
			} else {
				$('#map-content #'+hover_class).fadeIn();
			}
			
			if( $('#map-overs img').is(":visible")){
				$('#map-overs img:visible').hide();
				$('#map-overs img.'+hover_class).fadeIn();
			} else{
				$('#map-overs img.'+hover_class).fadeIn();
			}
		}
		
	});
	
	$('#london-map area').mouseenter(function(){
		$("#map-titles a."+$(this).attr('class')).trigger('mouseenter');
	});
	
	
	$.preload( '#full-screen-image img', {//the first argument is a selector to the images		
		onFinish:finish,		
		threshold: 1 
	});	

	function finish(){//hide the summary
		$('#full-screen-image img.first').fadeIn("slow");
	};
