/*
 * Type: BC
 */


//
// constructor:
//
function InSkinContent_BC(InSkinObj) {

	this.InSkinObj = InSkinObj;

	// callbacks:
	this.onReady = null;
	this.onStart = null;
	this.onPause = null;
	this.onComplete = null;
	this.onNewItem = null;

	// specific properties for this content type:
	this.player = null;
	this.player_ready = false;
	this.started = false;
	this.is_playing = false;
	this.firstvideo = true;
}


//
// commands received from InSkin Base (Javascript):
//

// init:
InSkinContent_BC.prototype.init = function() {
}

// start:
InSkinContent_BC.prototype.start = function() {
	if (!this.started) {
		this.started = true;
		callFlash('startVideo');
		this.is_playing = true;
	}
	else {
	try {
		callFlash('pauseAd', false);
		callFlash('pauseVideo', false);
		this.is_playing = true;
	}
	catch (e) {}
	}
}

// pause:
InSkinContent_BC.prototype.pause = function() {
	try {
		callFlash('pauseAd', true);
		callFlash('pauseVideo', true);
		this.is_playing = false;
	}
	catch (e) {}
}


//
// specific methods for this content type:
//

// the player is loaded:
InSkinContent_BC.prototype.playerReady = function() {
	this.player_ready = true;
	if (this.onReady) this.onReady();
}

InSkinContent_BC.prototype.eventStart = function(obj) {
	if (this.onStart) this.onStart();
	this.is_playing = true;
}

InSkinContent_BC.prototype.eventLoad = function(obj) {
	if (this.firstvideo) {
		this.firstvideo = false;
		return;
	}

	if (this.onNewItem) this.onNewItem();
}

InSkinContent_BC.prototype.eventStop = function(obj) {
	if (this.onPause) this.onPause();
	this.is_playing = false;
}

InSkinContent_BC.prototype.eventComplete = function(obj) {
	if (this.onComplete) this.onComplete();
	//this.is_complete = true;
	//if (this.is_playing) {
	//	alert('reload ad');
	//}
}


//
// global functions:
//

// reference to our InSkin object:
var InSkinContent_BC_InSkinBase = null;

// handle "onTemplateLoaded" event:
function InSkinContent_BC_onTemplateLoaded(inskin) {
	InSkinContent_BC_InSkinBase = inskin;

	// add all necessary event handlers:
	try {
		callFlash('addEventListener', 'contentLoad', 'InSkinContent_BC_onContentLoad');
		callFlash('addEventListener', 'adStart', 'InSkinContent_BC_onStart');
		callFlash('addEventListener', 'mediaStart', 'InSkinContent_BC_onStart');
		callFlash('addEventListener', 'mediaLoad', 'InSkinContent_BC_onLoad');
		callFlash('addEventListener', 'adStop', 'InSkinContent_BC_onStop');
		callFlash('addEventListener', 'mediaStop', 'InSkinContent_BC_onStop');
		callFlash('addEventListener', 'mediaComplete', 'InSkinContent_BC_onComplete');
	}
	catch (e) {}
	
	InSkinContent_BC_InSkinBase.playerReady();
}

// handle "contentLoad" event:
function InSkinContent_BC_onContentLoad(obj) {
	InSkinContent_BC_InSkinBase.content.playerReady();
}

// handle "adStart" or "mediaStart" events:
function InSkinContent_BC_onStart(obj) {
	//alert('start');
	InSkinContent_BC_InSkinBase.content.eventStart(obj);
}

// handle "mediaLoad" events:
function InSkinContent_BC_onLoad(obj) {
	//alert('load');
	InSkinContent_BC_InSkinBase.content.eventLoad(obj);
}

// handle "adStop" or "mediaStop" events:
function InSkinContent_BC_onStop(obj) {
	//alert('stop');
	InSkinContent_BC_InSkinBase.content.eventStop(obj);
}

// handle "mediaComplete" event:
function InSkinContent_BC_onComplete(obj) {
	//alert('complete');
	InSkinContent_BC_InSkinBase.content.eventComplete(obj);
}
