/**
 * Base JS object
 */
window.Base = {
	p: {
		jQ: {
			swf: '#mainflash, #youtubeflash',
			mepForm: '#get-meplist'
		},

		swf: {
			'mainflash': {
				u: "/static/swf/widget.swf",
				w: 700,
				h: 366,
				v: "9.0.0",
				c: "#001031"
			},
			'youtubeflash': {
				u: "http://www.youtube.com/v/lacKIL779Pc&hl=en&fs=1",
				w: 425, 
				h: 344,
				v: "9.0.0",
				c: "#001031"
			}
		}
	},

	DOM: {
		swfObject: function(i) {
			// Ensure swfobject loaded - note no caps
			if (typeof window.swfobject == "undefined") {
				return;
			}
			var conf = Base.p.swf[this.id];
			swfobject.embedSWF(conf.u, this.id, conf.w, conf.h, conf.v, {}, {bgcolor: conf.c}, {});
		}
	},

	Events: {
		addAutoSubmit: function(i) {
			// When select dropdown changed, automatically submit the form
			jQuery(this).find("select").change(Base.Events.autoSubmit);
		},
		autoSubmit: function(ev) {
			jQuery(this).parents("form").submit();
		}
	},

	go: function() {
	    
	    // Detect if url contains timetolead.eu - if so, put the full path into the (unspecified) widget
        // if(window.location.host.search('timetolead.eu') > -1 ) { 
        //   	Base.p.swf.mainflash.u = "http://wwfmep.webfactional.com/static/swf/widget.swf"
        // }
        
		// Detect language
		Base.lang = jQuery("body").attr("lang");
		// If language, then change swf file reference
		if (Base.lang != "") {
			Base.p.swf.mainflash.u = Base.p.swf.mainflash.u.replace(/widget.swf/, Base.lang + "_widget.swf");
		}
		// Add Flash with swfobject
		jQuery(Base.p.jQ.swf).each(Base.DOM.swfObject);

		// turn any Take-Action MEP form into auto-submit-on-change
		jQuery(Base.p.jQ.mepForm).each(Base.Events.addAutoSubmit);
	}
};

if (typeof window.jQuery != "undefined") {
	$("html").addClass("js");
	$().ready(Base.go);
}
