// Called from flash video player, updates the video information
function getVideoInfo(id, title, rating, views) {
	//console.log('getVideoInfo: ' + title + ', ' + id + ', ' + rating + ', ' + views);
	
	$("#videoTitle").html(title);
	$('#videoViews').html(views);	
}

// Called from flash video player, updates ad positions with the associated ad
function getVideoAd(id, path, url, position) {
	//console.log('getVideoAd: ' + id + ', ' + path + ', ' + url + ', ' + position);
	
	el = (position == 'MAIN') ? '#sponsor' : '#banner';
	sponsor_image_view = (position == 'MAIN') ? 'sponsor_image_view' : 'bottom_ad_view';
	
	if ($(el).length > 0) {
		$.get('/player/actions.cfm?advideo_id=' + id + '&' + sponsor_image_view + '=yes&cb' + Math.random());
	}
	
	if (path.search('.jpg') > 0 || path.search('.gif') > 0 || path.search('.png') > 0) {	
		$(el).html('<a href="#"><img src="' + path + '" alt="" onclick="adClick(\'' + id + '\', \'' + url + '\', \'' + position + '\');" /></a>');
	} else if (path.search('.swf') > 0) {
		if (position == 'MAIN') {		
			$(el).html('<div class="swf"><object width="300" height="250"><param name="wmode" value="transparent"></param><param name="movie" value="' + path + '"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><param value="path=' + url + '" name="flashvars"><embed onclick="adClick(\'' + id + '\', \'' + url + '\', \'' + position + '\');" src="' + path + '" type="application/x-shockwave-flash" wmode="transparent" allowscriptaccess="always" allowfullscreen="true" width="300" height="250" flashvars="path=' + url + '"></embed></object><span onclick="adClick(\'' + id + '\', \'' + url + '\', \'' + position + '\');"><img src="/secure/images/layout/trans.gif" width="300" height="250" alt=""/></span></div>');
		} else {
			$(el).html('<div class="swf"><object width="728" height="90"><param name="wmode" value="transparent"></param><param name="movie" value="' + path + '"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><param value="path=' + url + '" name="flashvars"><embed onclick="adClick(\'' + id + '\', \'' + url + '\', \'' + position + '\');" src="' + path + '" type="application/x-shockwave-flash" wmode="transparent" allowscriptaccess="always" allowfullscreen="true" width="728" height="90" flashvars="path=' + url + '"></embed></object><span onclick="adClick(\'' + id + '\', \'' + url + '\', \'' + position + '\');"><img src="/secure/images/layout/trans.gif" width="728" height="90" alt=""/></span></div>');
		}
	} else {
		$(el).html('');
	}
}

// Counts ad clicks from the ads
function adClick(id, path, position) {
	//console.log('adClick: ' + id + ', ' + path + ', ' + position);
	
	clickType = (position == 'MAIN') ? 'sponsor_image_click' : 'bottom_ad_click';	
	clickpath = '/player/actions.cfm?' + clickType + '=yes&advideo_id=' + id + '&path=' + path;
	
	window.open(clickpath);
	return false;
}

function addToFavorites(id) {
	//console.log('addToFavorites: ' + id);
	
	window.document.player.addToFavorites(id);
}

function playVideo(id) {
	//console.log('addToFavorites: ' + id);
	
	window.document.player.playVideo(id);
}

function popupVideo(id, panel) {
	showFavorites = (panel == 'showFavorites') ? '&showFavorites=true' : '';
	w = 980;
	h = 596;
	url = "/player/player.cfm?video_id=" + id + "&autoPlay=true" + showFavorites;
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	childWindow = open(url, "","toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width="+w+",height="+h+",left ="+LeftPosition+",top="+TopPosition+"");
	if (childWindow.opener == null) childWindow.opener = self;	
}

var d = new Date();
var start = d.getTime();