// The MIT License
// 
// Copyright (c) 2011 CODES S.A de C.V
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.


// Autor: 		Mario Rivera Angeles (mario.rivera@codes.com.mx)
// Web Site:  	www.codes.com.mx
// Objetivo: 	Widget para mantener el contenido reducido, navegando por pestanias
// Version: 	1.0.0

jQuery.noConflict();


/**
 * @class 	Menu (Cargal el widget de la seccion de areas de negocio)
 * @param 	{}
 * @type 	{}
 */
Menu = (function(){
	jQuery.ajax({ 
		url: "/wp-content/themes/codespages/menu-contenido.html", 
		context: document.body, 
		success: function(data){
			var contenidoSubMenus = jQuery(data);			
			jQuery.each(jQuery("div#nav > ul > li:visible > a"), function(key, value){				
				var submenu = jQuery(contenidoSubMenus).filter("div").eq(key);
				if(jQuery(submenu).attr("title") == "true"){
					jQuery(value).attr("href","#");
					jQuery(value).attr("title",jQuery(submenu).html());
					jQuery(value).tooltip({ effect: 'slide', offset:[1,100]}).dynamic({ bottom: { direction: 'down', bounce: true } });
				}


			});
		}
	});	
});


/**
 * @class 	AreasDeNegocio (Cargal el widget de la seccion de areas de negocio)
 * @param 	{}
 * @type 	{}
 */
AreasDeNegocio = (function() {
			
	/**
	 * @function ajax
	 */
	if(jQuery("#showcase").length != 0){	
		jQuery.ajax({ 
			url: "/wp-content/themes/codespages/oferta-comercial-contenido.html", 
			context: document.body, 
			success: function(data){
			
				var contenidoOfertaComercial = [];	
				var tables = jQuery(data).filter("#home-oferta-negocio").find("table");
				var images = jQuery(data).filter("#home-oferta-negocio").find("img");
				
				jQuery.each(tables, function(key, value){
					contenidoOfertaComercial[key] = {url: jQuery(images[key]).attr("src"), description: jQuery(tables[key]).html() };
				});
				/**
				 * @function showcase (carga el widget de areas de negocio)
				 */
				jQuery("#showcase").showcase({
					css: { width: "400px", height: "300px" },
					animation: { type: "fade" },
					images: contenidoOfertaComercial,
					autoHide : true,
					navigator: {
						position:"top-left",
						orientation:"vertical",
						css: {
							padding:"6px",
							margin:"25px 0px 0px 0px" }
						},
					titleBar: { 
						css: { 
							height:"150px"							
						} ,
						cssClass:"showCase"
					}
				});
			}
		});
	}		
});

/**
 * @class 	Noticias (Cargal el widget de la seccion de Noticias)
 * @param 	{}
 * @type 	{}
 */
Noticias = (function(){
	if(jQuery("#s3slider").length != 0){
	
		/**
		 * @function s3Slider
		 */
		jQuery('#s3slider').s3Slider({
			timeOut: 10000
		});
		
		/**
		 * @function s3Slider
		 */
		jQuery('#s3slider1').s3Slider({
			timeOut: 10000
		});
		
		/**
		 * @function (selector de ajuste de estilos)
		 */
		jQuery("#s3slider ul").add("#s3slider1 ul").css("padding","0");		
	}	
});


/**
 * @class 	PilaresOrganizacionales (Cargal el widget de la seccion Pilares Organizacionales)
 * @param 	{}
 * @type 	{}
 */
PilaresOrganizacionales = (function(){
	if(jQuery("#photos").length != 0){	
		/**
		 * @function galleryView
		 */
		jQuery('#photos').galleryView({
			panel_width: 800,
			panel_height: 300,
			frame_width: 100,
			frame_height: 100,
			overlay_height: 200
		});
	}
});


/**
 * @class 	ExperienciaCasosDeExito (Cargal el widget de la seccion Experiencia - Casos de Exito)
 * @param 	{}
 * @type 	{}
 */
ExperienciaCasosDeExito = (function(){
	/**
	 * Establece el URL de los recursos de la seccion de casos de exito
	 * @type {string}
	 */
	var URL_PAGE_CASOS_EXITO = "/wp-content/themes/codespages/casos-de-exito.html";
	
	/**
	 * @function ajax (implementacion de ajax)
	 */
	jQuery.ajax({ 
		url: URL_PAGE_CASOS_EXITO, 
		context: document.body, 
		success: function(data){			
			jQuery(data).filter("table#casosExito").children().appendTo(jQuery("table#casosExito"));
			if(jQuery(".feature_box").length != -1){
				jQuery.fn.showFeatureText = function() {
				  return this.each(function(){    
					var box = jQuery(this);			
					var text = jQuery(this).find('p');
					
					text.css({ position: 'absolute', top: '57px' }).hide();
				
					box.hover(function(){
					  text.slideDown("fast");
					},function(){
					  text.slideUp("fast");
					});
				
				  });
				}
				jQuery('.feature_box').showFeatureText();
			}
			
		}
	});
	
});

/**
 * @class 	AcercaDePartners (Cargal el widget de la seccion Acerca de - Partners)
 * @param 	{}
 * @type 	{}
 */
AcercaDePartners = (function() {
		
	var URL_PARTNERS = "/wp-content/themes/codespages/menu-partners.html";

	/**
	 * @function ajax (implementacion de ajax)
	 */
	jQuery.ajax({
		url: URL_PARTNERS,
		context: document.body,
		success: function(data){
			jQuery(data).filter("table#partners").children().appendTo(jQuery("table#partners"));
			if(jQuery(".feature_box").length != -1){
				jQuery.fn.showFeatureText = function() {
				  return this.each(function(){
					var box = jQuery(this);
					var text = jQuery(this).find('p');

					text.css({ position: 'absolute', top: '57px' }).hide();

					box.hover(function(){
					  text.slideDown("fast");
					},function(){
					  text.slideUp("fast");
					});

				  });
				}
				jQuery('.feature_box').showFeatureText();
			}

		}
	});
	
});

/**
 * @class 	Tecnologias (Cargal el widget de la seccion de know how - tecnologias)
 * @param 	{}
 * @type 	{}
 */
Tecnologias = (function() {

	/**
	 * Establece el URL de los recursos de la seccion de tecnologias
	 * @type {string}
	 */
	var URL_PAGE_TECNOLOGIAS = "/wp-content/themes/codespages/tecnologias.html";

	/**
	 * @function ajax (implementacion de ajax)
	 */
	jQuery.ajax({ 
		url: URL_PAGE_TECNOLOGIAS, 
		context: document.body, 
		success: function(data){			
			jQuery(data).filter("table#tecnologias").children().appendTo(jQuery("table#tecnologias"));					
			if(jQuery(".feature_box2").length != -1){
				jQuery.fn.showFeatureText = function() {
				  return this.each(function(){    
					var box = jQuery(this);			
					var text = jQuery(this).find('p');
					
					text.css({ position: 'absolute', top: '57px' }).hide();
				
					box.hover(function(){
					  text.slideDown("fast");
					},function(){
					  text.slideUp("fast");
					});
				
				  });
				}
				jQuery('.feature_box2').showFeatureText();
			}
			
		}
	});
	 
});

/**
 * @class 	Clientes (Cargal el widget clientes)
 * @param 	{}
 * @type 	{}
 */
Clientes = (function() {			
	/**
	 * Establece el indice de contenido a presentar
	 * @type {array}
	 */
	var encabezados = ['Financiero', 'Gobierno', 'Otros'];
	
	/**
	 * @function 	formatText
	 * @param 		{index, panel}
	 * @type 		{int, object}
	 */
	function formatText(index, panel) {
			return encabezados[index - 1];
	}
	
	/**
	 * @function anythingSlider
	 */
	jQuery('#sliderClientes').anythingSlider({
			width               : 500,       	// if resizeContent is false, this is the default width if panel size is not defined
			height              : 400,       	// if resizeContent is false, this is the default height if panel size is not defined
			resizeContents      : true,     	// If true, solitary images/objects in the panel will expand to fit the viewport
			autoPlay            : false,     	// This turns off the entire slideshow FUNCTIONALY, not just if it starts running or not
			navigationFormatter : formatText 	// Format navigation labels with text
	})
});


/**
 * @function document.ready
 * @param {document}
 * @type {document}
 */
jQuery(window.document).ready(function(){
	jQuery("#widgetCodes").find("td").css("padding","10px");
	new Menu();
	new AreasDeNegocio();
	new Noticias();
	new PilaresOrganizacionales();
	new ExperienciaCasosDeExito();
	new AcercaDePartners();
	new Tecnologias();
	new Clientes();
});
