/*--------------------------------------------------------------------------*/

var OmniPopUp = function(trigger, pop, width, height){
	this.trigger = $(trigger);
	this.pop = $(pop);
	this.header = this.pop.find('.header');
	this.player = this.pop.find('.player');
	this.width = width;
	this.height = height;
	this.href = $(trigger).attr("href");
	this.title = $(trigger).attr("title");
	this.setup();
};
OmniPopUp.prototype = {
    setup: function(){
		var self = this;
		this.trigger.click(function (ev) {
			ev.preventDefault();
			self.open();
		});
    },
	open: function () {	
		var self = this;
		if ($('#modal_overlay')) {
			this.initModalOverlay($('#modal_overlay'));
		}
		
		$(this.pop).center();
		$(this.pop).show();
		var closeBtn = this.pop.find('.close');
		closeBtn.click(function () {
			self.close();
		});
		
		this.header.html(this.title);
		this.embedVideo();

		//omniture
		//Omniture.trackPopup(this.pop.find('.header').text());
	},
	close: function () {
		$(this.pop).hide();
		if ($('#modal_overlay')) {
			$('#modal_overlay').hide();
		}
		this.header.html('');
		this.player.html('');
	},
	initModalOverlay: function (el) {
		el.css("height", $('body:first').height());
		$(el).show();
	},
    embedVideo: function(){
		var url = this.href;
		$(this.player).flash({
            swf: url,
            width: this.width,
            height: this.height
        }, {
            version: '8.0.0'
        }, {
            expressInstall: true
        });
    }
};

$(document).ready(function() {
	$(".meta .share").hoverIntent(
		function() {
			$(this).children(".menu").show().animate({
				bottom: '19',
				opacity: '1'
			},250);
		},
		function() {
			$(this).children(".menu").animate({
				bottom: '5',
				opacity: '0'
			},250, function() { $(this).hide() });
		}
	);
	
	$('a.omni_pop').each(function () {
		new OmniPopUp($(this), $('#video_popup'), 900, 715);
	});
	
});
