// header video

var width = 940;
var height = 360;
var div_id = "flash_video";

// initialize some handy vars
var video_el = document.getElementById(div_id);


if(video_el != null)
{
	var video_element = $('head_video');
	var cookie_name = "blanko_"+video_element.className;

	if(typeof(video_element.currentTime) != "undefined")
	{
		// play pause on video click
		video_element.onclick = function()
		{
			if(video_element.paused)
			{
				video_element.play();
			}
			else
			{
				video_element.pause();
			}
			
			return false;
		}
		
		// emulate on click on video element to enabled autoplay on ipad
		if(document.createEvent) 
		{
			evt = document.createEvent("MouseEvents");
			
			if(evt.initMouseEvent) 
			{
				evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
				video_element.dispatchEvent(evt);
			}
		}
	}
	else
	{
		var video_name = document.getElementById(div_id).className;

		var video_url = "/files/videos/"+video_name+".mp4";
		var poster_url = "/files/videos/"+video_name+".jpg";

		var flashvars = {
			width: width,
			height: height,
			image: poster_url,
			file: video_url,
			screencolor: "FFFFFF",
			frontcolor: "555555",
			backcolor: "DDDDDD",
			lightcolor: "000000",
			icons: false,
			controlbar: "none",
			autostart: true
		};

		var params = {
			wmode: "transparent"
		};

		var attributes = {
		};


		swfobject.embedSWF("/themes/blanko/media/swf/player.swf", div_id, width, height, "9.0.98", "/themes/blanko/media/swf/expressInstall.swf", flashvars, params, attributes);
	}
}


// cookie handling
function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = ";expires="+date.toGMTString();
	}
	else var expires = "";
	
	var cookie = name+"="+value+expires+";path=/";
	
	document.cookie = cookie;
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');

	for(var i=0;i<ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0)
		{
			//alert(name+': '+c.substring(nameEQ.length,c.length));
			return c.substring(nameEQ.length,c.length);
		}
	}
	return false;
}

function eraseCookie(name)
{
	createCookie(name,"",-1);
}

// google maps

var el = document.getElementById("maps");
if (el != null)
{
	var blanko_location = new google.maps.LatLng(51.2096, 6.78051);
	
	var myOptions =
	{
	    zoom: 17,
	    center: blanko_location,
	    mapTypeControl: true,
	    mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
	    navigationControl: true,
	    navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
	    mapTypeId: google.maps.MapTypeId.SATELLITE      
	}
	 
	var map = new google.maps.Map(el, myOptions);
	
	var blankoImage = new google.maps.MarkerImage('/themes/blanko/media/images/blanko_map_icon.png',
		new google.maps.Size(112, 65),
		new google.maps.Point(0,0),
		new google.maps.Point(3, 60)
	);
	
	var marker = new google.maps.Marker({
		position: blanko_location,
		map: map,
		icon: blankoImage,
	});
}


var brunch_map = document.getElementById("maps_brunch");
if (brunch_map != null)
{
	var eigelstein_map_location = new google.maps.LatLng(51.2155,6.7551);
	var eigelstein_location = new google.maps.LatLng(51.214136,6.7551);
	
	var myOptions =
	{
	    zoom: 15,
	    center: eigelstein_map_location,
	    mapTypeControl: true,
	    mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
	    navigationControl: true,
	    navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
	    mapTypeId: google.maps.MapTypeId.ROADMAP      
	}
	 
	var map = new google.maps.Map(brunch_map, myOptions);
	
	var marker = new google.maps.Marker({
		position: eigelstein_location,
		map: map,
		title: "Brauhaus Eigelstein"
	});
	
	var infowindow = new google.maps.InfoWindow({
	    content: "<strong>Brauhaus Eigelstein</strong><br />Hammer Straße 17<br />40219 Düsseldorf"
	});
	
	infowindow.open(map,marker);
	google.maps.event.addListener(marker, 'click', function() {
	  infowindow.open(map,marker);
	});
}
