var lb_movies = new Array();

function lbMovie(movieName) {
    if( document.getElementById(movieName) )
        return document.getElementById(movieName);
    else
        return false;
}

function is_movie($name) {

	if( lb_movies.length == 0 )
		return false;

	var list = "|" + lb_movies.join("|") + "|";

	if( list.indexOf('|' + $name + '|') > -1 )
		return true;
	else
		return false;
}

function lbSize(movieName, width, height) {
	lbMovie(movieName).style.width	= width + 'px';
	lbMovie(movieName).style.height	= height + 'px';
}

function browserPlugin(plugin){
	var haveplugin = false;
	if (navigator.plugins) {
		for (i=0; i < navigator.plugins.length; i++ ) {
		   if (navigator.plugins[i].name.indexOf(plugin) >= 0)
		        { haveplugin = true; }
		}
	}
	
	return haveplugin;
}

function LbVideoPlace(id){

    var options = {
		// default options
		id            : ( typeof(arguments[1].id)             != 'undefined' ) ? arguments[1].id            : 'movie',
		skin          : ( typeof(arguments[1].skin)           != 'undefined' ) ? arguments[1].skin          : '/static/swf/lb_skin.swf',
		volume        : ( typeof(arguments[1].volume)         != 'undefined' ) ? arguments[1].volume        : 100,
		height        : ( typeof(arguments[1].height)         != 'undefined' ) ? arguments[1].height        : 220,
		width         : ( typeof(arguments[1].width)          != 'undefined' ) ? arguments[1].width         : 390,
		autoplay      : ( typeof(arguments[1].autoplay)       != 'undefined' ) ? arguments[1].autoplay      : false,
		hoverControls : ( typeof(arguments[1].hoverControls)  != 'undefined' ) ? arguments[1].hoverControls : true,
		initialPic    : ( typeof(arguments[1].initialPic)     != 'undefined' ) ? arguments[1].initialPic    : '/static/swf/load.swf',
		finalPic      : ( typeof(arguments[1].finalPic)       != 'undefined' ) ? arguments[1].finalPic      : false,
		continuousPlay: ( typeof(arguments[1].continuousPlay) != 'undefined' ) ? arguments[1].continuousPlay: true,
		xmlFile       : ( typeof(arguments[1].xmlFile)        != 'undefined' ) ? arguments[1].xmlFile       : false,
		videoFile     : ( typeof(arguments[1].videoFile)      != 'undefined' ) ? arguments[1].videoFile     : false,
		flashFile	  : ( typeof(arguments[1].flashFile)      != 'undefined' ) ? arguments[1].flashFile     : '/static/swf/video.swf',
		playAdvert    : ( typeof(arguments[1].playAdvert)     != 'undefined' ) ? arguments[1].playAdvert    : false,
		clickableAd   : ( typeof(arguments[1].clickableAd)    != 'undefined' ) ? arguments[1].clickableAd   : false,
		controlsDisabled : ( typeof(arguments[1].controlsDisabled) != 'undefined' ) ? arguments[1].controlsDisabled : false,
		wmode         : ( typeof(arguments[1].wmode)          != 'undefined' ) ? arguments[1].wmode         : 'transparent',
        startFull     : ( typeof(arguments[1].startFull)      != 'undefined' ) ? arguments[1].startFull		: 'false',
        title		  : ( typeof(arguments[1].title)    	  != 'undefined' ) ? arguments[1].title			: '', 
        subtitle	  : ( typeof(arguments[1].subtitle)       != 'undefined' ) ? arguments[1].subtitle		: '',
        autoload	  : ( typeof(arguments[1].autoload)       != 'undefined' ) ? arguments[1].autoload		: 'false'
	};

	while( is_movie(options.id) ) { // make sure each movie has a unique name
		options.id = options.id + '_';
	}

	lb_movies[lb_movies.length] = options.id;

	var flash_version = swfobject.getFlashPlayerVersion();

	if ( ( // if the flash player can play anything
			(flash_version.major == 9 && (flash_version.minor > 9 || flash_version.release >= 115) ) ||
			( flash_version.major > 9 )
		 ) || (
		 	// or the video file is an flv
		 	flash_version.major >= 8 &&
		 	options.videoFile.substring(options.videoFile.length - 3) == 'flv'
		 )
		){
		// we can embed the flash movie
	    var flashvars = {
	    	myId			: options.id,
	        Volume          : options.volume,
	        hoverControls   : options.hoverControls,
	        initialPic      : options.initialPic,
	        finalPic        : options.finalPic,
	        autoplay        : options.autoplay,
	        continuousPlay  : options.continuousPlay,
	        playAdvert      : options.playAdvert,
	        clickableAd     : options.clickableAd,
	        controlsDisabled: options.controlsDisabled,
			startFull		: options.startFull,
			title			: options.title,
			subtitle		: options.subtitle,
			autoload		: options.autoload
	    };

		if( options.skin )
			flashvars['c_skin']     = options.skin;
		
		if( options.xmlFile )
			flashvars['xmlFile']    =	options.xmlFile;
		
		if( options.videoFile )
			flashvars['videoFile']  = options.videoFile;
	    
	    var params = {
	        quality         : 'autohigh',
	        wmode           : options.wmode,
	        allowfullscreen : true,
	        bgcolor         : '#000000',
	        allowScriptAccess   : 'sameDomain'
	    };
	    var attributes = {
	        id    : options.id,
	        name  : options.id
	    };

    	swfobject.embedSWF( options.flashFile, id, options.width, options.height, "8",null, flashvars, params, attributes);

	} else if( browserPlugin("QuickTime") && (
										options.videoFile.substring(options.videoFile.length - 3) == 'mov' ||
										options.videoFile.substring(options.videoFile.length - 3) == 'm4v' ||
										options.videoFile.substring(options.videoFile.length - 3) == 'mp4'
									   )
			 ) {

		// if it's a quicktime embedable file
		addEvent(window, 'load', function(){
			if( options.initialPic ) {
				document.getElementById(id).innerHTML = '<embed width="' + options.width + '" height="' + options.height + '" targetcache="true" controller="false" autostart="true" scale="aspect" bgcolor="transparent" \
    				src="' + options.videoFile + '" type="video/quicktime"/>';
    		} else {
				document.getElementById(id).innerHTML = '<embed width="' + options.width + '" height="' + options.height + '" targetcache="true" controller="false" autohref="false" scale="aspect" bgcolor="000000" \
    				src="' + options.initialPic + '" href="' + options.videoFile + '" type="video/quicktime" target="myself" />';
    		}
    		
		})
	}
	 /**/

}

function lbGetUrl(){
  return window.location.href;
}