var cookiename = "autostartcookiedemo";

function storecookie(arg) {
    var expiration = new Date((new Date()).getTime() + 31536000000);
    var cookie = cookiename + '=' + arg;
    cookie += '; expires=' + expiration.toGMTString();

    document.cookie = cookie;
}


function loadcookie() {
    var allcookies = document.cookie;
    if (allcookies == "") return false;

    var start = allcookies.indexOf(cookiename + '=');
    if (start == -1) return false;

    start += cookiename.length + 1;

    var end = allcookies.indexOf(';', start);
    if (end == -1) end = allcookies.length;

    var cookie = allcookies.substring(start, end);
    return cookie;
}


function killcookie() {
    if (confirm("Do you really want to clear the cookie?")) {
        var cookie;
        cookie = cookiename + '=';
        cookie += '; expires=Fri, 02-Jan-1970 00:00:00 GMT';
        document.cookie = cookie;
    }
}


function deletePlayer(theWrapper, thePlaceholder, thePlayerId) { 
        swfobject.removeSWF(thePlayerId);
        var tmp=document.getElementById(theWrapper);
        if (tmp) { tmp.innerHTML = "<div id=" + thePlaceholder + "></div>"; }
}


function createPlayer(thePlaceholder, thePlayerId, theFile, theStart) {
        var flashvars = {
                file:theFile, 
                autostart:theStart
        }
        var params = {
                allowfullscreen:"true", 
                allowscriptaccess:"always"
        }
        var attributes = {
                id:thePlayerId,  
                name:thePlayerId
        }
        swfobject.embedSWF("player.swf", thePlaceholder, "426", "260", "9.0.115", false, flashvars, params, attributes);
}


function initPlayer(theFile, theStart) { 
        deletePlayer('wrapper', 'placeholder1', 'player1'); 
        createPlayer('placeholder1', 'player1', theFile, theStart);
}


function startByCookie() { 
	var tmp = loadcookie();
	if(tmp != 'true') { 
		initPlayer('/rose2.flv&image=preview-rose.jpg', true);
	} else {
		initPlayer('/rose2.flv&image=preview-rose.jpg', false);
	}
	storecookie(true); 
}