function createCookie(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 readCookie(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 eraseCookie(name) {
	createCookie(name,"",-1);
}

function checkVideoSequence() {
    var showMovie = readCookie('BluespaceVideo');
    if(showMovie && showMovie=='noVid') {
        closeVideo();
    } else {
        showVideo();
        showCloseButton();
    }
    
}

function showCloseButton() {
    var button = document.getElementById('close_button');
    button.innerHTML = '<img src="/img/admin/nav-logout.gif" alt="Cerrar V&iacute;deo" title="Cerrar V&iacute;deo" style="cursor:pointer;" onclick="closeVideo();" />';
}

function hideCloseButton() {
    var button = document.getElementById('close_button');
    button.innerHTML = '';
}

function showVideo() {
    // Erase the cookie if available
    var showMovie = readCookie('BluespaceVideo');
    if(showMovie && showMovie=='noVid') {
        eraseCookie('BluespaceVideo');
        showCloseButton();
        document.getElementById('vidMessage').innerHTML='';
        document.getElementById('video_container').style.display='block';
    }
    // Call the Flash Movie
    var flashvars = {};
    var params = {};
    var attributes = {};
    attributes.id = "Smart_Blue_Video";
    swfobject.embedSWF("/flash/smart_blue/video_con_replay.swf", "movie", "516", "330", "9.0.0", "/flash/expressInstall.swf", flashvars, params, attributes);
}

function closeVideo() {
    var videoContainer = document.getElementById('video_container');
    var message = document.getElementById('vidMessage');
    message.innerHTML = '<a href="#" onclick="showVideo();"><b>Mostrar V&iacute;deo Smart Blue.</b></a>';
    videoContainer.style.display='none';
    createCookie('BluespaceVideo','noVid',365);
    hideCloseButton();
}