
var YFCaseStudyPlayer;
if (YFCaseStudyPlayer == undefined) {
	YFCaseStudyPlayer = function(settings) {
		this.init(settings);
	};
}

YFCaseStudyPlayer.prototype.init = function(settings) {
	try {
		// Initial settings
		this.spacer = 15;
		this.thumbWidth = 105;
		this.thumbHeight = 79;
		this.minWidth = 580;
		this.minHeight = 296;
		this.settings = {
			xmlloc: './casestudies/frontpage.xml',
			swfid: 'yf-casestudyplayer',
			swfloc: "./sites/default/files/casestudyplayer/yf-casestudyplayer.swf",
			replaceid: "yf-casestudyplayer",
			cols: 4,
			rows: 3,
			flashversion: "9.0.0",
			wmode: 'opaque',
			allownetworking: 'all'
		};
		// Update settings
		for(key in settings) {
			this.settings[key] = settings[key];
		}
		
		if( this.settings.rows < 3 ) this.settings.rows = 3;
		if( this.settings.cols < 3 ) this.settings.cols = 3;
	} catch (ex) {
		throw ex;
	}
};

YFCaseStudyPlayer.prototype.embed = function() {
	var width = ((this.settings.cols + 1) * (this.thumbWidth + this.spacer)) + this.spacer;
	var height = (this.settings.rows * (this.thumbHeight + this.spacer)) + this.spacer;
	if( width < this.minWidth ) width = this.minWidth;
	if( height < this.minHeight ) height = this.minHeight;
	swfobject.embedSWF(
		this.settings.swfloc, this.settings.replaceid, width + "", height + "", this.settings.flashversion, "", 
		{xmlloc: this.settings.xmlloc, rows:this.settings.rows, cols:this.settings.cols}, 
		{wmode: this.settings.wmode, allownetworking: this.settings.allownetworking, allowscriptaccess: "always"},
		{id: this.settings.swfid}
	);
}

YFCaseStudyPlayer.prototype.movie = function() {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[this.settings.swfid];
	} else {
		return document[this.settings.swfid];
	}
}

YFCaseStudyPlayer.prototype.filterByComplete = function() {
	this.movie().filterByComplete();
}

YFCaseStudyPlayer.prototype.filterByNotComplete = function() {
	this.movie().filterByNotComplete();
}

YFCaseStudyPlayer.prototype.clearFilter = function() {
	this.movie().clearFilter();
}


