$(document).ready(function(){
    $('.flash').fadeTo('fast', 0.20, function () {
        $(this).fadeTo('slow', 1);
    });



	  

/*TREU LOGIN*/	

$("#acceso a").click(function(e) {          

 e.preventDefault();

 $("#acceder").toggle();

 $("#acceso a").toggleClass("activo");

 $('#login_login').focus();

 });

			

$("#acceder").mouseup(function() {

 return false

});

			

$(document).mouseup(function(e) {

 if($(e.target).parent("#acceso a").length==0) {

 $("#acceso a").removeClass("activo");

 $("#acceder").hide();

  }

});	



/*TREU IDIOMA*/	

$("#idiomas > a").click(function(e) {          

 e.preventDefault();

 $("#cambiar").toggle();

 $("#idiomas > a").toggleClass("activo");

 });



$("#idiomas #cambiar a").mouseup(function() {

 return false

});



$(document).mouseup(function(e) {

 if($(e.target).parent("#idiomas > a").length==0) {

 $("#idiomas > a").removeClass("activo");

 $("#cambiar").hide();

  }

});	



/*TREU CREDITS*/

$("a#credits").click(function(e) {          

 e.preventDefault();

 $("#creditos").toggle();

 $("a#credits").toggleClass("activo");

 });



$("a#credits").mouseup(function() {

 return false

});



$(document).mouseup(function(e) {

 if($(e.target).parent("a#credits").length==0) {

 $("a#credits").removeClass("activo");

 $("#creditos").hide();

  }

});	



/*TREU UNIDADES*/

$("a#anadir").click(function(e) {          

 e.preventDefault();

 if ($("#unidades").is(':visible'))

    $('#f').submit()

 else {

     $("#unidades").toggle();

     $("#unidades input").focus();

     $("a#anadir").toggleClass("activo");

 }

 });



$("a#anadir").mouseup(function() {

 return false

});



$(document).mouseup(function(e) {

 if($(e.target).parent("#unidades").length==0) {

 $("a#anadir").removeClass("activo");

 $("#unidades").hide();

  }

}); 



/*TREU SELECT*/	

$('select').each(function () {

    var orig = $(this);

    $(this).hide();

    var sb = $('<div class="selectBox" />');

    var box = $('<div class="box"><span>' +

                $(this).children('option:selected').text() +

                '</span></div>');

    var select = $('<ul class="select"></ul>');

    $(this).children('option').each(function () {

        if ($(this).val() != '') {

            var option = $(this);

            var li = $('<li />');

            var a = $('<a><span>' + $(this).text() + '</span></a>');

            a.mouseover(function () {

                $(this).addClass('hover');

            });

            a.mouseout(function () {

                $(this).removeClass('hover');

            });

            a.click(function () {

                orig.val(option.val());

                box.children('span').text($(this).text());

                select.hide();

                box.removeClass('activo');

                orig.change();

                return false;

            });

            li.append(a);

            select.append(li);

        }

    });

    sb.append(box);

    select.hide();

    sb.append(select);

    $(this).after(sb);

});

$(".selectBox .box").click(function(e) {          

 e.preventDefault();

 $(this).siblings().first().toggle();

 $(this).toggleClass("activo");

 });

			

$(".select").mouseup(function() {

 return false

});

			

$(document).mouseup(function(e) {

 if($(e.target).parent(".box").length==0) {

    $('.box').removeClass("activo");

    $('.select').hide();

 }

});	





/*VER VIDEO

$("#vervideo a").click(function(e) {          
 e.preventDefault();
 $("#video").toggle();
 $("#vervideo").toggleClass("activo");
 });

*/



if ($('#slideshowHolder').size() > 0)

 $('#slideshowHolder').jqFancyTransitions({ 

 width: 748, 

 height: 462 ,  

 navigation: true, 

 //links : true,

 strips: 8, // number of strips

delay: 5000, // delay between images in ms

stripDelay: 50, // delay beetwen strips in ms

titleOpacity: 0.7, // opacity of title

titleSpeed: 1000, // speed of title appereance in ms

position: 'alternate', // top, bottom, alternate, curtain

direction: 'fountainAlternate' // left, right, alternate, random, fountain, fountainAlternate

 });



if ($('#slideshowInterior').size() > 0)

 $('#slideshowInterior').jqFancyTransitions({ 

 width: 748, 

 height: 290 ,  

 navigation: true, 

 links : false,

 strips: 8, // number of strips

delay: 5000, // delay between images in ms

stripDelay: 50, // delay beetwen strips in ms

titleOpacity: 0.7, // opacity of title

titleSpeed: 1000, // speed of title appereance in ms

position: 'alternate', // top, bottom, alternate, curtain

direction: 'fountainAlternate' // left, right, alternate, random, fountain, fountainAlternate

 });



/*SCROLL*/

$("#vervideo a").click(function(event){

	//$(".scroll").click(function(event){

		//prevent the default action for the click event

		event.preventDefault();



		//get the full url - like mysitecom/index.htm#home

		var full_url = this.href;



		//split the url by # and get the anchor target name - home in mysitecom/index.htm#home

		var parts = full_url.split("#");

		var trgt = parts[1];



		//get the top offset of the target anchor

		var target_offset = $("#"+trgt).offset();

		var target_top = target_offset.top;



		//goto that anchor by setting the body scroll top to anchor top

		$('html, body').animate({scrollTop:target_top}, 500);

});





   

}); 


