/*
 * -------------------------------------------------------------- utilizacion de cookies
*/
function getCookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ';', len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
} // function

function setCookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name+'='+escape( value ) +
		( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) + //expires.toGMTString()
		( ( path ) ? ';path=' + path : '' ) +
		( ( domain ) ? ';domain=' + domain : '' ) +
		( ( secure ) ? ';secure' : '' );
} // function

function deleteCookie( name, path, domain ) {
	if ( getCookie( name ) ) document.cookie = name + '=' +
			( ( path ) ? ';path=' + path : '') +
			( ( domain ) ? ';domain=' + domain : '' ) +
			';expires=Thu, 01-Jan-1970 00:00:01 GMT';
} // function

/*
..........................................................................
:: Menus desplegables de n-niveles                                      ::
..........................................................................
*/
$(document).ready(function() { // Prepara eventos del menu
    $('#nav li > ul').hide().parent()
        .bind('mouseenter', function() { despliega(this) })
        .bind('mouseleave', function() { pliega(this) });
});

function despliega(padre) {
    clearTimeout(padre.temporizador);
    $('#nav ul').parent('li').css({zIndex: 1});
    $(padre).css({zIndex: 1000})
	    .children('ul').fadeIn(300);
}

function pliega(padre) {
    padre.temporizador = setTimeout(function() {
		$(padre).children('ul').fadeOut(300);
    }, 300)
}

/*
..........................................................................
:: Clases para los elementos ultimo y primero de los listado            ::
..........................................................................
*/
$(document).ready(function(){
	$('li:first-child').addClass('first');
	$('li:last-child').addClass('last');
});

/*
..........................................................................
:: Hover para el IE6                                                    ::
..........................................................................
*/
if ($.browser.msie && $.browser.version < 7) {
	$(document).ready(function(){
		$('#nav a, #menuGlosario li').hover( function() {
			$(this).addClass('js-hover')
		}, function() {
			$(this).removeClass('js-hover')
		});
	});
}

/*
..........................................................................
:: Links en ventana nueva                                               ::
..........................................................................
*/
$(document).ready(function() {
	$('a[rel=external]').attr({target: '_blank'})
});

/*
..........................................................................
:: Plugin de jQuery para cambiar PNG's para IE6 dentro de un elemento   ::
:: Ej. uso: $('div.fulanito img').pngIE6()                              ::
:: El parametro 'blank' debe ser la ruta de un GIF transparente de 1x1  ::
..........................................................................
*/
jQuery.fn.extend({
    pngIE6: function(blank) {
        if ($.support.opacity) return this;
        if (!blank) blank = 'img/blank.gif';
        return this.each( function() {
            this.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src='+ this.src +',sizingMethod=image)';
            this.src = blank;
        });
    }
});

$(function() {
   	// iniciamos la web llamando a los filter para IE6
	$('img[src$=png]').pngIE6();

	// incrustamos el flash
	if (document.getElementById('contenidoFlash')) {
		var params ={
			'quality': 'high',
			'align': 'middle',
			'play': 'true',
			'wmode': 'transparent',
			'devicefont': 'false',
			'bgcolor': '#ffffff',
			'name': 'video',
			'allowFullScreen': 'false'
		};
		swfobject.embedSWF('video.swf', 'contenidoFlash', '628', '420', '9.0.116', 'expressinstall.swf', {}, params);
		var $nos = $('noscript');
		if ($nos.length) {
			$nos.parent().html($nos.text());
		}
	}
});
