/*   INSERT COPYRIGHT INFORMATION HERE
     *********************************
     INSERT INSTRUCTIONS FOR UPDATING HERE
     *************************************
*/

//***********************************************
//                POSITIONING
//***********************************************

//Position type ( 0 - Static, 1 - Relative, 2 - Dynamic )
var position_type = 0;
//x offset, used for 0-Static or 1-Relative
offsetx = 400;
//y offset, used for 0-Static or 1-Relative
offsety = 45;
//Preset position if above is 2-Dyanmic.  Options are
//0 - Top Left, 1 - Top Middle, 2 - Top Right
//3 - Middle Left, 4 - Middle, 5 - Middle Right
//6 - Bottom Left, 7 - Bottom Middle, 8 - Bottom Right
var preset_position = 8;

//***********************************************
//                TIMING OPTIONS
//***********************************************

//Time to delay showing video on page (0..n seconds)
var delay_time = 0;
//Time for video to remain on page (0..n seconds)
var remain_time = 0;
//Frequency that video shows ( 0 - every time, 1 - once per session, 2 - every x number of days )
var frequency = 0;
//Show video every (0..n) days
var frequency_days = 1;
//Seconds to fade video in for (0..n seconds)
var fadein_seconds = 0;
//Seconds to fade video out for (0..n seconds)
var fadeout_seconds = 0;

//***********************************************
//                FLASH MOVIE OPTIONS
//***********************************************

//URL for flash movie
video_url = '/flash/home.flv';
//Height of video (in pixels)
video_height = 400;
//Width of video (in pixels)
video_width = 560;
//Percent to buffer video for before playing (0-100)
var video_buffer = 80;
//User must press play button for video to play ( 0 - don't show before video, 1 - show before video )
var play_button_timing_before = 0;
//After movie stops, play button appears to replay ( 0 - don't show after video, 1 - show after video )
var play_button_timing_after = 0;
//Frame to show for Fade In/Fade Out/Mouseovers (0..n where n is last frame of video)
var frame_show_number = 0;
//URL to click to if user clicks video ( blank to not have a clickable video, otherwise a valid url to click to)
var clickable_url = '';
//Window option for clicking to URL above ( 0 - open in new browser window, 1 - open in same browser window )


delay_time = delay_time * 1000;
remain_time = remain_time * 1000;

var url_string = buildURLString();
var style_string = buildStyleString();


function buildURLString() {
	var sURL = "?a=" + video_url;

	if(delay_time > 0)
	      	sURL+= "&b=" + delay_time;
	if(remain_time > 0)
		sURL+= "&c=" + remain_time;
	sURL+= "&d=" + frequency;
	if(frequency_days > 0)
		sURL+= "&e=" + frequency_days;
	if(fadein_seconds > 0)
		sURL+= "&f=" + fadein_seconds;
	if(fadeout_seconds > 0)
		sURL+= "&g=" + fadeout_seconds;
	if(video_buffer > 0)
		sURL+= "&h=" + video_buffer;
	if(play_button_timing_before)
		sURL+= "&j=" + play_button_timing_before;
	if(play_button_timing_after)
		sURL+= "&k=" + play_button_timing_after;
	if(frame_show_number)
		sURL+= "&l=" + frame_show_number;
	if(clickable_url.length > 0) {
		sURL+= "&m=" + clickable_url; 
		sURL+= "&n=" + clickable_window_option;
	}

	return sURL;
}

function buildStyleString() {
	var style_string = '';
	if(position_type == 0)
		style_string = "style='position: absolute; z-index: 1000; left: " + offsetx + "px; top: " + offsety + "px; display: none'";
	if(position_type == 1)
		style_string = "style='position: relative; z-index: 1000; margin-left: " + offsetx + "px; margin-top: " + offsety + "px; display: none '";

	if(position_type == 2) {
		var ml = video_width/2 * -1;
		var mt = video_height/2 * -1;

		switch(preset_position) {
			case 0:
				style_string = "style='position: absolute; z-index: 1000; top: 0; left: 0; display: none'";
				break;
			case 1:
				style_string = "style='position: absolute; z-index: 1000; top: 0; left: 50%; margin-left: " + ml + "; display: none'";
				break;
			case 2:
				style_string = "style='position: absolute; z-index: 1000; top: 0; right: 0; display: none;'";
				break;
			case 3:
				style_string = "style='position: absolute; z-index: 1000; top: 50%; margin-top: " + mt + "; left: 0; display: none'";
				break;
			case 4:
				style_string = "style='position: absolute; z-index: 1000; top: 50%; left: 50%; margin-top: " + mt + "; margin-left: " + ml + "; display: none'";
				break;
			case 5:	
				style_string = "style='position: absolute; z-index: 1000; top: 50%; margin-top: " + mt + "; right: 0; display: none'";
				break;
			case 6:
				style_string = "style='position: absolute; z-index: 1000; bottom: 0; left: 0; display: none'";
				break;
			case 7:
				style_string = "style='position: absolute; z-index: 1000; bottom: 0; left: 50%; margin-left: " + ml + "; display: none'";
				break;
			case 8:
			default:
				style_string = "style='position: absolute; z-index: 1000; bottom: 0; right: 0; display: none'";
				break;
		}
	}
	return style_string;
}

function setCookie( name, value, expires, path, domain, secure ) {
        var today = new Date();
        today.setTime( today.getTime() );

        if ( expires ) {
                expires = expires * 1000 * 60 * 60 * 24;
        }

        var expires_date = '';
        if( expires ) {
                expires_date = new Date( today.getTime() + (expires) );
                expires_date = expires_date.toGMTString();
        }

        document.cookie = name + "=" +escape( value ) +
        ( ( expires ) ? ";expires=" + expires_date : "" ) +
        ( ( path ) ? ";path=" + path : "" ) +
        ( ( domain ) ? ";domain=" + domain : "" ) +
        ( ( secure ) ? ";secure" : "" );
}

function getCookie( check_name ) {
        var a_all_cookies = document.cookie.split( ';' );
        var a_temp_cookie = '';
        var cookie_name = '';
        var cookie_value = '';
        var b_cookie_found = false; 

        for ( i = 0; i < a_all_cookies.length; i++ ) {
		a_temp_cookie = a_all_cookies[i].split( '=' );
                cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
                if ( cookie_name == check_name ) {
                        b_cookie_found = true;
                        if ( a_temp_cookie.length > 1 ) {
                                cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
                        }
                        return cookie_value;
                        break;
                }
                a_temp_cookie = null;
                cookie_name = '';
        }
        if ( !b_cookie_found ) {
                return null;
        }
}

var show_video = getCookie('frequency') == null;

switch (frequency) {
        case 2:
                if(show_video) {
                        setTimeout("document.getElementById('player').style.display='block';", delay_time);
                        setCookie( 'frequency', frequency, frequency_days, '/', '', '');
                }
                break;
        case 1:
                if(show_video) {
                        setTimeout("document.getElementById('player').style.display='block';", delay_time);
                        setCookie( 'frequency', frequency, '', '/', '', '');
                }
                break;
        case 0:
        default:
                setTimeout("document.getElementById('player').style.display='block';", delay_time);
                break;
}


setTimeout("document.getElementById('player').style.display='block';", delay_time);

function startRemainingTimer() {
	setTimeout("document.getElementById('player').style.display='none';", remain_time);
}


var flashobj = '<object ' + style_string + ' classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0" width="' + video_width + '" height="' + video_height + '" id="player" align="middle">';
flashobj += '<param name="allowScriptAccess" value="sameDomain" />';
flashobj += '<param name="allowFullScreen" value="false" />';
flashobj += '<param name="movie" value="/players/swf/player.swf' + url_string + '" />';
flashobj += '<param name="wmode" value="transparent" />';
flashobj += '<param name="quality" value="high" />';
flashobj += '<param name="bgcolor" value="#ffffff" />';
flashobj += '<embed src="/players/swf/player.swf' + url_string + '" wmode="transparent" scale="exactFit" quality="high" bgcolor="#ffffff" width="' + video_width + '" height="' + video_height + '" name="player" align="middle" allowscriptaccess="sameDomain" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer"></embed>';
flashobj += '</object>';

if(show_video)
	document.write(flashobj);