/*
 * Custom and extended OBJECTS
 */

/**
 * Easy namespacing setup
 */
String.prototype.namespace = function(separator) {
	var ns = this.split(separator || '.'), p = window, i;
	for (i = 0; i < ns.length; i++) {
		p = p[ns[i]] = p[ns[i]] || {};
	}
};

/**
 * Creates a new, cloned instance of an Object
 * 
 * @param myObj
 * @return exact and full copy of myObj
 */
function clone(myObj) {
	if (typeof (myObj) != 'object')
		return myObj;
	if (myObj == null)
		return myObj;

	var myNewObj = new Object();

	for ( var i in myObj)
		myNewObj[i] = clone(myObj[i]);

	return myNewObj;
}

/**
 * Simple find for arrays, using comparator function when available
 */
Array.prototype.contains = function(element) {
	for ( var x = 0; x < this.length; x++) {
		if (!this[x].equals) {
			if (this[x] == element) {
				return x;
			}
		} else {
			if (this[x].equals(element)) {
				return x;
			}
		}
	}
	return false;
};

/**
 * Determines if an object (or the first of a passed in set of objects) is an
 * array
 * 
 * @return boolean
 */
function isArray() {
	if (typeof arguments[0] == 'object') {
		var criterion = arguments[0].constructor.toString().match(/array/i);
		return (criterion != null);
	}
	return false;
}

/**
 * @see http://blogger.xs4all.nl/peterned/archive/0001/01/01/156001.aspx
 */
Function.prototype.implement = function(proto) {
	for ( var i in proto) {
		this.prototype[i] = proto[i];
	}
};
Function.prototype.extend = function(constructor, prototype) {
	var base = this;
	var Extended = function() {
		base.apply(this, arguments);
		constructor.apply(this, arguments);
	};

	Extended.implement(base.prototype);
	Extended.implement(prototype);
	return Extended;
};

/*
 * GLOBALS
 */

//set up namespace for globals
("ing.wholesalebanking.campaign.globals").namespace();

//set up namespace for visual config
("ing.wholesalebanking.campaign.visual").namespace();

/*
 * START global constants 
 */
// Google API key, if needed
ing.wholesalebanking.campaign.globals.gApiKey = undefined;

ing.wholesalebanking.campaign.visual.flashObjectId = "visual-flash";
ing.wholesalebanking.campaign.visual.minFlashVersion = "6.0.0";

/* generic functions/constants used by all scrolling areas within the application */
ing.wholesalebanking.campaign.visual.autoScrollInterval = 20000;
ing.wholesalebanking.campaign.visual.detailFadeIn = 300;
ing.wholesalebanking.campaign.visual.detailFadeOut = 300;

ing.wholesalebanking.campaign.visual.overallContainerRef = "#campaign-visual-container";
ing.wholesalebanking.campaign.visual.scrollContainerRef = "#campaign-visual";
ing.wholesalebanking.campaign.visual.regularContentAreaRef = "#campaign-visual";
ing.wholesalebanking.campaign.visual.scrollAreaRef = ".scrollArea";
ing.wholesalebanking.campaign.visual.scrollContentRef = ".scroll-content";
ing.wholesalebanking.campaign.visual.itemRef = ".visualItem";
ing.wholesalebanking.campaign.visual.scrollButtonContainerRef = ".scrollNav";
ing.wholesalebanking.campaign.visual.scrollButtonNextRef = ".next";
ing.wholesalebanking.campaign.visual.scrollButtonNextOverClass = "nextOver";
ing.wholesalebanking.campaign.visual.scrollButtonPrevRef = ".previous";
ing.wholesalebanking.campaign.visual.scrollButtonPrevOverClass = "prevOver";

/* END global constants */

/* 
 * START dynamically (pre)initialized global variables 
 */

ing.wholesalebanking.campaign.visual.flashObject = undefined; // reference to flash object, IF it was created

ing.wholesalebanking.campaign.visual.indexOld = undefined; // reference to the photo that was shown before scrolling
ing.wholesalebanking.campaign.visual.indexNew = undefined; // reference to the phot that should be showing, after animation
ing.wholesalebanking.campaign.visual.toStart = false;
ing.wholesalebanking.campaign.visual.toEnd = false;
ing.wholesalebanking.campaign.visual.playing = true; // match up with auto-playing of viewer
/* END dynamically (pre)initialized global variables */

/* 
 * START helper objects, caches 
 */
/* END helper objects, caches */