//<![CDATA[
/*
 Copyright (c) 2007 Caridy Patiņo. All rights reserved.
 version 0.1.0
 Author: Caridy Patiņo (caridy at gmail.com)
*/
YAHOO.namespace("App");
(function() {

  var $B = YAHOO.CMS.Bubble,
	  $E = YAHOO.util.Event,
	  $D = YAHOO.util.Dom,
	  $ =  YAHOO.util.Dom.get;

	YAHOO.App.Core = function () {
	    var obj = {};
		try {
			obj.flags = DEFAULT_VARS;
		} catch(e) {
			obj.flags = {};
		}
        // Private Methods
		var actions = {
			navRecommendPage: function (layer, args) {
				  var e = args[0],
				      o = args[1] || {},
					  el = o.target || $E.getTarget(e);
				  var r = document.location;
				  el = $B.getAncestorByTagName( el, 'A' );
				  if (r && el) {
				    var page  = base64encode(utf16to8(r)),
				    	title = document.title;
				    document.location = YAHOO.CMS.Common.url_completion ( el.href, '_title=' + title  + '&_url=' + page );
				  }
			},
			navMPPrintableVersion: function () {
				window.open (YAHOO.CMS.Common.url_completion ( obj.navHistory[obj.navHistory.length - 1], 'tpl=tpls/printable' ),'','scrollbars=yes,width=800,height=600');
			},
			actionFormFieldFocus: function (layer, args) {
				  var el = $B.getAncestorByTagName( args[1].target, 'A' );
				  if (el && el.id && (el.id.indexOf('setfocus') === 0)) {
				  	// calculating the form field ID
				  	var field = $(el.id.slice (8, el.id.length));
					if (field) {
					  field.focus();
					}
				  }
			}
		};
	    $B.bubble.navigate.subscribe(function (layer, args) {
		  $B.processingAction (layer, args, actions);
	    });

        // Public Vars
		obj.navHistory = [];
        // Public Methods
		obj.init = function () {
		  this.navHistory.push ( window.location.href );
		};
        obj.initCategories = function () {
		    YAHOO.CMS.behaviors.Categories.load ();
		};
		obj.initSelector = function () {
		  YAHOO.util.Selector.add( 'left-column-selector' );
		  YAHOO.util.Selector.add( 'comments' );
		};
		obj.initHints = function () {
            YAHOO.CMS.widget.Tips.init();
            YAHOO.CMS.widget.Tips.config ({
                width: '250px'
            });
		};
		obj.initLocutor = function () {
		  // creating the info panel...
		  YAHOO.CMS.Common.values.hold( new YAHOO.CMS.widget.InfoPanel( 'advices',
										 {
										   handle:'advicehandle',
										   context:'ajax-advice-content',
										   webpart:'webparts/ajax/advice.inc.html',
										   force:false,
										   seconds: 60,
										   timer: 'ajax-advice-counter'
										 } ));

		};
		obj.initPlayers = function  () {
			YAHOO.CMS.Common.values.hold( new YAHOO.CMS.widget.Player ('tms-photos',
		     {
			 	context: 'tms-photos-hotspot', play: true, URL: DEFAULT_VARS.photos, mode: 'photo',
				repeating: true, seconds: 5
			 }));
		};
		obj.closing = function (items) {
		  if (items.length > 0) {
		    for(k = 0; k < items.length; k++) {
		        YAHOO.util.Dispatcher.jsLoader ( items[k].file, {after: items[k].method} );
		    }
		  }
		};
  	    return obj;
	}();

	// Initialize and render dynamic elements using onContentReady event for each webpart
    $E.onDOMReady(YAHOO.App.Core.init, YAHOO.App.Core, true);

})();
//]]>