/*--------------------------------------------------------------------------*/

var FlashLightbox = function (pop) {
	this.pop = $(pop);
	this.player = this.pop.find('.player:first');
	this.overlay = $('#modal_overlay');
	this.path = "/static/flash/cmor/";
	this.setup();
};
FlashLightbox.prototype = {
	setup: function () {
		var self = this;
		this.detectScreensize();
		$(window).bind('resize', function () {
			self.center(self.pop);
		});
	},
	initModalOverlay: function (el) {
		el.css("height", $('body:first').height());
		$(el).show();
	},
	center: function (el) {
		$(el).css("top", 10);
		$(el).css("left", ( $(window).width() - $(el).width() ) / 2+$(window).scrollLeft());
	},
	open: function () {
		this.initModalOverlay(this.overlay);
		this.pop.show();
		
		this.pop.fadeIn(10, function () {
			setTimeout(function () {
				$('#header').addClass('active');
				$('#main').addClass('active');
			}, 1000);
		});
		
		
	},
	close: function () {
		this.pop.hide();
		this.player.html('');
		this.overlay.hide();
	},
	detectScreensize: function () {
		var w = $(window).width();
	
		/* 1440 resolution */
		if (w >= 1400) {
			this.setSize(1440, 660);
		}
		/* 1280 resolution */
		if (w >= 1240 && w < 1400) {
			this.setSize(1280, 660);
		}
		/* 1024 resolution and below */
		if (w >= 990 && w < 1240) {
			this.setSize(1024, 660);
		}
		if (w < 990) {
			this.setSize(1024, 660);
		}
	},
	setSize: function (w, h) {
		this.pop.css("width", w);
		this.pop.css("height", h);
		
		$(this.player).flash({
			swf: this.path + "takeover" + w + ".swf", 
			width: w, 
			height: h, 
			wmode: 'transparent',
			hasVersion: 9,
			hasVersionFail: function (options) { return true; }
		});
		
		this.center(this.pop);
		this.open();
	}
}

function hideFlash () {
	var lightbox = $('#lightbox');
	var player = $('#flash_player');
	var overlay = $('#modal_overlay'); 
	lightbox.hide();
	overlay.hide();
	player.html('');
}

/*---------------------------------------------------------------------------*/
$(document).ready(function(){
	new FlashLightbox($('#lightbox'));
	
});
