// JavaScript Document

/**************************************************************  SELECT DE IDIOMA ******************************************************/
/* jqTransform * by mathieu vilaplana mvilaplana@dfc-e.com * Designer ghyslain armand garmand@dfc-e.com * Version 1.0 25.09.08  */
(function($){var defaultOptions={preloadImg:true};var jqTransformImgPreloaded=false;var jqTransformPreloadHoverFocusImg=function(strImgUrl){strImgUrl=strImgUrl.replace(/^url\((.*)\)/,"$1").replace(/^\"(.*)\"$/,"$1");var imgHover=new Image();imgHover.src=strImgUrl.replace(/\.([a-zA-Z]*)$/,"-hover.$1");var imgFocus=new Image();imgFocus.src=strImgUrl.replace(/\.([a-zA-Z]*)$/,"-focus.$1")};var jqTransformGetLabel=function(objfield){var selfForm=$(objfield.get(0).form);var oLabel=objfield.next();if(!oLabel.is("label")){oLabel=objfield.prev();if(oLabel.is("label")){var inputname=objfield.attr("id");if(inputname){oLabel=selfForm.find('label[for="'+inputname+'"]')}}}if(oLabel.is("label")){return oLabel.css("cursor","pointer")}return false};var jqTransformHideSelect=function(oTarget){var ulVisible=$(".jqTransformSelectWrapper ul:visible");ulVisible.each(function(){var oSelect=$(this).parents(".jqTransformSelectWrapper:first").find("select").get(0);if(!(oTarget&&oSelect.oLabel&&oSelect.oLabel.get(0)==oTarget.get(0))){$(this).hide()}})};var jqTransformCheckExternalClick=function(event){if($(event.target).parents(".jqTransformSelectWrapper").length===0){jqTransformHideSelect($(event.target))}};var jqTransformAddDocumentListener=function(){$(document).mousedown(jqTransformCheckExternalClick)};var jqTransformReset=function(f){var sel;$(".jqTransformSelectWrapper select",f).each(function(){sel=(this.selectedIndex<0)?0:this.selectedIndex;$("ul",$(this).parent()).each(function(){$("a:eq("+sel+")",this).click()})});$("a.jqTransformCheckbox, a.jqTransformRadio",f).removeClass("jqTransformChecked");$("input:checkbox, input:radio",f).each(function(){if(this.checked){$("a",$(this).parent()).addClass("jqTransformChecked")}})};$.fn.jqTransSelect=function(){return this.each(function(index){var $select=$(this);if($select.hasClass("jqTransformHidden")){return}if($select.attr("multiple")){return}var oLabel=jqTransformGetLabel($select);var $wrapper=$select.addClass("jqTransformHidden").wrap('<div class="jqTransformSelectWrapper"></div>').parent().css({zIndex:10-index});$wrapper.prepend('<div><span></span><a href="#" class="jqTransformSelectOpen"></a></div><ul></ul>');var $ul=$("ul",$wrapper).css("width",$select.width()).hide();$("option",this).each(function(i){var oLi=$('<li><a href="#" index="'+i+'">'+$(this).html()+"</a></li>");$ul.append(oLi)});$ul.find("a").click(function(){$("a.selected",$wrapper).removeClass("selected");$(this).addClass("selected");if($select[0].selectedIndex!=$(this).attr("index")&&$select[0].onchange){$select[0].selectedIndex=$(this).attr("index");$select[0].onchange()}$select[0].selectedIndex=$(this).attr("index");$("span:eq(0)",$wrapper).html($(this).html());$ul.hide();return false});$("a:eq("+this.selectedIndex+")",$ul).click();$("span:first",$wrapper).click(function(){$("a.jqTransformSelectOpen",$wrapper).trigger("click")});oLabel&&oLabel.click(function(){$("a.jqTransformSelectOpen",$wrapper).trigger("click")});this.oLabel=oLabel;var oLinkOpen=$("a.jqTransformSelectOpen",$wrapper).click(function(){if($ul.css("display")=="none"){jqTransformHideSelect()}if($select.attr("disabled")){return false}$ul.slideToggle("fast",function(){var offSet=($("a.selected",$ul).offset().top-$ul.offset().top);$ul.animate({scrollTop:offSet})});return false});var iSelectWidth=$select.outerWidth();var oSpan=$("span:first",$wrapper);var newWidth=(iSelectWidth>oSpan.innerWidth())?iSelectWidth+oLinkOpen.outerWidth():$wrapper.width();$wrapper.css("width",newWidth);$ul.css("width",newWidth-2);$ul.css({display:"block",visibility:"hidden"});var iSelectHeight=($("li",$ul).length)*($("li:first",$ul).height());(iSelectHeight<$ul.height())&&$ul.css({height:iSelectHeight,overflow:"hidden"});$ul.css({display:"none",visibility:"visible"})})};$.fn.jqTransform=function(options){var opt=$.extend({},defaultOptions,options);return this.each(function(){var selfForm=$(this);if(selfForm.hasClass("jqtransformdone")){return}selfForm.addClass("jqtransformdone");if($("select",this).jqTransSelect().length>0){jqTransformAddDocumentListener()}selfForm.bind("reset",function(){var action=function(){jqTransformReset(this)};window.setTimeout(action,10)})})}})(jQuery);
$(document).ready(function(){

	/*disparar el desplegado*/
	if ($(".desplegable").length > 0) {
		$('.desplegable.recogido div.contDespl').hide();	
		$('.desplegable .titu6 span').each(function(){
			var txto = $(this).text();
			$(this).wrapInner('<a href="#" title="Plegar/desplegar &#8220;'+txto+'&#8221;"></a>');
		});
		$(".desplegable .titu6 a").click(function(){
			$(this).closest('.desplegable').find('div.contDespl').slideToggle();	
			$(this).closest('.desplegable').toggleClass("recogido");
			return false;
		});
	}

	/****************bordes redondeados**************/
	if ($(".urlValoracion").length > 0) {
		$('.urlValoracion').corner("4px");
	}

	/****************enlace para imprimir**************/
	if ($("div#divFunc").length > 0) {
		var idioma = document.body.className;
		//Asignar texto por defecto en castellano: Imprimir
		$("div#divFunc ul").prepend("<li><a href='#' title='Imprimir' class='imprimir'>Imprimir</a></li>");
		//Asignar texto en enlace imprimir segun Idioma
		switch(idioma){
			//ingles
			case 'en': $("a.imprimir").text("Print"); $("a.imprimir").attr("title", "Print");
			break;
			//aleman
			case 'de': $("a.imprimir").text("");
			break;
			//frances
			case 'fr': $("a.imprimir").text("");
			break;
			//catalan			
			//euskera			
			default: $("a.imprimir").text("Imprimir"); $("a.imprimir").attr("title", "Imprimir");
		}
								
		$('div#divFunc ul li a.imprimir').click(function() {
			window.print();
			return false;
		});
	}	
	
	/*PNG para IE6*/
	if ($.browser.msie && $.browser.version <= 6 ) { 
		jQuery(function($) {
			DD_belatedPNG.fix('#cabecera h1 img, #divLogin .formulario, #divLogin .formulario .frm, #divBusca #txt_busca_gnral, .jqTransformSelectWrapper a.jqTransformSelectOpen, .jqTransformSelectWrapper div span, #fndCabecera, .moduloFoto h2 a,  .fndBlanco, .fndBlanco .nvlv')
		});
	}

if ($(".divPestanias").length) {
	$('.divPestanias').tabs({fxFade: true, fxSpeed: 'normal' });
	$('.divPestanias').addClass('conJs');
	$('.divPestanias ul.pestanias').siblings('.tabs-container').find('h3').addClass('oclt');
}
	/*Pestanias de login*/
   $("#pestasLogin ul li").click(function () {
		$(this).siblings('li').toggleClass("liLoginActivo");								   
        $(this).toggleClass("liLoginActivo");
    });

	/*Select de idioma*/
	if ($("#divIdioma").length > 0) {
		$(function() {
			//find all form with class jqtransform and apply the plugin
			$("#divIdioma").jqTransform();
		});
	}

	(function($) {
	jQuery.fn.clearField = function(settings) {
		/*** Settings**/
		settings = jQuery.extend({
			blurClass: 'clearFieldBlurred',
			activeClass: 'clearFieldActive'
		}, settings);
		/*** loop each element**/
		jQuery(this).each(function() {
			/*** Set element**/
			var el = jQuery(this);
			/*** Add rel attribute* */
			if(el.attr('rel') == undefined) {el.attr('rel', el.val()).addClass(settings.blurClass);}		
			/*** Set focus action* */
			el.focus(function() {	
				if(el.val() == el.attr('rel')) {
					el.val('').removeClass(settings.blurClass).addClass(settings.activeClass);					
				}
			});
			/*** Set blur action**/
			el.blur(function() {			 
				if(el.val() == '') {				
					el.val(el.attr('rel')).removeClass(settings.activeClass).addClass(settings.blurClass);
				}
			});
		});
		return jQuery;
	};
	})(jQuery);

	if ($(".inputText").length > 0) {
		$('.inputText').clearField();
	}
	if ($(".inputTxt1 input").length > 0) {
		$('.inputTxt1 input').clearField();
	}
	
	/*igualar altos*/	
	(function($){
		$.fn.igualaAltura = function() {
			masalto = 0;
			this.each(function(){
				esteAlto = $(this).height();
				if( esteAlto > masalto)
					masalto = esteAlto;
			});
			this.each(function(){
				$(this).height(masalto);
			});
		}
	})(jQuery);
	
	$(function(){
		if ($(".row .relac .inf").length > 0) {			
			$('.row').each(function() {
				$(this).find('.relac .inf').igualaAltura();
			});
		}	
	});	
	
	/*carrusel home*/
	if ($(".carrusel").length > 0) {
		$(".carrusel .news_items").css("height","330px");
		
		$(".carrusel .item").css("margin-bottom","0em");
		 $(".carrusel .container .first").addClass("activo");
		
		jQuery(".carrusel").accessNews({
			newsSpeed: "normal"
		});
		
		$(".prev, .next").hover(function(){
			$(this).css("background-position","0 100%");
		},function(){
			$(this).css("background-position","0 0");
		});
		$(".prev, .next").focus(function(){
			$(this).css("background-position","0 100%");
		});
		$(".prev, .next").blur(function(){
			$(this).css("background-position","0 0");
		});
		$(".prevOff, .nextOff").hover(function(){
			$(this).css("background-position","0 0");
		},function(){
			$(this).css("background-position","0 0");
		});
		$(".prevOff, .nextOff").focus(function(){
			$(this).css("background-position","0 0");
		});
		$(".prev, .next").blur(function(){
			$(this).css("background-position","0 0");
		});
		
		
	}
	
	/************* GALERIA HOME **/
	if ($("#galeria01").length) {
		//Click de los elementos
		$(".news_items a").click(function() {

		/*	 $(".item a").closest("li").removeClass("activo");
		  	if( $(".item strong a") ){
				$(".item strong a").unwrap();
			}
		  $(this).closest("li").addClass("activo");
			$(this).wrap("<strong title='Elemento activo'>");
			return false;*/
		});
		

	}	/************* FINGALERIA HOME NUEVA **/

	
	/*ventana imagen */
	if ($("a.popup").length > 0) {	
		$("a.popup").fancybox();
	}
	
	
			




/*MAPAS*/
if ($("#pagina #cuerpo .mapaListado").length > 0) {
	$(function() {
		/*Disparar el truco*/
		$('.divMapa img').maphilight();
		/*rollovers de los li*/
		$(".divListado li").each(function(i){
			i++;
			var numero = $(this).attr("class");	
			$(this).find('a').mouseover(function(i) {
				$('.mapaListado area.'+numero).mouseover();
				$(this).find('a').addClass('on');
				
				}).mouseout(function(i) {
				$('.mapaListado area.'+numero).mouseout();
				$(this).find('a').removeClass('on');
				})
		});
		/*rollovers de las areas*/
		$(".divMapa area").each(function(f){
		f++;
		var numero = $(this).attr("class");	
		$('area.'+numero).mouseover(function() {$('.divListado li.'+numero).addClass('on')}).mouseout(function() {$('.divListado li.'+numero).removeClass('on')});	
		});

	});
};

});

ddaccordion.init({
	headerclass: "expandable", //Shared CSS class name of headers group that are expandable
	contentclass: "categoryitems", //Shared CSS class name of contents group
	revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid value: "click", "clickgo", or "mouseover"
	mouseoverdelay: 200, //if revealtype="mouseover", set delay in milliseconds before header expands onMouseover
	collapseprev: true, //Collapse previous content (so only one open at any time)? true/false 
	defaultexpanded: [0], //index of content(s) open by default [index1, index2, etc]. [] denotes no content
	onemustopen: false, //Specify whether at least one header should be open always (so never all headers closed)
	animatedefault: false, //Should contents open by default be animated into view?
	persiststate: true, //persist state of opened contents within browser session?
	toggleclass: ["", "openheader"], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
	togglehtml: ["prefix", "", ""], //Additional HTML added to the header when it's collapsed and expanded, respectively  ["position", "html1", "html2"] (see docs)
	animatespeed: "fast", //speed of animation: integer in milliseconds (ie: 200), or keywords "fast", "normal", or "slow"
	oninit:function(headers, expandedindices){ //custom code to run when headers have initalized
		//do nothing
	},
	onopenclose:function(header, index, state, isuseractivated){ //custom code to run whenever a header is opened or closed
		//do nothing
	}
})


