/* SOUND MANAGER */

soundManager.url = '/content/'; // directory where SM2 .SWFs live

/*
 * Note that SoundManager will determine and append the appropriate .SWF file to the URL,
 * eg. /path/to/sm2-flash-files/soundmanager2.swf automatically.
 *
 * Bonus: Read up on HTML5 audio support, if you're feeling adventurous.
 * iPad/iPhone and devices without flash installed will always attempt to use it.
 *
 * Also, See the flashblock demo when you want to start getting fancy.
*/

// disable debug mode after development/testing..
//soundManager.debugMode = false;
soundManager.waitForWindowLoad = true;
// The basics: onready() callback
var mySound;

soundManager.onready(function(){
  // SM2 has loaded - now you can create and play sounds!
  if (navigator.appName == "Microsoft Internet Explorer" || /Firefox/.test(navigator.userAgent)){
	  mySound = soundManager.createSound({
		  id: 'aSound',
		  //autoLoad:true,
		  autoPlay:false,
		  url: '/sites/default/themes/basic/audio/audio.mp3'      
		  // other options here..
	  });  
	  myOnloadHandler();

	  function myOnloadHandler(){
          if (getCookie('off')!=1)
          {
                if (getCookie('posicion')){		
                	mySound.play({position:getCookie('posicion')});                	
                }
                else{
                        mySound.play();
                }
          }
	  };
  }
  else
  {	 
	  mySound = soundManager.createSound({
		  id: 'aSound',
		  autoLoad:true,
		  //autoPlay:true,
		  url: '/sites/default/themes/basic/audio/audio.mp3',    
		  onload:myOnloadHandler
		  // other options here..
	  }); 
	  function myOnloadHandler(){
          if (getCookie('off')!=1)
          {
                if (getCookie('posicion')){
                	mySound.play({position:getCookie('posicion')});           	
                }
                else{
                    mySound.play();
                }
          }
	  };
  }
});

// Optional: ontimeout() callback for handling start-up failure

soundManager.ontimeout(function(){

  // Hrmm, SM2 could not start. Flash blocker involved? Show an error, etc.?

});

jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
	return -c * ((t=t/d-1)*t*t*t - 1) + b;
};

jQuery(window).load(function (){

    jQuery('#soundOn').click(function(){
                if (getCookie('off')==1)
                {
                        setCookie('off',0);
                        mySound.play({position:getCookie('posicion')});
                }
                else
                {
                        mySound.play();
                }
    });
    jQuery('#soundOff').click(function(){
        mySound.pause();
        setCookie('off',1);
    });
    jQuery(document).click(function(){
        setCookie('posicion',mySound.position+1500);
    });



$('#block-views-botones_siguenos-block_1').removeClass('clearfix');

$('.views-field-field-agua-icono-fid > span ').click(function(){
    myUrl = $(this).find('a').attr('href');
    if (myUrl != "/%2523")
    { 
       location.href = $(this).find('a').attr('href');
     }else return false;

});

$('.ocultaMiniIcono').hover(
  function () {
    var tit = $(this).attr('titulo');
    $(this).append('<div id="altAgua" class="altAgua"><span>'+tit+'</span></div>');
  },
  function () {
   $(this).find("div:last").remove();
  }
);

//$('.ocultaMiniIcono').append('<span class="altAgua"><br>sddsffdsfdsfsdfsdf</span>');

//$('#cabeceraPie li.active-trail').nextAll().css('left', '-13px'); KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK

$('#cabeceraPie ul>li>ul>li.active-trail').nextAll().css('left', '0px');

$('#titslideshow').serialScroll({
		items:'li',
		prev:'#firstscroll img',
		next:'#lastscroll img',
		start:0,
		duration:1200,
		force:true,
                axis:'y',
		stop:true,
		lock:false,
		cycle:false,
		easing:'easeOutQuart',
		jump: false 
	});

if($('.titular').html()=='Compromisos Idi'){
  $('h1.titular').html('Compromisos I+D+i');
}
$('#titslideshow li').click(function() {
  $('#titslideshow li').removeClass("backgroundScroll");
  $(this).addClass("backgroundScroll");

  var n = '#contentResource .views-row-'+$(this).attr("class").match(/[\d\.]+/g);

  var d = '.views-row-'+$(this).attr("class").match(/[\d\.]+/g)+' .views-field-field-publicaciones-archivo-fid';

  if( $(d).html() != null){
    $("#titresource").html($(n).html());
    $("#titresource").append('<div id="titdownload">'+$(d).html()+'</div>');
  }else{
    $("#titresource").html($(n).html());
  }

});
$('#imgaddthistoolbox').click(function() {
  if($('#cajaCompartir').is(':visible')){
    $("#cajaCompartir").hide();
  }else{
    $("#cajaCompartir").show();
    $(".url-share input").val(window.location.href);    
  }
});

$("#titslideshow .views-row-first").addClass("backgroundScroll");
$("#titresource").html($("#contentResource .views-row-1").html()); 

if( $(".views-row-1 .views-field-field-publicaciones-archivo-fid").html()  != null){

  $("#titresource").append('<div id="titdownload">'+$(".views-row-1 .views-field-field-publicaciones-archivo-fid").html()+'</div>');

}else{
  $("#titdownload").hide();
}


/* MAPA AGUA INDUSTRIAL*/
  ocultaTodo();
  $('#sadIm01').show();

/* Boton Mas siguenos */
  $('#botonMas').click(function(){
    $('#block-views-botones_siguenos-block_2').toggle();
  });

  if ($('#block-views-botones_siguenos-block_2').length) {
    $('#botonMas').show();
  }

  /*Texto Buscar clickable*/
  $('#search-theme-form').parent().prev().css('cursor','pointer');
  $('#search-theme-form').parent().prev().click(function(){
    $('#search-theme-form').submit();
  });



  $('.icoServCont').hover(
    function(){
        $(this).children('.icoServTxt').css('background',"url('/img/pixel_boton_azul.png')");
    },
    function(){
        $(this).children('.icoServTxt').css('background',"url('/img/pixel_verde.png')");
    }
  );


});

function muestra(a)
{
  var id = parseInt(a) + 1;
  var nodo = "#sadIm0"+id.toString();
  ocultaTodo();
  $(nodo).show();
};
function ocultaTodo()
{
 $('#sadIm01').hide();
 $('#sadIm02').hide();
  $('#sadIm03').hide();
  $('#sadIm04').hide();
  $('#sadIm05').hide();
};


function setCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
};

function getCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
};

function deleteCookie(name) {
    setCookie(name,"",-1);
};





