//Connection speed script found at http://whois.ipinc.net/connect_speed_html.txt
//Flash player modifications by Allen Rowland, BlueFire Graphics


//***********************************************************
//EDIT HERE   EDIT HERE   EDIT HERE   EDIT HERE   EDIT HERE
var flvs = new Array(
	new flv("http://www.internet-spokesmodels.com/clients/toppers_movable/toppers1large.flv", 
			336, //width
			448, //height
			900, //minimum speed in kbs 15000 = 15,000 kilobytes per second
			400, //position from left
			300, //position from top (or bottom if below is true)
			false) //true = scroll with page, false = stay in place
			, //use comma to seperate videos
			
	new flv("http://www.internet-spokesmodels.com/clients/toppers_movable/toppers1medium.flv", 
			240, //width
			320, //height
			400, //minimum speed in kbs 2000 = 2,000 kilobytes per second
			400, //position from left
			450, //position from top (or bottom if below is true)
			false) //true = scroll with page, false = stay in place
			, //use comma to seperate videos
			
	new flv("http://www.internet-spokesmodels.com/clients/toppers_movable/toppers1small.flv", 
			96, //width
			128, //height
			0, //minimum speed in kbs 0 = 0 kilobytes per second
			50, //position from left
			600, //position from top (or bottom if below is true)
			false) //true = scroll with page, false = stay in place
			//if last or only video DO NOT use comma
);

var moveable = false;
var delay = "3000";
var fadeSpeed = "5";
var waitToPlay = "false";
var link = 'http://www.wine-toppers.com/Toppers.html';
var win = "_self";
var playOnce = "true";
//EDIT HERE   EDIT HERE   EDIT HERE   EDIT HERE   EDIT HERE
//***********************************************************




//***********************************************************
//DO NOT EDIT   DO NOT EDIT   DO NOT EDIT   DO NOT EDIT
var connectionSpeed = 0;
var video = null;
var LOADED = false;
var moving = false; 

document.onmouseup = stopMove;
document.onload = init();
if (document.layers) { // Netscape
    document.captureEvents(Event.MOUSEMOVE);
    document.onmousemove = captureMousePosition;
} else if (document.all) { // Internet Explorer
	document.onmousemove = captureMousePosition;
} else if (document.getElementById) { // Netcsape 6
    document.onmousemove = captureMousePosition;
}

var xMousePos = 0;
var yMousePos = 0; 
var xMousePosMax = 0; 
var yMousePosMax = 0;
window.onscroll = moveVideo;
//DO NOT EDIT   DO NOT EDIT   DO NOT EDIT   DO NOT EDIT
//***********************************************************

function captureMousePosition(e) {
    if(moving){
	
	if (document.layers) {
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    } else if (document.all) {
        xMousePos = window.event.x+document.body.scrollLeft;
        yMousePos = window.event.y+document.body.scrollTop;
        xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
        yMousePosMax = document.body.clientHeight+document.body.scrollTop;
    } else if (document.getElementById) {
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    }
		document.getElementById('internet_spokesmodels_flash').style.position = "absolute";
		if(xMousePos+video.width < xMousePosMax){
			document.getElementById('internet_spokesmodels_flash').style.left = xMousePos;
		}
		if(yMousePos+video.height < yMousePosMax){
			document.getElementById('internet_spokesmodels_flash').style.top = yMousePos;
		}
	}
}

function setMove(){
	if(moveable){
		moving = true;
	}
}

function stopMove(){
	moving = false;
}

function moveVideo(){
	if(LOADED && video.scrollWithPage){
			document.getElementById('internet_spokesmodels_flash').style.bottom = video.topBottom - document.body.scrollTop;
	}
}

function init(){
	drawCSImageTag( 'http://www.internet-spokesmodels.com/images/loader.jpg', 45112);
}

function drawCSImageTag( fileLocation, fileSize) {
	start = (new Date()).getTime();
	loc = fileLocation + '?t=' + escape(start);
	document.write('<img src="' + loc + '" onload="connectionSpeed=computeConnectionSpeed(' + start + ',' + fileSize + ');loadVideo();" style="visibility: hidden; position: absolute; left: 0; top: 0;">');
	return;
}

function computeConnectionSpeed( start, fileSize ) {
	end = (new Date()).getTime();
	connectSpeed = (Math.floor((((fileSize * 8) / ((end - start) / 1000)) / 1024) * 10) / 10);
	return connectSpeed;
}

function determineBestFlv(flvArray){
	
	for (i=0;i<flvArray.length;i++){
		if(connectionSpeed > flvArray[i].minSpeed){
			return flvArray[i];
		}
	}
	
	return flvArray[flvArray.length - 1];
}


function flv(loc, width, height, minSpeed, left, topBottom, scrollWithPage) {
	this.loc=loc;
	this.width=width;
	this.height=height;
	this.minSpeed=minSpeed;
	this.left=left;
	this.topBottom=topBottom;
	this.scrollWithPage=scrollWithPage;
}

function loadVideo(){
	
	video = determineBestFlv(flvs);
	
	document.getElementById('internet_spokesmodels_flash').style.position = "absolute";
	if(video.scrollWithPage){
		document.getElementById('internet_spokesmodels_flash').style.bottom = video.topBottom;
	}else{
		document.getElementById('internet_spokesmodels_flash').style.top = video.topBottom;
	}
	document.getElementById('internet_spokesmodels_flash').style.left = video.left;
	document.getElementById('internet_spokesmodels_flash').style.zIndex = 989;
	document.getElementById('internet_spokesmodels_flash').innerHTML = ('<div id="alternative_content">' +
			   '<a href="http://www.adobe.com/go/getflashplayer">' +
			   '<img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />' +
			   '</a>' +
			   '</div>');

	 
	var flashvars = {};
	flashvars.videoPath = video.loc;
	flashvars.videoWidth = video.width;
	flashvars.videoHeight = video.height;
	flashvars.delay = delay;
	flashvars.fadeSpeed = fadeSpeed;
	flashvars.waitToPlay = waitToPlay;
	flashvars.link = link;
	flashvars.window = win;
	flashvars.playOnce = playOnce;

	var params = {};
	params.wmode = "transparent";
	params.allowscriptaccess = "always";

	var attributes = {};

	swfobject.embedSWF("http://www.internet-spokesmodels.com/player/player.swf", "alternative_content", video.width, video.height, "8.0.0", "http://www.internet-spokesmodels.com/scripts/expressInstall.swf", flashvars, params, attributes);
	LOADED = true;
}

