jQuery.cookie=function(name,value,options){if(typeof value!='undefined'){options=options||{};if(value===null){value='';options=$.extend({},options);options.expires=-1;}var expires='';if(options.expires&&(typeof options.expires=='number'||options.expires.toUTCString)){var date;if(typeof options.expires=='number'){date=new Date();date.setTime(date.getTime()+(options.expires*24*60*60*1000));}else{date=options.expires;}expires='; expires='+date.toUTCString();}var path=options.path?'; path='+(options.path):'';var domain=options.domain?'; domain='+(options.domain):'';var secure=options.secure?'; secure':'';document.cookie=[name,'=',encodeURIComponent(value),expires,path,domain,secure].join('');}else{var cookieValue=null;if(document.cookie&&document.cookie!=''){var cookies=document.cookie.split(';');for(var i=0;i<cookies.length;i++){var cookie=jQuery.trim(cookies[i]);if(cookie.substring(0,name.length+1)==(name+'=')){cookieValue=decodeURIComponent(cookie.substring(name.length+1));break;}}}return cookieValue;}};

$(document).ready(function(){
						   
	$('div').pngFix();
	
	if($.cookie('apartado')){
		if($.cookie('apartado').indexOf("html")!=-1){
			$("a[@href='"+$.cookie('apartado')+"']").addClass("activo");
		}else{
			$("a[@rev='"+$.cookie('apartado')+"']").addClass("activo");
		}
	}else{
		$("a[@rev='1']").addClass("activo");
	}
 
	$('#pestanas').tabs(parseInt($.cookie('seccion')),{ fxSlide: true, fxFade: true, fxSpeed: 'fast' });
	$('#container').triggerTab($.cookie('seccion'));
	
	$("#not1").click(function () {
	  $("#not1_a").slideToggle("slow");
	});
	$("#not2").click(function () {
	  $("#not2_a").slideToggle("slow");
	});
	$("#nov1").click(function () {
	  $("#nov1_a").slideToggle("slow");
	});
	
	$("#printt").click(function () {
	  window.print();
	  return false;
	});
	
	$("a[@rel='home']").click(function(){
		$.cookie('seccion', '1'); 
		$.cookie('apartado', '1'); 
	});
	
	$("a[@rel='idiomas']").click(function(){
										  
		if($.cookie('apartado')=="" || $.cookie('apartado')==undefined){
			var urll="presentacion.html";
		}else if($.cookie('apartado').indexOf(".html")==-1){
			var urll=$("a[@rev='"+$.cookie('apartado')+"']").attr("href");
		}else{
			var urll=$.cookie('apartado');
		}
		if(urll.indexOf("_i.")==-1){
			urll=urll.replace(".html","_i.html");
			location.href="default_i.html";
		}else{
			urll=urll.replace("_i.html",".html");
			location.href="default.html";
		}
		return false;
	});
	$(".fade").click(function(){
		$('#contenido').fadeOut("fast",function(){
			$('#contenido').fadeIn("def");
		});
	});
	$("a[@rel='1']").click(function(){
		$('#contenido').fadeOut("fast");
		if(this.href.indexOf("http")==-1){
			$.cookie('seccion', '1'); 
			$.cookie('apartado', this.rev); 
		}
		//recorre los elementos del array
		$(".activo").removeClass();
		$("a[@rev='"+$.cookie('apartado')+"']").addClass("activo");	
		$('#contenido').fadeIn("def");
	});
	$("a[@rel='2']").click(function(){
		$('#contenido').fadeOut("fast");
		if(this.href.indexOf("http")==-1){
			$.cookie('seccion', '2'); 
			$.cookie('apartado', this.rev); 
		}
		$(".activo").removeClass();
		$("a[@rev='"+$.cookie('apartado')+"']").addClass("activo");
		$('#contenido').fadeIn("def");
	});
	$("a[@rel='3']").click(function(){
		$('#contenido').fadeOut("fast");
		if(this.href.indexOf("http")==-1){
			$.cookie('seccion', '3'); 
			$.cookie('apartado', this.rev); 
		}
		$(".activo").removeClass();
		$("a[@rev='"+$.cookie('apartado')+"']").addClass("activo");
		$('#contenido').fadeIn("def");
	});
	$("a[@rel='4']").click(function(){
		$('#contenido').fadeOut("fast");
		if(this.href.indexOf("http")==-1){
			$.cookie('seccion', '4'); 
			$.cookie('apartado', this.rev); 
		}
		$(".activo").removeClass();
		$("a[@rev='"+$.cookie('apartado')+"']").addClass("activo");
		$('#contenido').fadeIn("def");
	});
	
	
	var urll=document.location.href;
	var secc=$.cookie('apartado');
	
	if(secc=="" || secc==undefined){
		var secc="presentacion.html";
	}else if($.cookie('apartado').indexOf(".html")==-1){
		secc=$("a[@rev='"+$.cookie('apartado')+"']").attr("href");
	}else if(urll.indexOf("_i.html")!=-1){
		if(secc.indexOf("_i.html")==-1){
			secc=secc.replace(".html","_i.html");
		}
	}else if(urll.indexOf(".html")!=-1){
		if(secc.indexOf("_i.html")!=-1){
			secc=secc.replace("_i.html",".html");
		}
	}
	
	//$.cookie('apartado',secc);
	//$('#mi_iframe').attr("src",secc);	
		
		
		// Set specific variable to represent all iframe tags.
		var iFrames = document.getElementsByTagName('iframe');

		// Resize heights.
		function iResize()
		{
			// Iterate through all iframes in the page.
			for (var i = 0, j = iFrames.length; i < j; i++)
			{
				// Set inline style to equal the body height of the iframed content.
				iFrames[i].style.height = (iFrames[i].contentWindow.document.body.offsetHeight + 20) + 'px';
			}
		}

		// Check if browser is Safari or Opera.
		if ($.browser.safari || $.browser.opera)
		{
			// Start timer when loaded.
			$('#mi_iframe').load(function()
				{
					setTimeout(iResize, 0);
				}
			);

			// Safari and Opera need a kick-start.
			for (var i = 0, j = iFrames.length; i < j; i++)
			{
				var iSource = iFrames[i].src;
				iFrames[i].src = '';
				iFrames[i].src = iSource;
			}
		}
		else
		{
			
			// For other good browsers.
			$('#mi_iframe').load(function()
				{
					// Set inline style to equal the body height of the iframed content.
					this.style.height = (this.contentWindow.document.body.offsetHeight + 20) + 'px';
				}
			);
		}
	}
);
