/*
	Public Properties:
		boolean flashInstalled
		integer flashVersion

	Version:
		1.0.0
		18th March 2002

	Written By:
		Tim Booker
		tim@saltstonemedia.co.uk

	Original code from:
		http://www.xs4all.nl/~ppk/js/flash.html
*/

flashInstalled = null;
flashVersion = null;

if( navigator.plugins && navigator.plugins.length ) {

	// check the Netscape plugins array

	var x = navigator.plugins[ 'Shockwave Flash' ];

	if( x ) {

		flashInstalled = true;
		if( x.description ) {
			y = x.description;
			flashVersion = y.charAt( y.indexOf( '.' ) - 1 );
		}

	} else {
		flashInstalled = false;
	}

	if( navigator.plugins[ 'Shockwave Flash 2.0' ] ) {
		flashInstalled = true;
		flashVersion = 2;
	}

} else {

	// for IE, insert a bit of VBScript to do the detect

	var vbDetect = '<script language="vbscript">\n' +
		'on error resume next\n' +
		'\n' +
		'For i = 2 to 10\n' +
		'	If Not(IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & i))) Then\n' +
		'	Else\n' +
		'		flashInstalled = true\n' +
		'		flashVersion = i\n' +
		'	End If\n' +
		'Next\n' +
		'\n' +
		'If flashInstalled = null Then\n' +
		'	flashInstalled = false\n' +
		'End If\n' +
		'</script>\n';

	document.write( vbDetect );
}

function createCookie( name, value, days ) {
	if( days > 0 ) {
		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 popOrCookie( cookieName ) {
	var isCookieSet = readCookie( cookieName );
	if( ! isCookieSet ) {
		createCookie( cookieName, true, 1 );
		window.open( 'http://www.sleepovercompany.com/xmas.html', cookieName, 'width=600,height=550' );
	}
}
