/*

This js file requires the following Script Includes to be placed in the following order before this js file.

<script type="text/javascript" src="http://media.worldvision.org/js-includes/prod/shadowbox-2.0/src/excanvas-compressed.js"></script>
<script type="text/javascript" src="http://media.worldvision.org/js-includes/prod/shadowbox-2.0/src/shadow-box-round-corners-addon-compress.js"></script>
<script type="text/javascript" src="http://media.worldvision.org/js-includes/prod/shadowbox-2.0/src/adapter/shadowbox-base.js"></script>
<script type="text/javascript" src="http://media.worldvision.org/js-includes/prod/shadowbox-2.0/src/shadowbox_wv_ver_compressed.js"></script>


*/


// Assign Default Variables for Lightbox configurations
var lightbox_default_config = {
	sb_skin_name 	: 'worldvision',
	sb_skin_path 	: 'http://media.worldvision.org/js-includes/prod/shadowbox-2.0/src/skin',
	sb_lang_id 	: 'en',
	sb_lang_path 	: 'http://media.worldvision.org/js-includes/prod/shadowbox-2.0/src/lang',
	sb_player_array : ['flv', 'html', 'iframe', 'img', 'qt', 'swf', 'wmp'],
	sb_player_path 	: 'http://media.worldvision.org/js-includes/prod/shadowbox-2.0/src/player',
	sb_config_opts 	: {flashBgColor:'#ffffff'},
	sb_is_disabled	: false
}


function compareAndAssign(obj1,obj2){
	if(typeof obj1=='object'){
		var idx;
		for(idx in obj2){
			if(typeof obj1[idx]=="undefined" || obj1[idx]==null){
				obj1[idx] = obj2[idx];
			}
		}
		
	}else{
		obj1 = obj2;
	}
	return obj1;
}

/***************************************************************************************************

For a custom configuration different from the lightbox_default_config object. Create an object with lightbox_object_config as the variable name and define the
properties different from the lightbox_default_config object. 

For Example; to assign a different skin name and path values, just include the new values for those properties. 

lightbox_object_config = {
	sb_skin_name:'name-path',
	sb_skin_path:'include-path-for-skins'
	
}

Note: 	In order for this to work, the lightbox_default_config object has to be assigned before this js include. 
		Also be aware that properties that are assigned to invalid values will cause errors to the lightbox feature. 

**********************************************************************************************************************************************************/


// Check for custom configurations included by developer.
// undefined configurations variables will be assigned to defaults value via compareAndAssign function

if(lightbox_object_config){
	lightbox_object_config = compareAndAssign(lightbox_object_config,lightbox_default_config);
}else{
	var lightbox_object_config = lightbox_default_config;
}



// Load Required Shadowbox Skin, Language Settings, and Player
try{
		Shadowbox.loadSkin(lightbox_object_config.sb_skin_name, lightbox_object_config.sb_skin_path);
		Shadowbox.loadLanguage(lightbox_object_config.sb_lang_id, lightbox_object_config.sb_lang_path);
		Shadowbox.loadPlayer(lightbox_object_config.sb_player_array, lightbox_object_config.sb_player_path);
}catch(e){
	lightbox_object_config.sb_is_disabled = true;
}

// This function configures the options needed for Shadowbox
var configure_lightbox = function(options,isdisabled){

	if(isdisabled!=true){
		// Add Shadowbox Options to page for reference review API http://www.mjijackson.com/shadowbox/doc/api.html
		if(typeof options != "object"){
			options = {
				flashBgColor:"#ffffff"
    			}
		}
   
   		// The Callback function after initialization was a code modification to allow the canvas rounded corners to be implemented
   		var init_cb = function(){};
	
		// This statement is dependent on the rounded corners being present. shadow-box-round-corners-addon-compress.js
   		if(typeof configureElements=="function"){init_cb = configureElements}

		// Initialization Call For Shadowbox Object
    		Shadowbox.init(options, init_cb);
	}

};


var attachTemplateLightBox = function(elms){
	//alert(elms[0].toSource());
	if(typeof elms == "array"){
		if(elms.length > 0){
			for(var n=0;n<elms.length;n++){
				if(elms[n].length>=3){shadowboxAttachEvent(elms[0],elms[1],elms[2])};		
			}
		}
	}
}


var reportLightBoxToOmniture = function(v,obj,t,acct){
	if((!WVOM || !v) || (!obj || v=='')){return false}
	try{
		acct = (acct) ? acct : WVOM.acct;
		t = (typeof t==='string') ? t : 'o'; 
		var s=s_gi(acct);
		s.tl(obj,t,v);
		return true;
	}catch(e){return false}	
}



// Test for currently used window.onload function 
var winOnload = (typeof window.onload == "function") ? window.onload : null;

// Assign Shadoxbox Configuration During Window Onload Event
window.onload = function(){
	if(winOnload!=null){winOnload();}
	configure_lightbox(lightbox_object_config.sb_config_opts,lightbox_object_config.sb_is_disabled);
	if(lightbox_default_config.sb_is_disabled!=true){
		if(document.getElementById('wvuswebfeedbacklink')){
			var fblink = document.getElementById('wvuswebfeedbacklink');
			shadowboxAttachEvent('wvuswebfeedbacklink','onclick',{player:'iframe',title:fblink.title,content:fblink.href,width:600,height:440},'bot_lbx_feedback');
		}
	}
};





/**
 *  Allow shadbox.open function to be attached to an element through an event

 *
 * @param      	Object/String 	elm	The HTML Element Object if Object or HTML Id is string
 * @param      	String		event	Event of HTML Element
 * @param	Object		options	Shadowbox Options for Shadowbox.open reference to http://www.mjijackson.com/shadowbox/doc/usage.html#usage-advanced 	
 */
var shadowboxAttachEvent = function(elm,e,opts,rto){
	try{
		rtnValue = (e == "onclick") ? false : null;
		if(typeof elm === "string"){elm =  document.getElementById(elm)}
		var rl = (typeof rto=== "string") ? function(){try{reportLightBoxToOmniture(rto,this)}catch(e){}} : function(){};
		elm[e] = function(){
			if(Shadowbox.open){
				if(typeof opts === "string" || typeof opts !== "object"){
					opts = {}
				}
				try{rl();}catch(e){}
				Shadowbox.open(opts);
			}
			return rtnValue;	
		}
	}catch(e){}							
}
