/**
 * BT - On Vision - [onvision] Custom JS
 * @version 1.0
 * @author LBi - http://www.lbi.com/en
 * @requires jQuery Core 1.3+ - http://www.jquery.com/
 * @requires jQuery UI 1.7.1 - http://ui.jquery.com/
*/
/*jslint bitwise: true, eqeqeq: true, passfail: false, nomen: false, plusplus: false, undef: true, evil: true */
/*global window, document, $, jQuery, LBI, DI, self */

/**
* @namespace Root namespace for holding all objects created for LBI.
*/
var BTV = window.BTV || {};

/**
 * @namespace Accordion element behaviour.
 * @requires jQuery UI accordion plugin
 */
BTV.accordion = {

	currentTrigger			: '.current',
	selectedClass			: 'active',

	/**
	 * Setup an accordion on the passed in elements.
	 *
	 * @param {String} accordionSelector CSS style selector
	 * @param {String} triggerSelector CSS style selector
	 */
	build: function (accordionSelector, triggerSelector) {

		// Assign initial active class cos we need to
		$(accordionSelector + ' ' + BTV.accordion.currentTrigger).parent().parent().addClass(BTV.accordion.selectedClass);
		
		// Setup accordion
		$(accordionSelector).accordion({
			header: triggerSelector,
			active: BTV.accordion.currentTrigger, // Selected index class
			collapsible: false,
			autoHeight: false, // removes forced equal heights on accordion parts
			clearStyle: true, // Clear height property after transition. Prevents content overflow
			changestart: function (event, ui) {
				// Fires at start of transition
				if(ui.newHeader) {
					ui.newHeader.parent().parent().toggleClass(BTV.accordion.selectedClass);
				}
			},
			change: function (event, ui) {
				// Fires at end of transition
				if (ui.oldHeader) {
					ui.oldHeader.parent().parent().toggleClass(BTV.accordion.selectedClass);
				}
			}
		});
	},

	/**
	 * Initialise content accordion.
	 */
	init: function () {
		// Content accordion
		this.build('.itemList .accordion', 'h3.trigger');
	}
};

BTV.headerVideoPanelBehaviour = {
	
	panelOpen: true,
		
	init: function() {
		
		$('#headerVideoTabs').tabs();
		
		BTV.headerVideoPanelBehaviour.panelSetup();
	    
	},
	
	panelSetup : function() {
		
		var headerVideoPanelToggler = $('#headerVideoPanelToggler');
		var headerVideoPanel = $('#headerVideoPanel');
		var headerVideoText = $('#headerVideoText');
		var headerVideoPanelShadow = $('#headerVideoPanelShadow');
		var headerVideoPanelDynamicContent = $('#headerVideoPanelDynamicContent');
		var panelTogglerTextTrailersHighlights = '<span class="postit">TRAILERS &#38; HIGHLIGHTS</span>';
		var panelTogglerTextClose = '<span class="postit">CLOSE</span>';
		
		headerVideoPanelToggler.animate({ height: "213px", top: "47px" }, 2000);
		// animate the slide panel
		headerVideoPanel.animate({
			right: "-412px"
		}, 2000, function() {
			// hide slide panel shadow                        
			headerVideoPanelShadow.hide();
			headerVideoPanelToggler.innerHTML = panelTogglerTextTrailersHighlights;
			headerVideoPanelToggler.attr('class', 'panelOpen');
		});
		
		headerVideoText.animate({bottom: "0px" }, 2000);
		
		BTV.headerVideoPanelBehaviour.panelOpen = false;

		headerVideoPanelToggler.click(function() {
			switch(BTV.headerVideoPanelBehaviour.panelOpen){
				case true:
					// panel closed settings
					
					// animate the slide trigger                        
					$(this).animate({ height: "213px", top: "47px" }, 750);
					
					// animate the slide panel
					headerVideoPanel.animate({
						right: "-412px"
					}, 750, function() {
						// hide slide panel shadow                        
						headerVideoPanelShadow.hide();
						headerVideoPanelToggler.html(panelTogglerTextTrailersHighlights);
						headerVideoPanelToggler.attr('class', 'panelOpen');
					});
					
					headerVideoText.animate({bottom: "0px" }, 750);

					BTV.headerVideoPanelBehaviour.panelOpen = false;								
					break;
				
				case false:
					// panel open settings
					
					headerVideoText.animate({bottom: "-390px" }, 750);
					
					// show slide panel shadow                        
					headerVideoPanelShadow.show();
					
					// animate the slide trigger
					$(this).animate({ height: "70px", top: "120px" }, 750);
					headerVideoPanelToggler.html(panelTogglerTextClose);
					headerVideoPanelToggler.attr('class', 'panelClose');
				
					// animate the slide panel
					headerVideoPanel.animate({
						right: "-58px"
					}, 750, 'easeOutBack', function() {
						
					});						

					BTV.headerVideoPanelBehaviour.panelOpen = true;								
					break;
				
			}				
		});
		
		$('#headerVideoPanel .videoImageLink').click(function() {
			
			var requestUrl = LBI.common.ajax.tagUrl($(this).attr('href'));
			
			$.ajax({
				dataType: "html",
				url: requestUrl,
				error: function(data) {
					alert('error.');
				},
				success: function(data) {
					
					headerVideoPanelToggler.animate({ height: "213px", top: "47px" }, 750);
					headerVideoPanel.animate({
						right: "-412px"
					}, 750, function() {
						// hide slide panel shadow                        
						headerVideoPanelShadow.hide();
						headerVideoPanelToggler.attr('class', 'panelOpen');
						
						headerVideoText.animate({bottom: "0px" }, 750);

						BTV.headerVideoPanelBehaviour.panelOpen = false;

						document.getElementById('headerVideoDynamicContent').innerHTML = data;

						headerVideoText = $('#headerVideoText');
						headerVideoText.animate({bottom: "0px" }, 750);

						LBI.common.onPageFlash();

						// trigger page update
						LBI.common.ajax.pageUpdated();
						
					});	

				}
			});
			
			return false;
	
		});	
	
	}

};

/**
 * @namespace help video behaviour.
 * @requires jQuery UI accordion plugin
 */
BTV.helpVideo = {
	helpVideoSelector : '.helpVideo',
	videoWapperSelector : '.helpVideoWrapper',
	videoLinkSelector : '.videoLink',
	errorMessage : '<p class="error">Sorry this video is not available now, please try later.</p>',
		
	init : function(){
		//set up video nav tabs
		$('#helpVideoTabs').tabs();
		var videoTriggers = $(this.helpVideoSelector + ' ' + this.videoLinkSelector);
		//load video from first trigger by default
		BTV.helpVideo.loadVideo($(videoTriggers)[0]);
		
		videoTriggers.click(function(){
			var trigger = this;
			var dataURL = LBI.common.ajax.tagUrl($(trigger).attr('href'));
			BTV.helpVideo.loadVideo(dataURL);
			return false;
		});
	},
	loadVideo : function(dataURL, focusEl){
		//load video content
		var videoWapper = $(BTV.helpVideo.videoWapperSelector);
		$.ajax({
			url : dataURL,						
			success : function (response) {		
				videoWapper.html(response);
				// trigger on page flash
				LBI.common.onPageFlash();
				// trigger page updated
				if (focusEl) {
					LBI.common.ajax.pageUpdated(focusEl);
				}
				else {
					LBI.common.ajax.pageUpdated();
				}
			},
			error : function () {
				videoWapper.html(BTV.helpVideo.errorMessage);				
				// trigger page updated
				LBI.common.ajax.pageUpdated();
			}
		});		
	}
};
/**
 * @namespace sortable table behaviour.
 * @requires jQuery tablesorter plugin
 */

BTV.tableSorter = {
	init : function(obj, options) {
	var defaults = {dateFormat: 'uk'};
	var settings = $.extend({}, defaults, options);
	    obj.tablesorter(settings);
	},
	
	//extend to support soring of new date format eg. "18 May, 2005" or "18 May 2008"
	newDateFormat : function(){
		var monthNames = {};
		monthNames["Jan"] = "01";
		monthNames["Feb"] = "02";
		monthNames["Mar"] = "03";
		monthNames["Apr"] = "04";
		monthNames["May"] = "05";
		monthNames["Jun"] = "06";
		monthNames["Jul"] = "07";
		monthNames["Aug"] = "08";
		monthNames["Sep"] = "09";
		monthNames["Oct"] = "10";
		monthNames["Nov"] = "11";
		monthNames["Dec"] = "12";
		
		$.tablesorter.addParser({
			id: 'newDate',
			is: function(s) {
			  return false;
			},
			format: function(s) {
			  var hit = s.match(/(\d{1,2})\s([A-Za-z]{3}),?\s(\d{4})/);
			  var d = "0" + hit[1];
			  d = d.substr(d.length - 2);
			  var m = hit[2];
			  m = monthNames[m];
			  var y = hit[3];
			  return "" + y + m + d;
			},
			type: 'numeric'
		});
	}
};
/**
 * @namespace browse On Demand behaviour.
 */
BTV.browseOnDemand = {
	contentSelector: '.onDemandContent',
	mainSelector : '.onDemandMain',
	detailsClass : 'onDemandDetails',
	sorterName: 'Header',
	expandedClass : 'expanded',
	currentClass : 'current',
	sortUpClass : 'sortUp',
	sortDownClass : 'sortDown',
	loader : '<div class="loader"></div>',
	errorMessage : '<p class="error">Sorry this programme information is not available now, please try later.</p>',
	
	init : function(){
		//trigger table sorting function
		var options = {widgets: ['zebra'], headers: {3: {sorter: 'newDate'}}};
		BTV.tableSorter.init($(BTV.browseOnDemand.mainSelector + ' table'), options);
		
		//build sorting header for on demand main content
		this.buildHeader($(BTV.browseOnDemand.mainSelector));
		
		//prepare markup for loading programme details
		$(this.contentSelector).append('<div class="' + this.detailsClass + '"</div>');
		
		//bind functions to onDemandMain programmme link
		var currentPosition = 0;
		$(this.contentSelector + ' tbody th a').click(function(){
			var trigger = this;
			var dataURL = LBI.common.ajax.tagUrl($(trigger).attr('href'));
			
			//if programme already expanded return to programme list, otherwise load details of this programmme
			if($(BTV.browseOnDemand.contentSelector).hasClass(BTV.browseOnDemand.expandedClass)){
				BTV.browseOnDemand.closeExpanded(trigger);
				$(BTV.browseOnDemand.mainSelector).scrollTop(currentPosition);
			}else{
				currentPosition = $(BTV.browseOnDemand.mainSelector).scrollTop();
				BTV.browseOnDemand.loadContent(dataURL, trigger);				
			}		
			return false;	
	        });
	},
	
	buildHeader : function(context){
			//build sorting header from sortable table thead elements
			var header = $(context).find('thead th');
			var nav = $(document.createElement("ul"));
			var navName = $(context).attr("class") + BTV.browseOnDemand.sorterName;			
			
			if($('.'+ navName).length !== 0){
				nav = $(context).siblings('.'+ navName);
			}else{	
				nav.addClass(navName);
				for(var i=0, j = header.length; i < j; i ++){
					var list = document.createElement("li");
					list.innerHTML = $(header[i]).text();
					list.className = BTV.browseOnDemand.sorterName + i;
					nav.append(list);				
				}			
				context.parent().prepend(nav);
			}
			
			//bind sorting function to new headers
			nav.find('li').each(function(index){
				if($(header[index]).hasClass('header')){
					$(this).click(function(){			
				
					$(this).siblings().removeClass(BTV.browseOnDemand.sortUpClass + ' ' + BTV.browseOnDemand.sortDownClass);
					
					if($(this).hasClass(BTV.browseOnDemand.sortUpClass)){
						$(this).removeClass(BTV.browseOnDemand.sortUpClass);
						$(this).addClass(BTV.browseOnDemand.sortDownClass);
					}else{
						$(this).removeClass(BTV.browseOnDemand.sortDownClass);
						$(this).addClass(BTV.browseOnDemand.sortUpClass);
					}
					//trigger sorting
					$(header[index]).click();
					return false;
					});
				}else{
					$(this).addClass('disabled');
				}
		});	
	},
	
	closeExpanded : function(trigger){
		$(BTV.browseOnDemand.contentSelector).toggleClass(BTV.browseOnDemand.expandedClass);
		$(trigger).parent().parent().toggleClass(BTV.browseOnDemand.currentClass);		
	},
	
	loadContent : function(dataURL, trigger, focusEl){
		//make ajax call to load details of a requested programme
		var detailsCont = $('.' + BTV.browseOnDemand.detailsClass);
		$.ajax({
			url : dataURL,
			beforeSend: function(){
				BTV.browseOnDemand.closeExpanded(trigger);
				detailsCont.html(BTV.browseOnDemand.loader);
			},						
			success : function (response) {		
				detailsCont.html(response);
				
				// trigger table sorter
				$(detailsCont).find('table').tablesorter({ headers: {3: {sorter: 'newDate'}}});
				BTV.browseOnDemand.buildHeader(detailsCont);
				
				// trigger page updated
				if (focusEl) {
					LBI.common.ajax.pageUpdated(focusEl);
				}
				else {
					LBI.common.ajax.pageUpdated();
				}
			},
			error : function () {
				detailsCont.html(BTV.browseOnDemand.errorMessage);				
				// trigger page updated
				LBI.common.ajax.pageUpdated();
			}
		});		
	}
};

/**
 * @namespace Tooltip Bindings
 */
BTV.tooltips = {
	containerSelector : '.tipContainer',
	primarySelector : '.primary',
	tipSelector : '.tip',
	
	init : function(){
    var arrowShift = 30;
		$(BTV.tooltips.containerSelector).hover(function(e) {
                  
      var x = e.pageX - $(BTV.tooltips.primarySelector).offset().left - arrowShift;
      var y = e.pageY - $(BTV.tooltips.primarySelector).offset().top;
            
      $(BTV.tooltips.tipSelector, this).css("left", x);
      $(BTV.tooltips.tipSelector, this).css("top", y);
		  		        
		},function(){
      $(BTV.tooltips.tipSelector, this).css("left", "-10000px");
		});
		
	}
};

/**
 * @namespace Product Ajax rating
 */
BTV.productRating = {
  ratingPanel : '.ratingPanel',    
  ratingPrompt : '.ratingPrompt',      
	ratingInstructions : '.ratingInstructions',  	  
	ratingTrigger : '.ratingTrigger',  
	ratingConfirm : '.ratingConfirm',  	
	starContainer : '.starContainer',  
	stars : '.stars',
	star : '.stars li a',
	loader : '.ratingLoader',
	voteURL : '/wp-content/themes/bt_vision_v1_0/htmlTemplates/modules/m_11.01_product_star_rating.shtml',
	productSelector : '.productDetails',
	
	init : function(){	  
	  var productID = $(BTV.productRating.productSelector).attr('id');

    //  Check if already rated product
    var hasRatedCookieValue = BTV.cookies.getCookie('rated_'+productID);
    var hasRated = (hasRatedCookieValue != null && hasRatedCookieValue == 'true') ? true : false;   
    if (hasRated) { 
      $(BTV.productRating.ratingTrigger).hide();    
      $(BTV.productRating.ratingConfirm).show();
    }
  	  
    // Activate Rating
		$(BTV.productRating.ratingTrigger).mouseenter(function() {
        $(BTV.productRating.stars).addClass("active");
        $(BTV.productRating.ratingTrigger).hide();         
        $(BTV.productRating.ratingInstructions).show();                
		});	  
	  
    // De-activate Rating
	  $(BTV.productRating.ratingPanel).mouseleave(function() {	  	    
        $(BTV.productRating.stars).removeClass("active");		
		    if (!$(BTV.productRating.stars).hasClass("complete") && (!hasRated)) {
          $(BTV.productRating.ratingTrigger).show();         
          $(BTV.productRating.ratingInstructions).hide();
        }
		});	  
		
    // Rate product via Ajax call
		$(BTV.productRating.star).click(function() {
		  
		  if ($(BTV.productRating.stars).hasClass("active")) {  		
		    		  
        // Hide trigger and show spinner
        $(BTV.productRating.ratingPrompt).html('Sending rating');
  		  $(BTV.productRating.starContainer).html($(BTV.productRating.loader));
		 
        // Send rating
  		  var rating = $(this).attr('class');
        $(BTV.productRating.ratingPanel).load(BTV.productRating.voteURL, {productID : productID, rating: rating}, function(response, status, xhr) {
            if(status == 'error') {
                $(BTV.productRating.ratingPrompt).html("Sorry, could not complete rating");                       
                $(BTV.productRating.loader).hide();
            } 
            $(BTV.productRating.stars).addClass("complete");  
            $(BTV.productRating.ratingTrigger).hide();         
            $(BTV.productRating.ratingInstructions).hide();         
            $(BTV.productRating.ratingConfirm).show();
            BTV.cookies.setCookie('rated_'+productID, true, 365);
        });
        
      }
		  return false;		
		});
		
	}
};

/**
 * @namespace Cookie Utilites
 */
BTV.cookies = {    
	
	setCookie : function(c_name,value,expiredays) {
    var exdate=new Date();
    exdate.setDate(exdate.getDate()+expiredays);
    document.cookie=c_name+ "=" +escape(value)+
    ((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
  },
  
  getCookie : function(c_name) {
    if (document.cookie.length > 0) {
      c_start = document.cookie.indexOf(c_name + "=");
      if (c_start != -1) {
        c_start = c_start + c_name.length+1;
        c_end = document.cookie.indexOf(";",c_start);
        if (c_end == -1) c_end = document.cookie.length;
        return unescape(document.cookie.substring(c_start,c_end));
      }
    }
    return "";
  }
};

/**
 * @namespace Freeview elements behaviour
 */
BTV.freeView = {
	
	genreFilter: '',
	date: '',
	timeStart: 0,
	timeEnd: 0,
	bbcRegion: '',
	itvRegion: '',
	channelListingsPosition: 1,
	channelListingsLimit: 8,
	channelScrollTime: 100,
	dateNavDaysPosition: 1,
	dateNavDaysLimit: 12,
	dayScrollTime: 100,
	
	init : function(){
		
		$('.programmeWrapper').bind("mouseenter",function(){
			$(this).closest('.channel').addClass('channelSelected');
			$(this).addClass('programmeWrapperSelected');
		}).bind("mouseleave",function(){
			$(this).closest('.channel').removeClass('channelSelected');
			$(this).removeClass('programmeWrapperSelected');
		});
		
		//define genre filter links
		var genreLinks = $('.genreNav a');
		// setup behaviour for genre filter links
		genreLinks.bind("click",function(){
			genreLinks.each(function () {
				$(this).removeClass('genreNavSelected');
			});
			$(this).addClass('genreNavSelected');
			BTV.freeView.genreFilter = $(this).text();
			console.log('genre: ' + BTV.freeView.genreFilter);
			
			BTV.freeView.ajax('genreNav');
			
			return false;
		});
		
		var dateNavDaysList = $('#dateNavDaysList');
		var dateNavDays = $('#dateNavDaysList a');
		var dateNavDaysLength = dateNavDays.length;
		var previousDates = $('#previousDates a:first');
		var nextDates = $('#nextDates a:first');
		
		dateNavDays.bind("click",function(){
			dateNavDays.each(function () {
				$(this).removeClass('dateSelected');
			});
			$(this).addClass('dateSelected');
			BTV.freeView.date = $(this).attr('href').split('date=')[1];
			console.log('date: ' + BTV.freeView.date);
			
			BTV.freeView.ajax('dateNav');
			
			return false;
		});		
		
		nextDates.bind("click",function(){
			if( (dateNavDaysLength - BTV.freeView.dateNavDaysPosition) > BTV.freeView.dateNavDaysLimit){
				 // define possible scroll
				var possibleScroll = (dateNavDaysLength - BTV.freeView.dateNavDaysPosition - BTV.freeView.dateNavDaysLimit);
				if(possibleScroll > BTV.freeView.dateNavDaysLimit){
					possibleScroll = BTV.freeView.dateNavDaysLimit;
				}
				BTV.freeView.dateNavDaysPosition = BTV.freeView.dateNavDaysPosition + possibleScroll;
				// animate channel listings content
				dateNavDaysList.animate({
					left: "-=" + (possibleScroll * 45),
					easing: "easin"
				}, BTV.freeView.dayScrollTime*possibleScroll);
				
			}
			return false;
		}).bind("mouseenter",function(){
			console.log('mouseenter');
		}).bind("mouseleave",function(){
			console.log('mouseleave');
		});
		
		previousDates.bind("click",function(){
			if(BTV.freeView.dateNavDaysPosition > 1){
				 // define possible scroll
				var possibleScroll = BTV.freeView.dateNavDaysPosition - 1;
				if(possibleScroll > BTV.freeView.dateNavDaysLimit){
					possibleScroll = BTV.freeView.dateNavDaysLimit;
				}
				// increment channel listings position
				BTV.freeView.dateNavDaysPosition = BTV.freeView.dateNavDaysPosition - possibleScroll;
				// animate channel listings content
				dateNavDaysList.animate({
					left: "+=" + (possibleScroll * 45),
					easing: "easin"
				}, BTV.freeView.dayScrollTime*possibleScroll);
			}
			return false;
		}).bind("mouseenter",function(){
			console.log('mouseenter');
		}).bind("mouseleave",function(){
			console.log('mouseleave');
		});
		
		var channelListingsContent = $('#channelListingsContent');
		var channelListingsLength = $('.channel').length;
		var scrollUpChannels = $('#scrollUpChannels');
		var scrollDownChannels = $('#scrollDownChannels');
		
		scrollUpChannels.bind("click",function(){
			if(BTV.freeView.channelListingsPosition > 1){
				 // define possible scroll
				var possibleScroll = BTV.freeView.channelListingsPosition - 1;
				if(possibleScroll > BTV.freeView.channelListingsLimit){
					possibleScroll = BTV.freeView.channelListingsLimit;
				}
				// increment channel listings position
				BTV.freeView.channelListingsPosition = BTV.freeView.channelListingsPosition - possibleScroll;
				// animate channel listings content
				$('#channelListingsContent').animate({
					top: "+=" + (possibleScroll * 60),
					easing: "easin"
				}, BTV.freeView.channelScrollTime*possibleScroll);
			}
			return false;
		}).bind("mouseenter",function(){
			console.log('mouseenter');
		}).bind("mouseleave",function(){
			console.log('mouseleave');
		});
		
		scrollDownChannels.bind("click",function(){
			if( (channelListingsLength - BTV.freeView.channelListingsPosition) > BTV.freeView.channelListingsLimit){
				 // define possible scroll
				var possibleScroll = (channelListingsLength - BTV.freeView.channelListingsPosition - BTV.freeView.channelListingsLimit);
				if(possibleScroll > BTV.freeView.channelListingsLimit){
					possibleScroll = BTV.freeView.channelListingsLimit;
				}
				// increment channel listings position
				BTV.freeView.channelListingsPosition = BTV.freeView.channelListingsPosition + possibleScroll;
				// animate channel listings content
				$('#channelListingsContent').animate({
					top: "-=" + (possibleScroll * 60),
					easing: "easin"
				}, BTV.freeView.channelScrollTime*possibleScroll);
				
			}
			return false;
		}).bind("mouseenter",function(){
			console.log('mouseenter');
		}).bind("mouseleave",function(){
			console.log('mouseleave');
		});
		
	},
	
	ajax : function(request_type) {
		
			switch (request_type)
			{
			case 'dateNav':
			  console.log('ajax request: dateNav');
			  break;
			case 'genreNav':
			  console.log('ajax request: genreNav');
			  break;
			default:
			  console.log('ajax request: default');
			}
		
			//$.ajax({
				//dataType: "html",
				//url: requestUrl,
				//error: function(data) {
					//alert('error.');
				//},
				//success: function(data) {
					
				//}
			//});
  
	}

};

/**
 * @namespace lightbox
 */
BTV.lightbox = {
  /**
	 * Init
	*/
  init: function () {
    
    /**
     * Video
     */
    $('.lightboxVideo').click(function() {

        // Video Type + Size                 
        var flashType= LBI.common.getPEClassInfo(this,"F_");                        
        var height = LBI.data.flashType[flashType].height + "px";
				var width = LBI.data.flashType[flashType].width + "px";
                                  
				// open a colorbox
				if (BTV.functions.isIE && !BTV.functions.isIE6) {
					// IE7 and 8 seem to need an explicit opacity of 0.5 to avoid having a very dark overlay(?)
					$.fn.colorbox({html:'<div id="flashVideo"></div>', innerWidth:width, innerHeight:height, open:true, transition:"none", scrolling:false, opacity: 0.5, close:"Close"});
				} else {
					$.fn.colorbox({html:'<div id="flashVideo"></div>', innerWidth:width, innerHeight:height, open:true, transition:"none", scrolling:false, close:"Close"});						
				}        

        var videoId= LBI.common.getPEClassInfo(this,"V_");            
				var videoLink = this.href;				
				var flashvars = {};
				flashvars.videoSource= videoLink;
				flashvars.width = parseInt(width,0);
				flashvars.height = parseInt(height,0);
				flashvars.autoplay = true;
				flashvars.muted = false;
				flashvars.showInteractive = false;				
				swfobject.embedSWF(LBI.data.flashPlayer01, videoId, width, height, "9.0.0", "expressInstall.swf",flashvars, LBI.data.pageVideoOptions.params);
				return false; 
		});

    /**
     * Others
     */				
		$('.lightbox').colorbox();		
		
    // Close button
		$('#cboxTopRight').html('<div id="cboxCloseCircle"></div>');
    $('#cboxCloseCircle').click(function() {
      $('#cboxClose').click();
    });

	}
		 
};




/**
 * @namespace Specific functions calls from an inline end of document script block.
 */
BTV.functions = {
  isIE : false,
	ieIE6 : false,
	/**
	 * Functions that need to be called before DOM ready etc, perhaps down to .NET implementation.
	 * <p>
	 * Insert inline call to LBI.functions.init() at end of document.
	*/
	init: function () {

  		//check for IE
  		this.isIE = !$.support.opacity;
  		this.isIE6 = this.isIE && !window.XMLHttpRequest;
	}
};

/*
 * SETUP DOM READY AND LOAD EVENTS HERE
*/
$(document).ready(function () {
	LBI.common.identJS();
	LBI.common.getNewWindowLinks();
	LBI.common.dynamicInputText();
	BTV.tableSorter.newDateFormat();
	BTV.accordion.init();
	BTV.headerVideoPanelBehaviour.init();
	LBI.common.onPageFlash();
	BTV.browseOnDemand.init();
	BTV.tooltips.init();
	BTV.productRating.init();
	BTV.freeView.init();
	BTV.helpVideo.init();
	BTV.lightbox.init();	
	BTV.functions.init();
});
$(window).load(function () {
	
});