var iframe_player_key = '#@7b1365efd928a56bd71'

var url_vars = getUrlVars();
var source_host = escape(url_vars[2])

root_domain = "https://partners.dovie.tv/"

function addClickHandlers() {



}
  
$(document).ready(addClickHandlers);

var session_id = 0

function launchVideo(video_id) {
  
  if (session_id == 0) {
  
    session_id = Math.floor(Math.random()*99999999999999)
    tracking_location = 'https://partners.dovie.tv/ajax/analytics_tracking.php?event=6&video_id='+video_id+'&dovie_session='+session_id+'&source_host='+source_host+'&callback=?'
    $.getJSON(tracking_location)
    
  }
  
	opts.transition_interval=0
	$(document).everyTime(opts.transition_interval,"transition",function(){
		showNextItem();
	});
	
	var target_panel = '#video_panel_'+video_id
		  
  var save_html = $(target_panel).html()
    
  $('#video_panel_holder').html(save_html);
  
  $(target_panel).html('<div id="player" style="width: 739px; height: 419px;"></div>');
  $(target_panel).addClass('video_panel');
  
  var playlist_location = escape('https://partners.dovie.tv/rss/?video='+video_id+'&internal=1')
    
    flowplayer("player", "https://partners.dovie.tv/flowplayer.unlimited-3.2.2.swf",
     {
       logo: { 

           // default logo and its position 
           url: 'https://partners.dovie.tv/images/supportingimages/bug.png', 
           top: 20, 
           left: 20, 
           opacity: 0.4, 
           fullscreenOnly: false, 
           // time to display logo (in seconds). 0 = show forever 
           displayTime: 0, 

           /* 
               if displayTime > 0 then this specifies the time it will take for 
               the logo to fade out. this happens internally by changing the opacity 
               property from its initial value to full transparency. 
               value is given in milliseconds. 
           */ 
           fadeSpeed: 0, 

           // When the bug is clicked, user will be directed to this URL
           linkUrl: '' 
       },
       cachebusting: true,
       clip: {
         provider: 'rtmp',
         urlResolvers: 'bwcheck',
         autoPlay: true,
         onStart: function(clip) { 

            tracking_location = 'https://partners.dovie.tv/ajax/analytics_tracking.php?event=1&video_id='+video_id+'&dovie_session='+session_id+'&callback=?'
            $.getJSON(tracking_location)
          },
          onStop: function(clip) { 

            tracking_location = 'https://partners.dovie.tv/ajax/analytics_tracking.php?event=2&video_id='+video_id+'&dovie_session='+session_id+'&callback=?'
            $.getJSON(tracking_location)
          },
          onPause: function(clip) { 

            tracking_location = 'https://partners.dovie.tv/ajax/analytics_tracking.php?event=3&video_id='+video_id+'&dovie_session='+session_id+'&callback=?'
            $.getJSON(tracking_location)
          },
          onResume: function(clip) { 

            tracking_location = 'https://partners.dovie.tv/ajax/analytics_tracking.php?event=4&video_id='+video_id+'&dovie_session='+session_id+'&callback=?'
            $.getJSON(tracking_location)
          },
          onFinish: function(clip) { 

            tracking_location = 'https://partners.dovie.tv/ajax/analytics_tracking.php?event=5&video_id='+video_id+'&dovie_session='+session_id+'&callback=?'
            $.getJSON(tracking_location)
          }
       },
       playlist: playlist_location, 
       plugins: {
         rtmp: {
           url: 'https://partners.dovie.tv/dovieplayer.rtmp-3.1.3.swf',
           netConnectionUrl: 'rtmp://ec2-174-129-79-191.compute-1.amazonaws.com/vods3'
         },
         controls:  {

        		// location of the controlbar plugin
        		url: 'https://partners.dovie.tv/flowplayer.controls-3.2.1.swf',

        		// display properties such as size, location and opacity
           opacity: 0.35,

           borderRadius: '0px',
           backgroundColor: '#000000',
           bufferGradient: 'none',
           progressGradient: 'medium',
           durationColor: '#ffffff',
           volumeSliderColor: '#000000',
           buttonColor: '#5F747C',
           sliderGradient: 'none',
           sliderColor: '#000000',
           timeColor: '#ffffff',
           volumeSliderGradient: 'none',
           progressColor: '#112233',
           timeBgColor: '#555555',
           buttonOverColor: '#728B94',
           backgroundGradient: [0.6,0.3,0,0,0],
           bufferColor: '#445566',
           tooltipColor: '#5F747C',
           tooltipTextColor: '#ffffff',
           height: 24,
           opacity: 1.0,

        		// controlbar specific settings
        		all: false,
        		play: true,
        		scrubber: true,
        		volume: true,
        		mute: true,
        		fullscreen: true,
        		// tooltips (since 3.1)
        		tooltips: {
        			buttons: true,
        			fullscreen: 'Show Fullscreen'
        		}
        	},
         bwcheck: { 
          url: 'https://partners.dovie.tv/dovieplayer.bwcheck-3.1.3.swf', 
          serverType: 'wowza', 
          defaultBitrate: 768,
          // Use this connection for bandwidth detection 
          netConnectionUrl: 'rtmp://ec2-174-129-79-191.compute-1.amazonaws.com/bw', 

          // available bitrates for file names 
          bitrates: [512, 768, 1024, 2028],

          // use a customized urlPattern for file names 
          urlPattern: '{0}-{1}.{2}',
          // this method is called when the bandwidth check is done 
          onBwDone: function(url, chosenBitrate, bitrate) { 
            tracking_location = 'https://partners.dovie.tv/ajax/analytics_tracking.php?event=bitrate&bitrate='+bitrate+'&dovie_session='+session_id+'&callback=?'
            $.getJSON(tracking_location) 
          },
           onConnect: function(host) { 
               // var el = document.getElementById("rtmpInfo"); 
               // el.innerHTML = "Attempting to connect to: " +url; 
           }
         }
       },
       onLoad: function() { 
         
         // $f().playlist(".entries", {loop: true});
         //   
         //     addPlaylistHover(); 
           
       }
     }
    );  
    
  return false   
}
  
function getUrlVars() {

  var vars = [], hash;

  var hashes = window.location.href.split('/');

  for(var i = 0; i < hashes.length; i++) {

    hash = hashes[i].split('=');

    vars.push(hash[0]);

    vars[hash[0]] = hash[1];

  }

  return vars;

}

function currentYPosition() {
	if (self.pageYOffset)
		 return self.pageYOffset;
	if (document.documentElement && document.documentElement.scrollTop)
		return document.documentElement.scrollTop;
	if (document.body.scrollTop)
		 return document.body.scrollTop;
	return 0;
}
function elmYPosition(eID) {
	var elm  = document.getElementById(eID);
	var y    = elm.offsetTop;
	var node = elm;
	while (node.offsetParent && node.offsetParent != document.body) {
		node = node.offsetParent;
		y   += node.offsetTop;
	} return y;
}
function smoothScroll(eID) {
	var startY   = currentYPosition();
	var stopY    = elmYPosition(eID);
	var distance = stopY > startY ? stopY - startY : startY - stopY;
	if (distance < 100) {
		scrollTo(0, stopY); return;
	}
	var speed = Math.round(distance / 100);
	var step  = Math.round(distance / 25);
	var leapY = stopY > startY ? startY + step : startY - step;
	var timer = 0;
	if (stopY > startY) {
		for ( var i=startY; i<stopY; i+=step ) {
			setTimeout("window.scrollTo(0, "+leapY+")", timer * speed);
			leapY += step; if (leapY > stopY) leapY = stopY; timer++;
		} return;
	}
	for ( var i=startY; i>stopY; i-=step ) {
		setTimeout("window.scrollTo(0, "+leapY+")", timer * speed);
		leapY -= step; if (leapY < stopY) leapY = stopY; timer++;
	}
}

