$.ajaxSetup({ cache: false });

$(document).ready(function() {	
	var programme_array = new Array(398, 399, 400);
	randomGen(programme_array);
	var random_programme_id = programme_array[0];	
	renderInterface('content-left', random_programme_id);
	$('.tab-internet-video, #iv-container').hover(
		function() { 
			$('#iv-container').css('display', 'block');
		},
		function() { 
			$('#iv-container').css('display', 'none'); 
		}
	);
});

function renderInterface(d, pid){
	var html = '<!-- Interface --><div id="interface"><div id="openchannel-container"><div id="openchannelcore"> </div><div id="openchannel-slides"></div><div id="openchannel-tv"><div id="iv"></div></div></div></div><!--// interface -->';
	$('.'+d).html(html);
	loadInterface(pid);
}

$(window).load(function() {						   
	animateContent.run(); // Activate the content
	menu(); // Activate the navigation
	animateVideoServices(); // Animate video services
});

function loadInterface(id){
	var parameters = {};		
			parameters.width = 340;
			parameters.height = 191;
			parameters.show_controls = 1;
			parameters.programme_id = id;
			parameters.user_id = 9999;
			parameters.tracker_source = "Stuff Website";
			parameters.tracker_uri = "http://admin.multichanneltv.com/receiveTrackerNew.php";
			parameters.timer_colour = "0x99FF00"
			parameters.seek_bar_colour = "0xF35901"
			buildOpenChannel(parameters);
}

function gotoChapter(t){
	return openChannelOne.callCoreMethod('seekToSeconds',t);
}

function animateVideoServices(){
	$('#video-services').animate({left: '40px'},"slow");
};

$.fn.pause = function(duration) {
	$(this).animate({ dummy: 1 }, duration);
	return this;
};

function loadContent(id){
	switch (id){
		case "link-video-based-websites":
			$('#dynamic-content').html(renderLoading());
			$('#dynamic-content').load('content/video-based-websites');
			break;
		case "link-web-walkthroughs":
			$('#dynamic-content').html(renderLoading());
			$('#dynamic-content').load('content/web-walkthroughs');
			break;
		case "link-video-presentations":
			$('#dynamic-content').html(renderLoading());
			$('#dynamic-content').load('content/video-presentations');
			break;
		case "link-virtual-tours":
			$('#dynamic-content').html(renderLoading());
			$('#dynamic-content').load('content/virtual-tours');
			break;		
	}	
}

function randomGen(a){
	var i = a.length;
	if(i == 0) return false;
	while(--i){
		 var j = Math.floor(Math.random() * (i + 1));
		 var tempi = a[i];
		 var tempj = a[j];
		 a[i] = tempj;
		 a[j] = tempi;
	 }
}
