var GLOB = Array();
GLOB['panel'] = false; 

// JavaScript Document



var direction = 'forward';

function autoSlide(){
	position = currentPosition;
	
	switch (direction){
		case 'forward':
		if(position==0){ $('#leftControl').hide(); $('#rightControl').click();$('#rightControl').show();}
		else if(position==numberOfSlides-1){ $('#rightControl').hide(); $('#leftControl').click();$('#leftControl').show();direction = 'backward';}
		else if(position==numberOfSlides){$('#leftControl').click();direction = 'backward';}
		else if(position!=0){ $('#leftControl').show(); $('#rightControl').click(); }
   		break;
		case 'backward':
		if(position==0){ $('#leftControl').hide(); $('#rightControl').click();$('#rightControl').show();direction = 'forward';}
		else if(position!=0){ $('#leftControl').show(); $('#leftControl').click(); }
		break;
		default:
		break;
		
	}
	timed();
	
}


var currentPosition = 0;
var numberOfSlides = 0;




$(document).ready(function(){

  var slideWidth = 960;
  var slides = $('.slide');
  numberOfSlides = slides.length;
	
  // Remove scrollbar in JS
  $('#slidesContainer').css('overflow', 'hidden');

  // Wrap all .slides with #slideInner div
  slides
  .wrapAll('<div id="slideInner"></div>')
  // Float left to display horizontally, readjust .slides width
  .css({
    'float' : 'left',
    'width' : slideWidth
  });

  // Set #slideInner width equal to total width of all slides
  $('#slideInner').css('width', slideWidth * numberOfSlides);

  // Insert left and right arrow controls in the DOM
  $('#slideshow')
    .prepend('<span class="control" id="leftControl"></span>')
    .append('<span class="control" id="rightControl"></span>');

  // Hide left arrow control on first load
  manageControls(currentPosition);

  // Create event listeners for .controls clicks
  $('.control')
    .bind('click', function(){ timed();
    // Determine new position
      currentPosition = ($(this).attr('id')=='rightControl')
    ? currentPosition+1 : currentPosition-1;

      // Hide / show controls
      manageControls(currentPosition);
      // Move slideInner using margin-left
      $('#slideInner').animate({
        'marginLeft' : slideWidth*(-currentPosition)
      });
    });

  // manageControls: Hides and shows controls depending on currentPosition
  function manageControls(position){
    // Hide left arrow if position is first slide
    if(position==0){ $('#leftControl').hide() }
    else{ $('#leftControl').show() }
    // Hide right arrow if position is last slide
    if(position==numberOfSlides-1){ $('#rightControl').hide() }
    else{ $('#rightControl').show() }
  }
	
timed();

/* ----------------------- Contact Reveal ---------------------------- */
	
$("a.contact").click(function(){
	if(GLOB['panel']){
		$("div.panel").animate({'height':'0px'}, 500);
		GLOB['panel'] = false;
	}else{
		$("div.panel").animate({'height':'436px'}, 500, function(){
		// Load the google map
			$(function(){
				 if (GBrowserIsCompatible()) {
					var map = new GMap2(document.getElementById("exstatikmap"));
					map.addControl(new GLargeMapControl3D());
					map.setCenter(new GLatLng(53.823139,-1.578464), 13);
					var latlng = new GLatLng(53.823139,-1.578464);
					map.addOverlay(new GMarker(latlng));
				  }
			});	
		});
	
		GLOB['panel'] = true;
	}

	$("a.close").click(function(){
		$("div.panel").animate({'height':'0px','display':'none'}, 500);
		GLOB['panel'] = false;
		return false;
	});

	/* ------------------------ page selected detect ------------------------- */
 	return false;
   });
 
var timeOut;

function timed() { 
	clearTimeout(timeOut);
	timeOut = setTimeout('autoSlide()', 7000);
}

	
}); 

