var infos = [], slider_pod_height = 0, slider_pod_transition = 1500, slider_pod_pause = 6000, slider_timeout;
window.onload = function (){
	//poppin up some header elements out of nowhere
	$('#header').append( '<div class="logo"><a href="/" title="Back to home page"><img src="/var/az/50550/796757-Logo-amend.png" border="0" width="344" height="75"></a></div>');
	$('#header').append( '<div class="phone">01227 456 589</div>');
	//$('#header').append( '<a title="Find us on Facebook" id="Facebook" target="_blank" href="https://www.facebook.com/pages/Instyle-Interiors/187422204684205"><img height="47" width="47" alt="" src="/var/az/50550/782397-Facebook-Logo.png"></a>');

	//adding clearfix for the win
	$('#page, #content, #header').addClass('clearfix');


	//homepage sliding pod
	$('.homeBody #sidebar > div').each( function() {
		temp_h = $(this).height();
		if( temp_h > slider_pod_height ) slider_pod_height = temp_h;
	});
	$('.homeBody #sidebar').css('min-height', slider_pod_height);

	//on page load slide first element in
	if( $('.homeBody #sidebar > div').length > 0 ){
		$.getScript('/var/az/50550/743789-jquery.easing.1.3.js', function(data, textStatus){
			slider_timeout = setTimeout("slider_timeout_run()", slider_pod_pause);
		})

		$('.homeBody #sidebar').mouseout( function () {
			clearTimeout(slider_timeout);
			slider_timeout = setTimeout("slider_timeout_run()", slider_pod_pause);
		});

		$('.homeBody #sidebar').mouseover( function () {
			clearTimeout(slider_timeout);
		});
	}


	//check if slider exists, if it does load nivo-slider.js
	if( $('#slider').length > 0 ) {
		//load JS
		$.getScript('/var/az/50550/741787-nivo-slider.js', function(data, textStatus){
			//when niv-slider loaded, execute it
			$('#slider').nivoSlider({
				effect:"slideInRight",
				slices:1,
				boxCols:1,
				boxRows:1,
				animSpeed:500,
				pauseTime:6000,
				startSlide:0,
				directionNav:false,
				directionNavHide:true,
				controlNav:true,
				controlNavThumbs:false,
				controlNavThumbsFromRel:true,
				keyboardNav:true,
				pauseOnHover:true,
				manualAdvance:false
			});
			// and of course, fade the slider in.
			$('#slider').fadeIn('fast');
		});
	}

	// If images is present in gallery, load gallery script - fancybox in this case
	if( $('#gallery a').length > 0 ) {
		//load JS file
		$.getScript('/var/az/50550/783344-jquery.colorbox-min.js', function(data, textStatus){
			//execute fancybox
			$("#gallery a").colorbox({rel:'gallery', transition:"none", width:"75%", height:"75%"});
		});
	}

	if( $('#map').length > 0 ) {
		initialize();
	}
}
	//run sliding pods, run!
	function slider_timeout_run() {
		$('.homeBody #sidebar > div:nth(0)').animate({ top: '-100%' }, 500, 'easeInQuint');
		$('.homeBody #sidebar > div:nth(0)').fadeOut('slow');
		$('.homeBody #sidebar > div:nth(1)').animate({
			top: '0'
		}, slider_pod_transition, 'easeOutQuint', function() {
			slider_timeout = setTimeout("slider_timeout_run()", slider_pod_pause);
			$('.homeBody #sidebar > div:nth(0)').css('top', '100%');
			$('.homeBody #sidebar > div:nth(0)').fadeIn('slow');
			$( $('.homeBody #sidebar > div:nth(0)')).appendTo( $('#sidebar') )
		});
		
	}

  //google map options
  function initialize() {
	var latlng = new google.maps.LatLng(51.284826, 1.073906);
	var myOptions = {
	  zoom: 15,
	  center: latlng,
	  mapTypeId: google.maps.MapTypeId.ROADMAP
	};
	var map = new google.maps.Map(document.getElementById("map"), myOptions);

	var html = '<div class="info"><strong>INSYLE INTERIORS</strong><br />Lenleys, 25-34 Roper Road, Canterbury, Kent, CT2 7EL</div>';

	var marker = new google.maps.Marker({
		position: latlng,
		map: map,
		title:"Instyle Interiors Ltd",
		clickable: true,
		content: html
	});

	google.maps.event.addListener(marker, 'click', function() {
	   closeInfos();
	   var info = new google.maps.InfoWindow({content: this.content});
	   info.open(map,this);
	   infos[0]=info;

	});
  }

function closeInfos(){
   if(infos.length > 0){
	  infos[0].set("marker",null);
	  infos[0].close();
	  infos.length = 0;
   }
}
