function basename (path, suffix) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Ash Searle (http://hexmen.com/blog/)
    // +   improved by: Lincoln Ramsay
    // +   improved by: djmix
    // *     example 1: basename('/www/site/home.htm', '.htm');
    // *     returns 1: 'home'
    // *     example 2: basename('ecra.php?p=1');
    // *     returns 2: 'ecra.php?p=1'

    var b = path.replace(/^.*[\/\\]/g, '');
    
    if (typeof(suffix) == 'string' && b.substr(b.length-suffix.length) == suffix) {
        b = b.substr(0, b.length-suffix.length);
    }
    
    return b;
}

$(document).ready(function(){

	/*MENU*/	
	$('#nav li a').each(function () {
		if (basename(window.location.href) == basename($(this).attr('href')))
			$(this).addClass('activo');
		else
			$(this).removeClass('activo');
	});
	
	$('#nav li li a').each(function () {
		if (basename(window.location.href) == basename($(this).attr('href'))) {
			$(this).addClass('activo');
			if ($(this).parents('[id^=m_]').size() == 0)
				$(this).parent().parent().parent().children().slice(0, 1).addClass('activo');
		} else
			$(this).removeClass('activo');
	});
	
	    /*COLORBOX*/
	$("a[rel='lightbox']").colorbox({width:700});
	$(".html_lightbox").colorbox({iframe:true, innerWidth:760, innerHeight:500});
	
	
});

function slideSwitch() {
    var $active = $('#slideshow_1  DIV.active');

    if ( $active.length == 0 ) $active = $('#slideshow_1  DIV:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow_1  DIV:first');

    // uncomment the 3 lines below to pull the images in random order
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );
    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval( "slideSwitch()", 5000 );
});

function slideSwitch2() {
    var $active = $('#slideshow_2  DIV.active');

    if ( $active.length == 0 ) $active = $('#slideshow_2  DIV:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow_2  DIV:first');

    // uncomment the 3 lines below to pull the images in random order
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );
    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval( "slideSwitch2()", 6000 );
});

function cambiamail (buzon) {
    var res = "";
    for (var n = 0; n < buzon.length; n++)
    res += String.fromCharCode(buzon.charCodeAt(n));
    if (res.indexOf('@') < 0)
    res = res + '@' + 'infotelecom.es';
    location = "mail" + "to:" + res;
}
function cambiamail2 (buzon) {
    var res = "";
    for (var n = 0; n < buzon.length; n++)
    res += String.fromCharCode(buzon.charCodeAt(n));
    if (res.indexOf('@') < 0)
    res = res + '@' + 'hotmail.com';
    location = "mail" + "to:" + res;
}
