/*	
	Copyright 2006 Framfab A/S
*/

var minContentWidth		= 766;
var minContentHeight	= 0;
var flashMovie;
var myLocation = null;

function FramfabControl(){} // Used as namespace

FramfabControl.onResize = function()
{
	FramfabControl.setupScroll( "swfDIV" )
}
FramfabControl.fireClickTag = function( pageName, prop1, prop2, prop3, prop30, events, other )
{
	if (sLocale != null)
	{
		try {
		// Convert from tokenized to object form
			if (other == "null" || other == "undefined") other = "";	
			if (other != null && other.length > 0){
				var others = other.split(",");
				other = new Object();
				for(var i = 0; i < others.length; i++){
					var propName = others[i].split(":")[0];
					var propValue = others[i].split(":")[1];
					other[propName] = propValue;
				}
			}
		} catch ( err ) {
			other = null;
		}
		
		pageTracker._trackPageview("/IKEASB/" + sLocale + "/" + pageName.replace(/>/g,"/"));
		fireClickTagOmniture( "ikea_business>"+pageName, "ikea_business>"+prop1, prop2, (prop3!="null")?prop3:"", (prop30!="null")?prop30:"", (events!="null")?events:"", other )
	} else {
		return;
	}
}
FramfabControl.setStageHeight = function( height )
{
	minContentHeight = height;
	FramfabControl.setupScroll( "swfDIV" )
	FramfabControl.onScroll();
}

FramfabControl.onLoad = function(swf_path)
{
	var query = window.location.search.substring( 1 )+"";
	var hash = window.location.hash.substring( 1 )+"";
	var url = window.location.url+"";
	var queryVars = FramfabControl.parseQuery( query );
	var campaign = "";
	myLocation = url;
	
	if (swf_path == null) swf_path = 'shell.swf';
	if ( queryVars != undefined )
	{
		query = "";
		for ( var name in queryVars )
		{
			if ( name == "WT.mc_id" )
			{
				campaign = queryVars[ name ];
			}
			else
			{
				query += ( query == "" ) ? "?" : "&";
				query += name + "=" + queryVars[ name ];
			}
		}
	}

	
	var shellSWFObject = new SWFObject( swf_path, 'shellSWF', '100%', '100%', '9.0.115', '#fff' );

	shellSWFObject.useExpressInstall( 'expressinstall.swf' );
	shellSWFObject.addParam( 'swLiveConnect', 'true' );
	shellSWFObject.addParam( 'allowScriptAccess', 'always' );
	
	if ( FramfabControl.useWMode() ) {
		shellSWFObject.addParam( 'wmode', 'transparent' );
	}
	
	shellSWFObject.setAttribute( 'redirectUrl', 'noflash.html' );
	

	if ( queryVars != undefined )
	{
		for ( var name in queryVars )
		{
			shellSWFObject.addVariable( name, queryVars[ name ] ); 
		}
	}

	if ( window.location.hash != undefined )
	{
		shellSWFObject.addVariable( "location", window.location.hash.substring( 1 ) ); 
	}
	if (sLocale != null) shellSWFObject.addVariable( "sLocale", sLocale );
	
	shellSWFObject.write( "swfDIV" );
	FramfabControl.setupScroll( "swfDIV" );
	
	
}

FramfabControl.useWMode = function(){
	return true;
//	var approvedLocales = "en_US,de_DE,es_ES,ca_ES,pt_PT,xx_YY,zz_ZZ";
//	return(approvedLocales.indexOf(sLocale) >= 0);
}

FramfabControl.detectBrowser = function(){
	var x = navigator;
	var browserName = x.appName;
	var browserVersion = x.appVersion;
	var ua = x.userAgent;
	
	return browserName + ", " + browserVersion + ", " + ua;
}

FramfabControl.setLocale = function(locale) {
	if (locale != null && locale.length > 0){
//		s_language = locale.split("_")[0];
//		var country = locale.split("_")[1];
//		s_country = (country != "uk" ? country : "gb");
		sLocale = locale;
	}
}

FramfabControl.updateUrl = function( query, hash )
{
	window.location.href = "startup.html" + query + "#" + hash;
}

FramfabControl.parseQuery = function( query )
{
	var queryVars = {};
	var pairHalves;
	var NameValuePairs = query.split("&");
	var l = NameValuePairs.length;
   
	for( i = 0; i < l; i++ ) 
	{
		pairHalves = NameValuePairs[ i ].split( "=" );
		queryVars[ pairHalves[ 0 ] ] = pairHalves[ 1 ];
	}
   
	return queryVars;
}
//Repositions the MAP element
FramfabControl.mapPosition = 2;
FramfabControl.resized = function(xPos){
	document.getElementById('container').style.left = (xPos + this.mapPosition)+"px";
}
FramfabControl.getCookie = function(cookieId){
	if (document.cookie.length > 0){ 
		begin = document.cookie.indexOf(cookieId+"="); 
		if (begin != -1){ 
			begin += cookieId.length+1; 
			end = document.cookie.indexOf(";", begin);
			if (end == -1) end = document.cookie.length;
			return unescape(document.cookie.substring(begin, end));
		}
		return null; 
	}
}

FramfabControl.setupScroll = function( swfDIV )
{
	if ( document.getElementById( swfDIV ) != null )
	{
		// http://www.howtocreate.co.uk/tutorials/javascript/browserwindow
		var myWidth = 0, myHeight = 0;
		if( typeof( window.innerWidth ) == 'number' )
		{
			//Non-IE
			myWidth = window.innerWidth;
			myHeight = window.innerHeight;
		}
		else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
		{
			//IE 6+ in 'standards compliant mode'
			myWidth = document.documentElement.clientWidth;
			myHeight = document.documentElement.clientHeight;
		}
		else if(document.body && (document.body.clientWidth || document.body.clientHeight))
		{
			//IE 4 compatible
			myWidth = document.body.clientWidth;
			myHeight = document.body.clientHeight;
		}
		document.getElementById( swfDIV ).style.width = ( myWidth <= minContentWidth ) ? (minContentWidth + "px") : "100%";
		document.getElementById( swfDIV ).style.height = ( myHeight <= minContentHeight ) ? (minContentHeight + "px") : myHeight+40;
	}
}

FramfabControl.goBack = function()
{
	window.history.go( -1 );
}

FramfabControl.getScrollPosition = function()
{
	var returnValue = "";
	
	if ( document.all && !window.opera )
	{
		returnValue = document.documentElement.scrollTop+document.body.scrollTop;
	}
	else
	{
		returnValue = document.documentElement.scrollTop;
	}

	return returnValue;
}
FramfabControl.getWindowWidth = function()
{
	return (typeof window.innerWidth != 'undefined' ? window.innerWidth : document.body.offsetWidth);
}
FramfabControl.getWindowHeight = function()
{
	var myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myHeight = document.body.clientHeight;
	}

	return myHeight;
}
FramfabControl.onScroll = function()
{
	var flashMovie = this.getFlashMovie();
	if ( flashMovie.sendScrollHeight != undefined )
	{
		flashMovie.sendScrollHeight( FramfabControl.getScrollPosition() );
	}
}
FramfabControl.getFlashMovie = function() {
	return document.getElementById( "shellSWF" );
}

FramfabControl.setScroll = function( scrollValue )
{
	//alert("FramfabControl.setScroll: "+scrollValue);
	window.scrollTo( 0, scrollValue );
}
