// These functions are used for the Video Page.

var video_active = false;
$(function() {

	// Enable the user to select the video that they want.


	$('.video-link').click(function() {
		if(video_active == false) {

			video_active = true;
			var vid_id = $(this).attr('rel');
			
			var embed_code;
			var short_code;
			$('.video-agents').fadeOut('slow');
			$.getJSON('index.php/video_inspection/json_video/' + vid_id, function(json) {
				embed_code = json.embed;
				$('#player').attr('href',json.embed);
				flowplayer("player", "swf/flowplayer-3.2.7.swf");
				
				json.agent_photo = json.agent_photo.replace('http://imagetrack.com.au', '');
				console.log(json.agent_photo);
				console.log(json.agent_photo.length);
				if(json.agent_photo.length > 0) {
					var agent_photo = '<img src="' + json.agent_photo + '" />';
					$('#video-container').css({float: 'left', display: 'block', margin: '0'});
					$('#video-agents').html(agent_photo);
					$('#video-agents').append(json.agents);
					$('#video-agents').fadeIn('slow');
				}
				
				shortcode = json.shortcode;
				
				/*video_active = false;
var flashvars = {
				videopath: embed_code+"&sendtext=Send to a Friend&sendtitle=Send to a Friend&powered_by_logo=logo.jpg&emailpath=/tsr3/pv/sendemail.php&imagecastlink=http://tsr2.imagetrack.tv/tsr3/pv/view.php?sc="+shortcode,
				play: 'true',
				align: 'middle'
			}
			//alert(json.embed);
			
			var params = {
				displayheight: "288",
				enablejs: "true",
				javascriptid: "single",
				bufferlength: '5',
				smoothing: 'true',
				wmode: 'transparent',
				allowfullscreen: 'true',
				allowscriptaccess: 'always',
				url: ''
			}

			var attributes = {
				style: ';'
			}

			swfobject.embedSWF("http://lightboxfilms.com.au/website/mediaplayer/mediaplayer.swf", "video-object", "512", "308", "8.0.0","swf/expressInstall.swf", flashvars, params, attributes);
			*/
			if(json.agent_photo.length == 0) {
				$('#video-container').css({float: 'none', display:'block', margin: '0 auto', width: '512px'});
				$('#video-agents').hide();
			}
			});
		}
		//return false;
	});
	$('#' + first_vid + ' .video-link').click()

	// Ensure that you include any margins, padding etc...	
	var itemWidth = 150;

	// Thes are the items used for the scroller.
	// The div which spans the width of the page, and hides the extra images which overflow.
	var slDisplayBox = '#video-carousel';
	// The div which contains all the images, and moves along, giving the illusion of scrolling.
	var slItemContainer = '#video-scroller';
	// The actual slider.
	var slSlider = '#control';
	// The handle for the slider, which gives the user the ability to move the item container.
	var slHandle = '#handle';
	var slPrev = '#next';
	var slNext = '#prev';
	var productWidth = parseInt($(slItemContainer).width()) - parseInt($(slDisplayBox).width());
	
	// Tabs
	
	$('ul#video-tabs').tabs();

});

