//shadow-layer
var shadowLayer = {
	
	//layer width, it returns a string
	width: function(){
		
		if ($.browser.msie && $.browser.version == 8 )
	
		{
			var Width = $(document).width()-25;
			
		} else {
		
			var Width = $(document).width();
		}
	return Width;
	
	},
	
	//layer height, it returns a string
	height: function() {
		
		if ($.browser.msie && $.browser.version == 8 )
	
		{
			var Height = $(document).height()-20;
			
		} else {
		
			var Height = $(document).height();
		}
		
		return Height;
	},
	
	
	//template ALTA PRACTICAS
	template_APRACTICAS:	"	<div class='shadow-layer hidden' id='Sombra'> </div>" +
							"	<div class='info-loader mod-practica-form hidden' style='top:40px;' id='form-contacto'>" +
							"		<div class='m-head'><h2>Dar de alta una oferta</h2><p class='u-close'><a href='#' title='cerrar' onclick='shadowLayer.closed();'>cerrar</a></p></div>" + 
							"		<div class='m-content'><iframe width='100%' scrolling='no' frameborder='0' id='frm_ventana_alta'></iframe></div>" +
							"	</div>",
							
	//template ALTA PRACTICAS
	template_VERTELEFONO:	"	<div class='shadow-layer hidden' id='Sombra'> </div>" +
							"	<div class='info-loader mod-vertelefono-form hidden' id='form-contacto'>" +
							"		<div class='m-head'><h2>Tel&eacute;fono de Contacto</h2><p class='u-close'><a href='#' title='cerrar' onclick='shadowLayer.closed();'>cerrar</a></p></div>" + 
							"		<div class='m-content'><iframe width='100%' scrolling='no' frameborder='0' id='frm_ventana_vertlf'></iframe></div>" +
							"	</div>",
							
														
	//template ENVIAR AMIGO
	template_AMIGO:	"	<div class='shadow-layer hidden' id='Sombra'> </div>" +
							"	<div class='info-loader mod-contact-form mod-publish-form hidden' id='form-contacto'>" +
							"		<div class='m-head'><h2>Enviar a un amigo</h2><p class='u-close'><a href='#' title='cerrar' onclick='shadowLayer.closed();'>cerrar</a></p></div>" + 
							"		<div class='m-content'><iframe width='100%' scrolling='no' frameborder='0' id='frm_ventana_amigo'></iframe></div>" +
							"	</div>",

	//template MFO
	template_MFO: 	"	<div class='shadow-layer hidden' id='Sombra'> </div>" +
						"	<div class='info-loader mod-contact-form hidden' style='visibility:hidden;' id='form-contacto'>" +
						"		<div class='m-head'><h2>Solicitar informaci&oacute;n sin compromiso</h2><p class='u-close'><a href='#' title='cerrar' onclick='shadowLayer.closed();'>cerrar</a></p></div>" + 
						"		<div class='m-content'><iframe width='100%' scrolling='no' frameborder='0' id='frm_ventana'></iframe></div>" +
						"	</div>",

	//you can set a custom template shadowLayer.create("<div class='custom-class hidden'></div>")
	create_APRACTICAS: function(template_APRACTICAS) {
			
	if (template_APRACTICAS == undefined) {
		
		var template_APRACTICAS = this.template_APRACTICAS;
	}
	
	$("body").append(template_APRACTICAS);
	//$(".shadow-layer").css("width", this.width).css("height", this.height).fadeIn("slow");

	},
	
	//you can set a custom template shadowLayer.create("<div class='custom-class hidden'></div>")
	create_VERTELEFONO: function(template_VERTELEFONO) {
			
	if (template_VERTELEFONO == undefined) {
		
		var template_VERTELEFONO = this.template_VERTELEFONO;
	}
	
	$("body").append(template_VERTELEFONO);
	//$(".shadow-layer").css("width", this.width).css("height", this.height).fadeIn("slow");

	},
	
	//you can set a custom template shadowLayer.create("<div class='custom-class hidden'></div>")
	create_AMIGO: function(template_AMIGO) {
			
	if (template_AMIGO == undefined) {
		
		var template_AMIGO = this.template_AMIGO;
	}
	
	$("body").append(template_AMIGO);
	//$(".shadow-layer").css("width", this.width).css("height", this.height).fadeIn("slow");

	},

	//you can set a custom template shadowLayer.create("<div class='custom-class hidden'></div>")
	create_MFO: function(template_MFO) {
			
	if (template_MFO == undefined) {
		
		var template_MFO = this.template_MFO;

	}
	
	$("body").append(template_MFO);
	//$(".shadow-layer").css("width", this.width).css("height", this.height).fadeIn("slow");

	},

	//if the layer its created by server side shadowLayer.show();
	show: function() {

	$(".shadow-layer").css("width", this.width).css("height", this.height).fadeIn("slow");
	$(".info-loader").removeClass("hidden").fadeIn("slow");
	$("#form-contacto").css("visibility","visible")
	$("#Sombra").css("visibility","visible")

	},
	
	closed: function() {
	
	$(".shadow-layer").fadeOut("slow");
	$(".info-loader").fadeOut("slow");
	$(".info-loader").addClass("hidden");
	
	}

};

$("#Sombra").live("click", function() {
	shadowLayer.closed()
			});

//tabs
var tabbed = {
	
	//element that contains nav and content
	container: ".tabs-container",
	
	//the tabs navigation
	nav: ".t-nav",
	
	//the content to be tabbed
	content: ".t-content",
	
	//class added to the selected tab
	selected: "t-selected",
	
	//class added to the active content
	active: "t-active",
	
	init: function (container, nav, content, selected, active) {
		
		//if we have a container, then we can execute all code
		if ($(container).length >= 1) {
		
			//if the vars are not defined, we will get the defaults
			switch (undefined) {
			
				case container:
					var container = this.container;
				break;
				
				case nav:
			  		var nav = this.nav;
			  	break;
			  	
			  	case content:
			  		var content = this.content;
			  	break;
				
				case selected:
			  		var selected = this.selected;
			  	break;
			  	
			  	case active:
			  		var active = this.active;
			  	break;
			
			}
			
			//when the dom is ready, we get the first nav item and the first content item
		
			$(nav).each(function(){
	
				$(this).find("li:first-child").addClass(selected);
				$(this).parents(container).find(content + ":eq(0)").addClass(active);
			
			});
			
			//click event
			$(nav + " li a").live("click", function(){
	    		
				var path = $(this).attr("href");
				$(this).parents(nav).find("li").removeClass(selected);
				
				$(path).addClass(active).fadeIn();
				
				//we are looking for elements that are not "#some-id-from-anchor-link" and that are not the same class items nested like ".t-content -t-content"
				$(this).parents(container).find(content).not(path + " ," + content + " " + content).removeClass(active).hide();
				
				$(this).parent().addClass(selected);
				
		  		return false;
		  		
		 	 });
			
		}
	
	}

};


//placholder
var placeholder = {
	
	//element that contains the label and the form item (input, textarea)
	selector: ".placeholder", 
	
	init: function(selector){
		
		//if selector is undfined we get defaults
		if (selector == undefined) {
		
			selector = this.selector;
		}
		
		//elements to be attached to event
		var elements = selector + " input[type=text]," + selector + " input[type=password]," + selector + " textarea";
		
		//when the dom is ready, we check for filled inputs to hide their labels
		$(elements).each(function(){
	
			if(this.value != '') {
				
				$(this).parents(selector).find("label").hide();
					
			}
		});
		
		
		//focus event
		$(elements).focus(function(){
		
			$(this).parents(selector).addClass("focused");
			$(this).parents(selector).removeClass("blurred");
			$(this).parents(selector).find("label").fadeOut(70);
	
		});
		
		
		//blur event
		$(elements).blur(function(){
		
			$(this).parents(selector).removeClass("focused");
			$(this).parents(selector).addClass("blurred");
			
			if(this.value == '') {
				
				$(this).parents(selector).find("label").fadeIn(70);
				
				} else {
					
					$(this).parents(selector).find("label").hide();
					
				}
		});
		
	}
	
};


function rotatore_tabbed() {
		
	var num_elem = $(".rotatore-tabbed .col-l li").length;
	var ini_pos = $(".rotatore-tabbed .col-l .selected").index();
	
	$(".rotatore-tabbed .col-l li").eq(ini_pos).removeClass("selected");
	
	if (ini_pos < num_elem -1) {
		
		var ini_pos = ini_pos + 1;
	
	} else {
		
		var ini_pos = 0;
	
	}
	
	$(".rotatore-tabbed .col-l li").eq(ini_pos).addClass("selected");
	$(".rotatore-tabbed .col-r li").fadeOut();
	$(".rotatore-tabbed .col-r li:eq("+ini_pos+")").fadeIn();
	$(".rotatore-tabbed .col-r li:eq("+ini_pos+")").find(".m-txt").css({"bottom": "-100px"}).animate({ "bottom": "0" });

};




	
	

