/*!
 * jQuery hashchange event - v1.3 - 7/21/2010
 * http://benalman.com/projects/jquery-hashchange-plugin/
 * 
 * Copyright (c) 2010 "Cowboy" Ben Alman
 * Dual licensed under the MIT and GPL licenses.
 * http://benalman.com/about/license/
 */
(function($,window,undefined){'$:nomunge';var str_hashchange='hashchange',doc=document,fake_onhashchange,special=$.event.special,doc_mode=doc.documentMode,supports_onhashchange='on'+str_hashchange in window&&(doc_mode===undefined||doc_mode>7);function get_fragment(url){url=url||location.href;return'#'+url.replace(/^[^#]*#?(.*)$/,'$1');};$.fn[str_hashchange]=function(fn){return fn?this.bind(str_hashchange,fn):this.trigger(str_hashchange);};$.fn[str_hashchange].delay=50;special[str_hashchange]=$.extend(special[str_hashchange],{setup:function(){if(supports_onhashchange){return false;}
$(fake_onhashchange.start);},teardown:function(){if(supports_onhashchange){return false;}
$(fake_onhashchange.stop);}});fake_onhashchange=(function(){var self={},timeout_id,last_hash=get_fragment(),fn_retval=function(val){return val;},history_set=fn_retval,history_get=fn_retval;self.start=function(){timeout_id||poll();};self.stop=function(){timeout_id&&clearTimeout(timeout_id);timeout_id=undefined;};function poll(){var hash=get_fragment(),history_hash=history_get(last_hash);if(hash!==last_hash){history_set(last_hash=hash,history_hash);$(window).trigger(str_hashchange);}else if(history_hash!==last_hash){location.href=location.href.replace(/#.*/,'')+history_hash;}
timeout_id=setTimeout(poll,$.fn[str_hashchange].delay);};return self;})();})(jQuery,this);

var googleApiKey = function() {
	var host = window.location.hostname.replace(/^(.+\.)?([^\.]+\.[^\.]+)/, '$2');
	var keys = {
		'softwerk.de': 'ABQIAAAANRJ7gPzrsJ-pFMxZaq_dthSf9JUUgIDjBd14JvULz2uM3jdCABQmiIVDnzMbshM4solzCepzGDmbQQ',
		'bulthaup.de': 'ABQIAAAANRJ7gPzrsJ-pFMxZaq_dthT0AwXYBP7p5edl43ReikUbYImyWhR6VbK6oASGot8_r0BAwRU5tyWIxA',
		'bulthaup.com': 'ABQIAAAANRJ7gPzrsJ-pFMxZaq_dthQ4KR9FPKPxmf3Q1YJYwP__aWbwfRSw-vnYgF0qWUns9kQtnPGatccfFA',
		'bulthaup.it': 'ABQIAAAANRJ7gPzrsJ-pFMxZaq_dthSTMY7kYwBmp-R_eSHTFgNnaR5aqRTsu_6lY7D8trVAmt4ww5BClbINEA',
		'bulthaup.es': 'ABQIAAAANRJ7gPzrsJ-pFMxZaq_dthTp2bisl9iAGQ-8uU2RCTvZwM3YOhTOk-y71I_NoXlcdi0I8--B6mO4_g',
		'bulthaup.fr': 'ABQIAAAANRJ7gPzrsJ-pFMxZaq_dthQZAhsQSj979vI9DbeBjXaNZ9RorRSOLQ72NJGLOMFm8eAbnwrVvxNFcg',
		'bulthaup.nl': 'ABQIAAAANRJ7gPzrsJ-pFMxZaq_dthQMqkiwVJdMFHuYrV7Rxc2sCn78jxQRxD84xVkZm3fF34dFAHqOaVS6SA',
		'bulthaup.ch': 'ABQIAAAANRJ7gPzrsJ-pFMxZaq_dthQHKEsUcwe7uod2IwIMubqdv3JhexQz8J2KiSclkSjaYimiGG4pzskufA',
		'bulthaup.at': 'ABQIAAAANRJ7gPzrsJ-pFMxZaq_dthTyb63wzwG1DAL151p-X0A9fRO64RTnhvhHu0xL9AnRMIlcl5KF_WIRgw',
		'bulthaup.be': 'ABQIAAAANRJ7gPzrsJ-pFMxZaq_dthTA58N0Dyz2BJV3iIbACE16gD6RDBQfDS1ecC8QN1cUDGqLdeV5pnT7hw',
		'bulthaup.jp': 'ABQIAAAANRJ7gPzrsJ-pFMxZaq_dthRlXcWh8vciUmeOlWiiQELrK93kUxT4JJBt1-jT5LqN1FMXn92X7l20EQ'
	};
	return keys[host] || keys['bulthaup.de'];
};

var flashvars = {
	domain: '*',
	page: swfobject.getQueryParamValue("page") || (window.location.hash || '').replace(/^#\//, '').replace(/&/g, '%26') || "56E4DDB71A0594AFC12570750046B062",
	map: homepath+"systemcontentview/x_jsonmap.txt",
	variables: homepath+"systemcontentview/x_jsonvars.txt",
	languages: homepath+"systemcontentview/x_jsonlang.txt",
	resources: homepath+"systemcontentview/x_jsonresources.txt",
	jsonview: homepath+"jsonview/",
	skinswf: (window.skinSWF? (resourcepath+"imgref/D_" + window.skinSWF + "/$File/" + window.skinSWF): (resourcepath+"imgref/D_skin.swf/$File/skin.swf")),
	skin_videoswf: resourcepath+"imgref/D_skin_video.swf/$File/skin_video.swf",
	query: homepath+"systemcontentview/x_jsonquery.txt",
	base: window.location.pathname.replace(/(\/+)?$/, "/"),
	googleapikey: googleApiKey()/*,
	analytics: window.analyticsFlash || ''*/
};

function getViewportSize() { 
	var size = [0, 0]; 
	if (typeof window.innerWidth != "undefined") { 
		size = [window.innerWidth, window.innerHeight];
	} 
	else if (typeof document.documentElement != "undefined" && typeof document.documentElement.clientWidth != "undefined" && document.documentElement.clientWidth !== 0) {
		size = [document.documentElement.clientWidth, document.documentElement.clientHeight]; 
	}
	else {
		size = [document.getElementsByTagName("body")[0].clientWidth, document.getElementsByTagName("body")[0].clientHeight]; 
	}
	return size; 
}

function createFullBrowserFlash() {
	swfobject.createCSS("html", "height:100%;");
	swfobject.createCSS("body", "height:100%;");
	swfobject.createCSS("#container", "margin:0; width:100%; height:100%; min-width:846px; min-height:590px;");
	window.onresize = function() {
		var el = document.getElementById("container");
		if (el) {
			var size = getViewportSize(); 
			el.style.width = size[0] < 846 ? "846px" : "100%";
			el.style.height = size[1] < 590 ? "590px" : "100%";
		}
	};
	window.onresize();
}	

function initSWF() {
	var swf = window.bulthaupSWF || 'bulthaup.swf';
	swfobject.embedSWF(
		resourcepath+"imgref/D_" + swf + "/$File/" + swf, 
		"content", "100%", "100%", "9.0.124", 
		resourcepath+"imgref/D_expressInstall.swf/$File/expressInstall.swf",
		flashvars,
		{allowFullScreen: "true", scale: "noscale"},
		{id: 'website'}
	);
}

function trackSWF() {
  if (window.console && window.console.dir) {
     window.console.dir({arguments: arguments});
  }
}

function openLightBox(url, imageUrl) {
	url = url.replace(/\/jsonview\//, "/contentview/");
	if (url.indexOf('?') === -1) url += "?Open";
	if (url.indexOf('&lightbox') === -1) url += "&lightbox";
	$.fancybox({
		type: 'iframe',
		href: url,
		width: 800,
		height: 480,
		onStart: function() {
			if ($.browser.msie) {
				swfobject.removeSWF('website');
				$("#container").append('<div id="content"></div>');
			} else {
				$("#container").hide();
			}
		},
		onClosed: function() {
			if ($.browser.msie) {
				initSWF();
			} else {
				$("#container").show();
			}
		}
	});
	return false;
}

var openPopup = openLightBox;
if (!window.gotoMobile && !(window.useHtmlVersion && window.isMobileClient)) {
	$(document).ready(function() {
		if (window._gaq) {
			$(window).hashchange(function() { 
				_gaq.push(['_trackPageview', (location.hash || '').replace(/^#/, '')]);
			});
		}
	});
	
	if(location.search.indexOf('testnav') == -1 && location.search.indexOf('lightbox') == -1 && location.pathname.indexOf('/responseview/') == -1) {
		initSWF();

		if (swfobject.hasFlashPlayerVersion("9.0.124")) {
			if(!window.isBase) location.href = systemBaseURL+'#/'+(window.parentpageunid? window.parentpageunid: pageunid);
			swfobject.addDomLoadEvent(createFullBrowserFlash);
		}
	}
}




