/**
 * @author Brightcove, modified by Michael Bosworth to use mootools
 */

/*
var Effect = new mdp.Class({ });

Effect.Fade = function(id, options) {
   	var effect;
   	if(options != null){
  	    effect = $("$"+id).animate({
               opacity:0
           },
           (options.duration != null)? options.duration * 1000 : 500,
           function(){
            $("$"+id).css('display','none');
           }
       );
    }
   	else{
     effect = $("$"+id).animate({
               opacity:1
           },
           500,
           function(){
            $("$"+id).css('display','none');
           }
       );
   	}
   	return effect;
};

Effect.Appear = function(id, options) {
   	var effect;
   	if(options != null){
      effect = $("$"+id).animate({
               opacity:1
           },
           (options.duration != null)? options.duration * 1000 : 500,
           function(){
            $("$"+id).css('display','');
           }
       );
   	}
   	else{
       effect = $("$"+id).animate({
               opacity:1
           },
           500,
           function(){
            $("$"+id).css('display','none');
           }
       );
   	}
   	return effect;
};

Effect.toggle = function(id, effect){
	var el = $(id);
	if(el.style.display != "none"){
		el.style.display = "none";
	}
	else{
		el.style.display = "";
	}
};

Element.show = function(id) {
    $(id).style.display = "";
};
Element.hide = function(id) {
    $(id).style.display = "none";
};
Element.remove = function(id) {
    $(id).remove();
};

Element.extend({
	up: function(){
		return this.parent();
	}
});

function $F(id){
	return $(id).val();
}
*/

/*-------------------------------------------------------------------------- OBJECT DECLARATION*/
function bc_Item(){
    this._init.call(arguments);
}

bc_Item.prototype._init = function(pName, pIdPrefix)
{
    this.name = pName;
    this.selected = false;
    this.id = pIdPrefix + "_" + String(pName).replace(/[ '"]/g, ""); /*replaces all spaces and single quotes with nothing to make the name like bodyzone_Abs*/
};

bc_Item.prototype.getName = function()
{
    return this.name;
};

bc_Item.prototype.getSelected = function()
{
    return this.selected;
};

bc_Item.prototype.isSelected = function()
{
    return this.selected;
};

bc_Item.prototype.setSelected = function(pSwitch)
{
    this.selected = pSwitch;
};

bc_Item.prototype.getId = function()
{
    return this.id;
};

bc_Checkbox.prototype = new bc_Item();
bc_Checkbox.prototype.constructor = bc_Checkbox;

function bc_Checkbox(pName, pType){
    this._init(pName, null);
    this.type = pType;
    this.enabled = true;
}

bc_Checkbox.prototype.isEnabled = function()
{
    return this.enabled;
};

bc_Checkbox.prototype.setEnabled = function(pEnabled)
{
    this.enabled = pEnabled;
};


bc_BodyZoneCheckbox.prototype = new bc_Checkbox();
bc_BodyZoneCheckbox.prototype.constructor = bc_BodyZoneCheckbox;

function bc_BodyZoneCheckbox(pName){
    this._init(pName, "bodyzone");
    this.bodyZone = pName.toUpperCase();
}

bc_BodyZoneCheckbox.prototype.getBodyZone = function()
{
    return this.bodyZone;
};

bc_EquipmentCheckbox.prototype = new bc_Checkbox();
bc_EquipmentCheckbox.prototype.constructor = bc_EquipmentCheckbox;

function bc_EquipmentCheckbox(pName){
    this._init(pName, "equipment");
    this.equipment = pName.toUpperCase();
}

bc_EquipmentCheckbox.prototype.getEquipment = function()
{
    return this.equipment;
};

bc_TimeButton.prototype = new bc_Item();
bc_TimeButton.prototype.constructor = bc_TimeButton;

function bc_TimeButton(pTime){
    this._init(pTime+" Minutes", "time");
    this.time = pTime;
    this.selected = false;
}

bc_TimeButton.prototype.getTime = function()
{
   return this.time;
};

bc_PlaylistItem.prototype = new bc_Item();
bc_PlaylistItem.prototype.constructor = bc_PlaylistItem;

function bc_PlaylistItem(){
   var item = {}; /*temporary object so that we can assign local variables after the loop*/

    $.extend(item, arguments[0]);
    
    this._init(item.name, "title");
    this.hidden = false;
    /*this.name = item.name;
    //this.id = "title_" + item.name.replace(/ /g, ""); //replaces all spaces with nothing to make the name like title_MegaPushups
    */
    this.orderNumber = null;
    this.bodyZones = item.bodyZones;
    this.equipment = item.equipment;
    this.thumbnail = item.thumbnail;
    this.videoId = item.videoId;
    this.description = item.description;
    this.time = item.time;
    this.thumbnail = item.thumbnail;
    this.selected = item.selected;
    this.raw = null;
}

bc_PlaylistItem.prototype.getTime = function()
{
   return this.time;
};

bc_PlaylistItem.prototype.getBodyZones =  function()
	{
		return this.bodyZones;
	};

bc_PlaylistItem.prototype.getEquipment =  function()
	{
		return this.equipment;
	};

bc_PlaylistItem.prototype.getThumbnail =  function()
	{
		return this.thumbnail;
	};

bc_PlaylistItem.prototype.getVideoId =  function()
	{
		return this.videoId;
	};

bc_PlaylistItem.prototype.getTime =  function()
	{
		return this.time;
	};

bc_PlaylistItem.prototype.isHidden =  function()
	{
		return this.hidden;
	};

bc_PlaylistItem.prototype.setHidden =  function(pValue)
	{
		this.hidden = pValue;
	};

bc_PlaylistItem.prototype.getOrderNumber =  function()
	{
		return this.orderNumber;
	};

bc_PlaylistItem.prototype.setOrderNumber = function(pOrderNumber)
	{
		this.orderNumber = pOrderNumber;
	};



bc_LineupItem.prototype = new bc_Item();
bc_LineupItem.prototype.constructor = bc_PlaylistItem;

function bc_LineupItem(){
		var item = $.extend({}, arguments[0]); /*temporary object so that we can assign local variables after the loop*/

		this._init(item.name, "lineup_");
		this.bodyZones = item.bodyZones;
		this.equipment = item.equipment;
		this.thumbnail = item.thumbnail;
		this.description = item.description;
		this.videoIds = item.videoIds;
		this.time = item.time;
		this.thumbnail = item.thumbnail;
		this.selected = item.selected;
}

bc_LineupItem.prototype.getBodyZones= function()
	{
		return this.bodyZones;
	};

bc_LineupItem.prototype.getEquipment= function()
	{
		return this.equipment;
	};

bc_LineupItem.prototype.getVideoId= function()
	{
		return this.videoId;
	};

bc_LineupItem.prototype.getThumbnail= function()
	{
		return this.thumbnail;
	};

bc_LineupItem.prototype.getDescription= function()
	{
		return this.description;
	};

bc_LineupItem.prototype.getTime = function()
	{
		return this.time;
	};
/*--------------------------------------------------------------------------*/

var apiToken = encodeURIComponent("bkkyRXZCC4pq_wrL6cEux_XpNsb2Z6xDVH-OJJ7Qtlw.");

function setCookie()
{
	var cookie = {};
	cookie.path = "/";
	cookie.secure = "";
	cookie.domain = "";

    $.extend(cookie, arguments[0]);

	document.cookie = cookie.name+"="+cookie.data+"; expires="+cookie.expires+"; path=/";
}

function deleteCookie()
{
	var cookie = {};
	cookie.path = "/";
	cookie.domain = "";
	cookie.secure = "";

	var args = $H(arguments[0]);
	args.keys().each(function(pKey, pIndex)
	{
		if(pKey == "name") {
            cookie.name = args.values()[pIndex];
        }
		if(pKey == "path") {
            cookie.path = args.values()[pIndex];
        }
		if(pKey == "domain") {
            cookie.domain = args.values()[pIndex];
        }
		if(pKey == "secure") {
            cookie.secure = args.values()[pIndex];
        }
	});

	var expiryDate = new Date();
	expiryDate.setTime(expiryDate.getTime() - (365 * 24 * 60 * 60 * 1000)); /*1 year ago*/
	document.cookie = cookie.name+"=; path="+cookie.path+"; domain="+cookie.domain+"; expires="+expiryDate+"";
}


/*------------------------------------------------------------------------------------

 Preloader
 A very simple image preloader object
 Author: Warpspire (http://warpspire.com/tipsresources/interface-scripting/image-preloading-revisited/)

 Usage:

 Preloader.add(path);
 Preloader.onFinish(func);
 Preloader.load();

 path: 		A string or array of strings of image paths to preload
 func:     A function or array of functions to be called after images are loaded
 load():   Start the preloader

 ------------------------------------------------------------------------------------*/
var Preloader =
{
    callbacks: [],
    images: [],
    loadedImages: [],
    imagesLoaded: 0,

    add: function(image)
    {
        if (typeof image == 'string') {
            this.images.push(image);
        }
        if (typeof image == 'array' || typeof image == 'object')
        {
            for (var i = 0; i < image.length; i++)
            {
                this.images.push(image[i]);
            }
        }
    },
    onFinish: function(func)
    {
        if (typeof func == 'function') {
            this.callbacks.push(func);
        }
        if (typeof func == 'array' || typeof func == 'object')
        {
            for (var i = 0; i < func.length; i++)
            {
                this.callbacks.push(func[i]);
            }
        }
    },
    load: function()
    {
        for (var i = 0; i < this.images.length; i++)
        {
            this.loadedImages[i] = new Image();
            this.loadedImages[i].onload = function()
            {
                Preloader.checkFinished.apply(Preloader);
            };
            this.loadedImages[i].src = this.images[i];
        }
    },

    checkFinished: function()
    {
        this.imagesLoaded++;
        if (this.imagesLoaded == this.images.length) {
            this.fireFinish();
        }
    },
    fireFinish: function()
    {
        for (var i = 0; i < this.callbacks.length; i++)
        {
            this.callbacks[i]();
        }
        this.images = [];
        this.loadedImages = [];
        this.imagesLoaded = 0;
        this.callbacks = [];
    }
}

/*Preloader.add(gImages);*/
/*Preloader.load();*/
