
var AB = new Class({
	
	historyManager: null,
	options: {},
	mainMovie: null,
	language: null,
	
	
	initialize: function(options) {
		this.setOptions(options);
		
		var flashvars = {};
		flashvars.LANG = this.options.language;
		flashvars.LANGUAGES = this.options.siteLanguagesString;
		flashvars.CONTENT_PATH = this.options.content_path;
		flashvars.ABS_ROOT = this.options.site_abs_root;
		flashvars.ENVIRONMENT = "web";
		flashvars.HOME_SECTION_PATH = this.options.homeSectionPath;
		flashvars.SCREEN_WIDTH = screen.width;
		flashvars.SCREEN_HEIGHT = screen.height;
		flashvars.movie = this.options.site_abs_root + "_content/" + this.options.movieFileName;
		
		this.language = this.options.language;
		
		var params = {};
		params.menu = "false";
		params.scale = "noscale";
		//params.salign = "tl";
		params.wmode = "opaque";
		params.swliveconnect = "true";
		params.allowfullscreen = "true";
		params.allownetworking = "all";
		params.allowscriptaccess = "sameDomain";
		var attributes = { id: "mainMovie" };
		swfobject.embedSWF(this.options.site_abs_root + "_content/ab_wrapper.swf?rand="+Math.random(), "mainMovie", "100%", "100%", "9.0.0", this.options.site_abs_root + "_content/expressInstall.swf", flashvars, params, attributes);
		
		if (swfobject.hasFlashPlayerVersion("9.0.0")) { 
		  swfobject.addLoadEvent(this.setFocusOnFlash);
		}
		
		window.addEvent('domready', this.onDOMReady.bind(this));
		window.addEvent('load', this.checkHeight.bind(this));
		window.addEvent('resize', this.checkHeight.bind(this));
	},
	
	
	/*
		-- defined flash movie object var and the historyManager
	*/
	onDOMReady: function() { 
		// the flash movie is not instantiated immediately, so catch it after 1/10 of a second
		this.onDOMReady2.delay(100, this);
		if(Browser.Engine.presto) $('allContainer').setStyle('height', 'auto');
	},
	onDOMReady2: function() {
		this.mainMovie = swfobject.getObjectById('mainMovie');
		// this.historyManager = new HistoryManager();
		// this.historyManager.addEvent('onHistoryChange', this.navigate.bind(this));
		
		// var startLocation = this.historyManager.getCurrentLocation();
		// 		if(startLocation) 
		// 			this.navigate(startLocation, true);
		// 		else if(this.options.homeSectionPath)
		// 			this.navigate(this.options.initiallyOpenedSectionPath, true);
		
		swfmacmousewheel.registerObject("mainMovie");
	},
	
	
	/*
		-- puts the flash object in focus to receive keyboard events without clicking on it
	*/
	setFocusOnFlash: function() {
		var fl = $('mainMovie');
		if(fl && fl.focus) { try { fl.focus(); } catch(e) { } }
	},
	
	/*
		-- adds/removes scrollbars
	*/
	checkHeight: function() {
		if(!Browser.Engine.presto) {
			// spare Opera - it's just too glitchy
			var allCSize = $('allContainer').getSize();
			if(allCSize.y <= 530) {
				$('innerContainer').setStyle("height", "580px");	
			} else {
				$('innerContainer').setStyle("height", "100%");	
			}
		
			if(allCSize.x < 920) {
				$('innerContainer').setStyle("width", "930px");	
			} else {
				$('innerContainer').setStyle("width", "100%");	
			}
			/*if(allCSize.y <= 530) {
				$('mainMovie').setStyle("height", "580px");	
			} else {
				$('mainMovie').setStyle("height", "100%");	
			}
		
			if(allCSize.x < 920) {
				$('mainMovie').setStyle("width", "930px");	
			} else {
				$('mainMovie').setStyle("width", "100%");	
			}*/
		}
	},
	
	
	/*
		- FROM FLASH via ExternalInterface: update historyManager
	*/
	external_Addhit: function(hitStr) {
		if(window.pageTracker && pageTracker._trackPageview)
			pageTracker._trackPageview(hitStr);
		//console.debug(hitStr);
	},


	/*
		-- FROM FLASH via ExternalInterface: update language
	*/
	external_ChangeLanguage: function(newLangId) {
		// this.language = newLangId;
	}
	
	
	
	
	
	
	
	
});

AB.implement(new Options);
var ab = new AB(globalOptions);
