// google maps
var geocoder;
var map;
var query = "Deinsesteenweg 108b, Drongen, Belgium";
var bannerPath = "/assets/image/home/";
var currentBanner = 1;
var currentTestimonial = 0; 
var numBanners = 2;

function loadMap(holder)
{
  geocoder = new google.maps.Geocoder();
  var options = {zoom: 15, mapTypeId: google.maps.MapTypeId.ROADMAP}
  map = new google.maps.Map(document.getElementById(holder), options);
  codeAddress();
}

function codeAddress()
{
	var address = query;
	geocoder.geocode( { 'address': address}, function(results, status)
	{
	  if (status == google.maps.GeocoderStatus.OK)
	  {
		map.setCenter(results[0].geometry.location);
		var marker = new google.maps.Marker({
			map: map,
			position: results[0].geometry.location
		});
	  }
	  else
	  {
		alert("Geocode was not successful for the following reason: " + status);
	  }
	});
}

function rotateBanner(locale)
{
  var banner = bannerPath + locale + "/banner_" + currentBanner + ".jpg";

  $("bannerimage").src = banner;

  currentBanner++;

  // reset current
  if(currentBanner > numBanners) currentBanner = 1;
}

function rotateTestimonials()
{
  var div = document.getElementById("testimonials");
  var elements = div.getElementsByClassName("testimonial");
  var t;

  currentTestimonial++;
  if(currentTestimonial == elements.length) currentTestimonial = 0;

  for(var i=0; i < elements.length; ++i)
  {
    t = elements[i];

    if(i != currentTestimonial)
    {
      t.className += "invisible";
    }
    else
    {
      t.className = t.className.replace('invisible','');
    }
  }
}


// set this to the url where the .js is loaded?
var $root = "http://www.playlane.be/";
var $fbimageURL = $root + "/assets/image/app_logo.gif"; // 75 x 75 px
var $title= "PLAYLANE";
var $caption = "";

function initFB()
{
  // create facebook application and put the appId here
  FB.init({appId: '166203063416423', status: true, cookie: true, xfbml: true});
  FB.Event.subscribe('auth.login', function(response) {
        window.location.reload();
  });
}

function shareOnFacebook($title, $bloglink, $description)
{
    FB.ui(
        {
            method: 'stream.publish',
            attachment:
            {
                name: $title,
                caption: $caption,
                description: ($description),
                href: $root,
                media: [{'type': 'image', 'src': $fbimageURL, 'href': $root}]
            },
            action_links:
            [
                { text: 'PLAYLANE', href: $bloglink }
            ],
            user_message_prompt: $title
        },
        function(response)
        {
            if (response && response.post_id)
            {}
            else
            {}
        }
    );
}

