var my_vsp = 'http://yakkingheads.com/client/dream_makers.js?swf=http://yakkingheads.com/client/dream_makers.swf&flv=http://flash.yourvideopartner.com/files/host_us/viking_spas.flv&start=normal&close=close&play_when=1&align_right=true&show_loading=yes&width=427&height=240&vlm=80&x_off=185';

function parseGetVars(url) {
	var map = {};
	var parts = url.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
	map[key] = value;
	});
	return map;
}
var getVars = parseGetVars(my_vsp);

var my_swf = getVars['swf'];
var vsp_flv = getVars['flv'];


var x_off = getVars['x_off'];


	var ma_a = getVars['width'] / 480;
	var ma_b = 200 * ma_a;
	var w = Math.round(ma_b);
	
	var ma_c = w / 200;
	var ma_d = 100 * ma_c;
	var h = Math.round(ma_d);
//var w = 200;
//var h = 150;

/* Playback Parameters */
if(getVars['start'] == 'mini')
{
	var shrink_on_start = 'yes';
}
else
{
	var shrink_on_start = 'no';	
}

if(getVars['close'] == 'shrink')
{
	var shrink_on_end = 'yes';
	var shrink_on_stop = 'yes';
	var close_on_end = 'no';
	var close_on_stop = 'no';
}
else
{
	var shrink_on_end = 'no';
	var shrink_on_stop = 'no';
	var close_on_end = 'yes';
	var close_on_stop = 'yes';	
}

if(getVars['show_loading'] == '')
{
	var show_loading = 'yes';
}
else
{
	var show_loading = getVars['show_loading'];
}


if(getVars['vlm'] == '')
{
	var vlm = 80;
}
else
{
	var vlm = getVars['vlm'];
}

var vlm = getVars['vlm'];

/*
	Switch Mode:
	1: Sequential
	2: Random
*/
var switchMode = 2;

/* Date Range:
	If set to false, the optional date range parameter is ignored
	If set to true .. the swf is only displayed if it falls on that reange.
*/
var useDateRange = false;

/*
	Properties are specified as follows:
	'url,width,height,lf_Position, lf_Position_Dynamic, lf_OffSet_Top_Position, lf_OffSet_Left_Position,right_align,play_when,start_date,end_date,small_width, small_height'
	play_when: 1=any, 2=first visit only, 3=subsequent visits
	date format: {m/d/y H:M} e.g. {9/1/09 13:15} or just the time {9:30}. if blank, just use {}	
*/
var arr_GLOBAL_SOURCE = new Array
(
	my_swf+','+getVars['width']+','+getVars['height']+',3,3,0,0,'+getVars['align_right']+','+getVars['play_when']+',{},{},'+w+','+h

);
/* End Properties */




/*
YHeads-Player playerbase .JS file.
Version 1.5.0.0
Last Modified: 11/29/2009
*/


/* BEGIN --- cookie functions */

var firstVisit = true;

function getCookie(c_name) {
	if (document.cookie.length>0) {
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1) {
			firstVisit = false;
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1)
				c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return "";
}

function setCookie(c_name,value,expiredays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

var cookieName = "swfID";
var cookieVal = getCookie(cookieName);
var swfIndex = 0;

/* END --- cookie functions */


/* START --- Date Check functions */
function validRange(s, e) {
	if ( !s && !e ) {
		return false;
	}
	var v = false;
	if ( s ) {
		v = validDate(s,true)
	}
	if ( e ) {
		var v_e = validDate(e,false)
		if ( v ) {
			v = v_e;
		}
	}
	return v;
}

function validDate(dt,s) { //yy,mm,dd,hh,mm,ss

	if (!dt)
		return false;
	
	var today = new Date();
	
	dt = dt.replace('{', '');
	dt = dt.replace('}', '');
	var y = 0;
	var m = 0;
	var d = 0;
	var hh = 0;
	var mm = 0;
	
	var arr_dt = dt.split(' ');
	if ( arr_dt[0].split('/')[2]) {
		y = arr_dt[0].split('/')[2];
		m = arr_dt[0].split('/')[0] - 1;
		d = arr_dt[0].split('/')[1];
		if (arr_dt[1]) {
			hh = arr_dt[1].split(':')[0];
			mm = arr_dt[1].split(':')[1];
		}
		var v_dt = new Date(y, m, d, hh, mm ,0);
	}
	else if (arr_dt[0].split(':')[1]) { // only time is specified
		y = today.getFullYear();
		m = today.getMonth();
		d = today.getDate();
		hh = arr_dt[0].split(':')[0];
		mm = arr_dt[0].split(':')[1];
		var v_dt = new Date(y, m, d, hh, mm ,0);
	}

	var days = 0;
	var difference = 0;
	

	var v_dt = new Date(y, m, d, hh, mm ,0);
	//alert(v_dt.toString());
	difference = v_dt - today;

	days = Math.round(difference/(1000*60*60*24));
	
	//alert(dt + ' - ' + difference);
	//y + ', ' + m + ', ' + d + ', ' + hh + ', ' + mm + ', 0');
	//alert(v_dt + ' - ' + today + ' - ' + dt + ' - ' + days);
	
	if (difference < 0 && s) {
		return true;
	}
	else if(difference > 0 && !s) {
		return true;
		
	}
	return false;
}

/* END ------ Date Check functions */

var arr_GLOBAL = new Array();

if (useDateRange) {
	for ( var i=0; i<arr_GLOBAL_SOURCE.length; i++ ) {
		var arr_prop = arr_GLOBAL_SOURCE[i].split(',');
		if ( validRange(arr_prop[9], arr_prop[10]) ) {			
				arr_GLOBAL.push(arr_GLOBAL_SOURCE[i]);
		}
	}

	// if no dates are valid... just pick up the swfs with no date
	if (arr_GLOBAL.length == 0) {
		for ( var i=0; i<arr_GLOBAL_SOURCE.length; i++ ) {
			var arr_prop = arr_GLOBAL_SOURCE[i].split(',');
			if ( !arr_prop[9] && !arr_prop[10] ) {			
					arr_GLOBAL.push(arr_GLOBAL_SOURCE[i]);
			}
		}
	}
}

// at this point, arr_GLOBAL should have valid swfs by date
// narrow down the source to just the filtered videos
if (arr_GLOBAL.length > 0) {
	arr_GLOBAL_SOURCE = arr_GLOBAL;
	arr_GLOBAL = new Array();
}

// now filter by visit
for ( var i=0; i<arr_GLOBAL_SOURCE.length; i++ ) {
	var arr_prop = arr_GLOBAL_SOURCE[i].split(',');
	if ( firstVisit && (arr_prop[8] == 1 || arr_prop[8] == 2) ) {
		arr_GLOBAL.push(arr_GLOBAL_SOURCE[i]);
	}
	else if ( firstVisit == false && (arr_prop[8] == 1 || arr_prop[8] == 3) ) {
		arr_GLOBAL.push(arr_GLOBAL_SOURCE[i]);
	}
}

// if no movies quality, then ignore previous filter
/*
if (arr_GLOBAL.length > 0) {
	arr_GLOBAL = arr_GLOBAL_SOURCE;
}
*/

if ( cookieVal.length > 0 ) {
	
	if (switchMode == 1) {	
		swfIndex = Math.round(cookieVal) + 1;
		if (swfIndex >= arr_GLOBAL.length) {
			swfIndex = 0;
		}
	}
	else {
		swfIndex = Math.floor(Math.random()*(arr_GLOBAL.length))
	}
}

//alert('cookieVal: ' + cookieVal + '\nswitchMode: ' + switchMode + '\narr_GLOBAL: ' + arr_GLOBAL + '\nswfIndex: ' + swfIndex);

setCookie(cookieName, swfIndex, 7);

if(cookieVal.length > 0 && getVars['play_when'] == 2) { }
else {	
	var arr_SwfInfo = arr_GLOBAL[swfIndex].split(',');

	var lf_URL = arr_SwfInfo[0];
	var GLOBAL_WIDTH = arr_SwfInfo[1];
	var GLOBAL_HEIGHT = arr_SwfInfo[2];
	var lf_Position = arr_SwfInfo[3];
	var lf_Position_Dynamic = arr_SwfInfo[4];
	var lf_OffSet_Top_Position = arr_SwfInfo[5];
	var lf_OffSet_Left_Position = arr_SwfInfo[6];
	var rt_Align = arr_SwfInfo[7];
	var sm_GLOBAL_WIDTH = arr_SwfInfo[11];
	var sm_GLOBAL_HEIGHT = arr_SwfInfo[12];
	var lf_ID = '01010';
	var lfVersion = -1;
	var arrNavInfo = [];
	var lfString;
	var viewState = 1;



if ( shrink_on_start == undefined ) {
	shrink_on_start = "yes";
}
if ( shrink_on_stop == undefined ) {
	shrink_on_stop = "yes";
}
if ( close_on_stop == undefined ) {
	close_on_stop = "no";
}
if ( shrink_on_end == undefined ) {
	shrink_on_end = "yes";
}
if ( close_on_end == undefined ) {
	close_on_end = "no";
}
if ( show_loading == undefined ) {
	show_loading = "yes";
}

var divID = 'div' + lf_ID;

arrNavInfo.navprop = navigator.userAgent.toLowerCase();

if (navigator.vendor == 'KDE' || ( document.childNodes && ( !document.all || navigator.accentColorName ) && !navigator.taintEnabled )) {
    arrNavInfo[0] = 'kde';
    arrNavInfo[1] = 'Safari';
} else if (window.opera && document.childNodes) {
    arrNavInfo[0] = 'opr';
    arrNavInfo[1] = 'Opera';
} else if (navigator.appName.indexOf('WebTV') + 1) {
    arrNavInfo[0] = 'wtv';
    arrNavInfo[1] = 'WebTV';
} else if (navigator.product == 'Gecko') {
    arrNavInfo[0] = 'gek';
    arrNavInfo[1] = 'Gecko engine (Mozilla, Netscape 6+ etc.)';
} else if (document.getElementById) {
    arrNavInfo[0] = 'ie';
    arrNavInfo[1] = 'Internet Explorer 5+';
} else {
    arrNavInfo[0] = 'na';
    arrNavInfo[1] = 'an unknown browser';
}
if (navigator.plugins != null && navigator.plugins.length > 0)
{
    if (navigator.plugins['Shockwave Flash 2.0'] || navigator.plugins['Shockwave Flash']) {
        var swVer2 = navigator.plugins['Shockwave Flash 2.0'] ? ' 2.0' : '';
        var lfDescription = navigator.plugins['Shockwave Flash' + swVer2].description;
        var descArray = [];
        var tempArrayMajor = [];
        var versionMajor = [];
        var tempArrayMinor = [];
        var versionMinor;
        descArray = lfDescription.split(' ');
        tempArrayMajor = descArray[2].split('.');
        versionMajor = tempArrayMajor[0];
        if (descArray[3] != '') {
            tempArrayMinor = descArray[3].split('r');
        } else {
            tempArrayMinor = descArray[4].split('r');
        }
        versionMinor = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
        lfVersion = parseFloat(versionMajor + '.' + versionMinor);
    }
} else {
    for (var i = 8; i < 20; i++)
    {
        try {
            var objFlash = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.' + i);
            if (objFlash) {
                lfVersion = i;
            }
        } catch(e) {}
    }
}

function initVideo() {
      showLFOW_Video();
}

    if ((lf_Position !== 2) && (arrNavInfo[0] !== 'na')) {
        try {
            if (window.addEventListener) window.addEventListener('load', initVideo, false);
            else if (window.attachEvent) window.attachEvent('onload', initVideo);
        } catch(e) {
            showLFOW_Video();
        }
    } else {
        showLFOW_Video();
    }

function showLFOW_Video()
{
    if ((lf_Position !== 2) && (arrNavInfo[0] !== 'na')) {
        try {
            var lfDiv = document.createElement('div');
            if (lfDiv === undefined) {
                lf_Position = 'err';
            } else if (lfDiv == null) {
                lf_Position = 'err';
            } else {
                if(navigator.appName == "Microsoft Internet Explorer" && document.compatMode == "BackCompat") { //this line added by corey 02/23/2010
				lfDiv.id = divID;
                lfDiv.style.position = 'absolute';
                lfDiv.style.zIndex = 9999;
                lfDiv.style.left = 0;
                lfDiv.style.top = 0;
                lfDiv.style.height = GLOBAL_HEIGHT;
                lfDiv.style.width = GLOBAL_WIDTH;
                lfDiv.style.visibility = 'visible';
                //lfDiv.style.overflow = 'hidden';
				}/////////This area added by corey 02/23/2010
				else { ///////////////////////////////
				lfDiv.id = divID; ////////////////////
				lfDiv.style.position = 'fixed'; //////
				lfDiv.style.zIndex = 9999; ///////////
				lfDiv.style.left = 0; ////////////////
				lfDiv.style.bottom = 0; //////////////
				lfDiv.style.height = GLOBAL_HEIGHT; //
				lfDiv.style.width = GLOBAL_WIDTH; ////
				lfDiv.style.visibility = 'visible'; //
				//lfDiv.style.overflow = 'hidden'; /////
				}/////////////////////////////////////
            }
        } catch(e) {
            lf_Position = 'err';
        }
    }
    makeScript()
    if ((lf_Position !== 2) && (lf_Position !== 'err') && (arrNavInfo[0] !== 'na')) {
        lfDiv.innerHTML = lfString;
        document.body.appendChild(lfDiv);
    } else if (lf_Position !== 2) {
        if(navigator.appName == "Microsoft Internet Explorer" && document.compatMode == "BackCompat")
		{
			document.write( '<div id="' + divID +'" style="position: absolute;z-index: 999;left: 0px;top: 0px;height: '+ GLOBAL_HEIGHT +'px;width: '+ GLOBAL_WIDTH +'px;">'+ lfString +'</div>' );
		}
		else		
		{
			document.write( '<div id="' + divID +'" style="bottom:0px left:0px; z-index: 999; top:0px; height: '+ GLOBAL_HEIGHT +'px;width: '+ GLOBAL_WIDTH +'px;">'+ lfString +'</div>' );
		}
		
    } 
	else {
        
		if(navigator.appName == "Microsoft Internet Explorer" && document.compatMode == "BackCompat")
		{
			document.write( '<div id="' + divID +'" style="position: relative;z-index: 999;left: ' + lf_OffSet_Left_Position + 'px;top: ' + lf_OffSet_Top_Position + 'px;height: '+ GLOBAL_HEIGHT +'px;width: '+ GLOBAL_WIDTH +'px;">'+ lfString +'</div>' );
		}
		else		
		{
			document.write( '<div id="' + divID +'" style="bottom:0px z-index: 999;left: ' + lf_OffSet_Left_Position + 'px;top: ' + lf_OffSet_Top_Position + 'px; height: '+ GLOBAL_HEIGHT +'px;width: '+ GLOBAL_WIDTH +'px;">'+ lfString +'</div>' );
		}		
    }
    
        switch (arrNavInfo[0]) {
            case 'ie':
                if (window.onscroll === undefined) {
                    window.setInterval('ScrollHnd()', 30);
                } else {
                    window.onscroll = ScrollHnd;
                }
				window.onresize = moveVid;
				//window.onscroll = ScrollHnd;
                //window.onresize = ScrollHnd;
                //window.setInterval('ScrollHnd()', 30);
            break;
            case 'gek':
                if (window.onscroll === undefined) {
                    window.setInterval('ScrollHnd()', 30);
                } else {
                    window.onscroll = ScrollHnd;
                }
				window.onresize = moveVid;
            break;
            case 'opr':
                window.onscroll = ScrollHnd;
                window.onresize = ScrollHnd;
            break;
            case 'kde':
                window.onscroll = ScrollHnd;
                window.onresize = ScrollHnd;
            break;
            case 'wtv':
                if (window.onscroll === undefined) {
                    window.setInterval('ScrollHnd()', 30);
                } else {
                    window.onscroll = ScrollHnd;
                    window.onresize = ScrollHnd;
                }
            break;
        }
        ScrollHnd();
    
}
function ScrollHnd()
{
    var divScroll;
    var wnd;
    var screenWd = 0;
    var screenHt = 0;
    var screenX = 0;
    var screenY = 0;
    var objDoc;
    var divLeft = 0;
    var divTop = 0;

    objDoc = document;
    wnd = window;

    if (objDoc.getElementById) {
        divScroll = objDoc.getElementById(divID);
        if (divScroll.style) {
            divScroll = divScroll.style;
        }
    }
    if (window.innerHeight)
    {
        screenHt = wnd.innerHeight;
        screenWd = wnd.innerWidth;
    }
    else if (objDoc.documentElement && ( objDoc.documentElement.clientWidth || objDoc.documentElement.clientHeight ))
    {
        screenWd = objDoc.documentElement.clientWidth;
        screenHt = objDoc.documentElement.clientHeight;

    }
    else if (objDoc.body && ( objDoc.body.clientWidth || objDoc.body.clientHeight ))
    {
        screenWd = objDoc.body.clientWidth;
        screenHt = objDoc.body.clientHeight;
    }
    if (window.innerHeight)
    {
        screenY = wnd.pageYOffset;
        screenX = wnd.pageXOffset;
    }
    else if (objDoc.body && ( objDoc.body.scrollLeft || objDoc.body.scrollTop ))
    {
        screenY = objDoc.body.scrollTop;
        screenX = objDoc.body.scrollLeft;
    }
    else if (objDoc.documentElement && ( objDoc.documentElement.scrollLeft || objDoc.documentElement.scrollTop ))
    {
        screenY = objDoc.documentElement.scrollTop;
        screenX = objDoc.documentElement.scrollLeft;
    }
    divLeft = divLeft;
		if (rt_Align == 'true') /*** added 9/22/09 ***/
			divLeft += screenX;
    divTop = divTop + screenY;
    divLeft = divLeft;
		if (rt_Align == 'true'){  /*** added 9/22/09 : Modified 11/30/09 ***/
			if (viewState == 1) {
				divLeft += (screenWd - GLOBAL_WIDTH);
			}
			else {
				divLeft += (screenWd - sm_GLOBAL_WIDTH - 30);
			}
		}
		if (viewState == 1) {
	    divTop = divTop + (screenHt - GLOBAL_HEIGHT);
		}
		else {
	    divTop = divTop + (screenHt - GLOBAL_HEIGHT) + (GLOBAL_HEIGHT - sm_GLOBAL_HEIGHT);
		}
    divScroll.left = divLeft + 'px';
	if(navigator.appName == "Microsoft Internet Explorer" && document.compatMode == "BackCompat")
	{
    divScroll.top = divTop + 'px';
	}
}
function makeScript()
{
    lfString = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' width='" + GLOBAL_WIDTH + "' height='" + GLOBAL_HEIGHT + "' id='obj" + lf_ID + "' align='middle' codebase='https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,24,0' >";
    lfString += "<param name='movie' value='" + lf_URL + "' />";
    lfString += "<param name='quality' value='high' />";
    lfString += "<param name='wmode' value='transparent' />";
    lfString += "<param name='flashvars' value='x_off="+x_off+"&vlm="+vlm+"&flv_loc="+vsp_flv+"&shrink_on_start=" + shrink_on_start + "&shrink_on_stop=" + shrink_on_stop + "&close_on_stop=" + close_on_stop + "&shrink_on_end=" + shrink_on_end + "&close_on_end=" + close_on_end + "&show_loading=" + show_loading + "' />";
    lfString += "<param name='allowScriptAccess' value='always' />";
    lfString += "<param name='loop' value='false' />";
    lfString += "<embed src='" + lf_URL +"' allowScriptAccess='always' quality='high' wmode='transparent' flashvars='x_off="+x_off+"&vlm="+vlm+"&flv_loc="+vsp_flv+"&w=" + sm_GLOBAL_WIDTH + "&h=" + sm_GLOBAL_HEIGHT + "&shrink_on_start=" + shrink_on_start + "&shrink_on_stop=" + shrink_on_stop + "&close_on_stop=" + close_on_stop + "&shrink_on_end=" + shrink_on_end + "&close_on_end=" + close_on_end + "&show_loading=" + show_loading + "&awidth='" + GLOBAL_WIDTH + "&aheight='" + GLOBAL_HEIGHT + "' loop='false' width='" + GLOBAL_WIDTH + "' height='" + GLOBAL_HEIGHT + "' name='obj" + lf_ID + "' align='middle' type='application/x-shockwave-flash' pluginspage='https://www.macromedia.com/go/getflashplayer' />";
    lfString += "</object>";
}

function yh_hide() {
	ScrollHnd();
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(divID).style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.divID.display = 'none';
		}
		else { // IE 4
			document.all.divID.style.display = 'none';
		}
	}
	ScrollHnd();
}

function yh_grow() {
	ScrollHnd();
	viewState = 1;
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(divID).style.width = GLOBAL_WIDTH + 'px';
		document.getElementById(divID).style.height = GLOBAL_HEIGHT + 'px';
	}
	else {
		if (document.layers) { // Netscape 4
			document.divID.width = GLOBAL_WIDTH + 'px';
			document.divID.height = GLOBAL_HEIGHT + 'px';
		}
		else { // IE 4
			document.all.divID.style.width = GLOBAL_WIDTH + 'px';
			document.all.divID.style.height = GLOBAL_HEIGHT + 'px';
		}
	}	
	ScrollHnd();
}

function yh_shrink() {
	ScrollHnd();
	viewState = 2;
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(divID).style.width = sm_GLOBAL_WIDTH + 'px';
		document.getElementById(divID).style.height = sm_GLOBAL_HEIGHT + 'px';
	}
	else {
		if (document.layers) { // Netscape 4
			document.divID.width = sm_GLOBAL_WIDTH + 'px';
			document.divID.height = sm_GLOBAL_HEIGHT + 'px';
		}
		else { // IE 4
			document.all.divID.style.width = sm_GLOBAL_WIDTH + 'px';
			document.all.divID.style.height = sm_GLOBAL_HEIGHT + 'px';
		}
	}		
	ScrollHnd();	
}

function moveVid() {
	document.getElementById(divID).offsetLeft = lf_OffSet_Left_Position - GLOBAL_WIDTH;
	document.getElementById(divID).offsetTop = lf_OffSet_Top_Position - GLOBAL_HEIGHT;
}

} 
