//heading replacement call
	//Cufon.replace('h2:not(.text_box h2, .no-submit h2), h3:not(.text_box h3), .text_box h1, .vod_intro h1, .edit_genres label, .showsnav .genrelist li, .competition_details label.large');

//including mousewheel plugin
	/* Copyright (c) 2006 Brandon Aaron (brandon.aaron@gmail.com || http://brandonaaron.net) * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses. * Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers. * Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix. * $LastChangedDate: 2007-12-20 09:02:08 -0600 (Thu, 20 Dec 2007) $ * $Rev: 4265 $ * Version: 3.0 * Requires: $ 1.2.2+ */
	(function($){$.event.special.mousewheel={setup:function(){var handler=$.event.special.mousewheel.handler;if($.browser.mozilla)$(this).bind('mousemove.mousewheel',function(event){$.data(this,'mwcursorposdata',{pageX:event.pageX,pageY:event.pageY,clientX:event.clientX,clientY:event.clientY});});if(this.addEventListener)this.addEventListener(($.browser.mozilla?'DOMMouseScroll':'mousewheel'),handler,false);else
	this.onmousewheel=handler;},teardown:function(){var handler=$.event.special.mousewheel.handler;$(this).unbind('mousemove.mousewheel');if(this.removeEventListener)this.removeEventListener(($.browser.mozilla?'DOMMouseScroll':'mousewheel'),handler,false);else
	this.onmousewheel=function(){};$.removeData(this,'mwcursorposdata');},handler:function(event){var args=Array.prototype.slice.call(arguments,1);event=$.event.fix(event||window.event);$.extend(event,$.data(this,'mwcursorposdata')||{});var delta=0,returnValue=true;if(event.wheelDelta)delta=event.wheelDelta/120;if(event.detail)delta=-event.detail/3;if($.browser.opera)delta=-event.wheelDelta;event.data=event.data||{};event.type="mousewheel";args.unshift(delta);args.unshift(event);return $.event.handle.apply(this,args);}};$.fn.extend({mousewheel:function(fn){return fn?this.bind("mousewheel",fn):this.trigger("mousewheel");},unmousewheel:function(fn){return this.unbind("mousewheel",fn);}});})(jQuery);

//including jscrollpane
	(function($){$.jScrollPane={active:[]};$.fn.jScrollPane=function(settings)
	{settings=$.extend({},$.fn.jScrollPane.defaults,settings);var rf=function(){return false;};return this.each(function()
	{var $this=$(this);$this.css('overflow','hidden');var paneEle=this;if($(this).parent().is('.jScrollPaneContainer')){var currentScrollPosition=settings.maintainPosition?$this.position().top:0;var $c=$(this).parent();var paneWidth=$c.innerWidth();var paneHeight=$c.outerHeight();var trackHeight=paneHeight;$('>.jScrollPaneTrack, >.jScrollArrowUp, >.jScrollArrowDown',$c).remove();$this.css({'top':0});}else{var currentScrollPosition=0;this.originalPadding=$this.css('paddingTop')+' '+$this.css('paddingRight')+' '+$this.css('paddingBottom')+' '+$this.css('paddingLeft');this.originalSidePaddingTotal=(parseInt($this.css('paddingLeft'))||0)+(parseInt($this.css('paddingRight'))||0);var paneWidth=$this.innerWidth();var paneHeight=$this.innerHeight();var trackHeight=paneHeight;$this.wrap($('<div></div>').attr({'className':'jScrollPaneContainer'}).css({'height':paneHeight+'px','width':paneWidth+'px'}).attr('tabindex',settings.tabIndex));$(document).bind('emchange',function(e,cur,prev)
	{$this.jScrollPane(settings);});}
	if(settings.reinitialiseOnImageLoad){var $imagesToLoad=$.data(paneEle,'jScrollPaneImagesToLoad')||$('img',$this);var loadedImages=[];if($imagesToLoad.length){$imagesToLoad.each(function(i,val){$(this).bind('load readystatechange',function(){if($.inArray(i,loadedImages)==-1){loadedImages.push(val);$imagesToLoad=$.grep($imagesToLoad,function(n,i){return n!=val;});$.data(paneEle,'jScrollPaneImagesToLoad',$imagesToLoad);var s2=$.extend(settings,{reinitialiseOnImageLoad:false});$this.jScrollPane(s2);}}).each(function(i,val){if(this.complete||this.complete===undefined){this.src=this.src;}});});};}
	var p=this.originalSidePaddingTotal;var realPaneWidth=paneWidth-settings.scrollbarWidth-settings.scrollbarMargin-p;var cssToApply={'height':'auto','width':realPaneWidth+'px'}
	if(settings.scrollbarOnLeft){cssToApply.paddingLeft=settings.scrollbarMargin+settings.scrollbarWidth+'px';}else{cssToApply.paddingRight=settings.scrollbarMargin+'px';}
	$this.css(cssToApply);var contentHeight=$this.outerHeight();var percentInView=paneHeight/contentHeight;if(percentInView<.99){var $container=$this.parent();$container.append($('<div></div>').attr({'className':'jScrollPaneTrack'}).css({'width':settings.scrollbarWidth+'px'}).append($('<div></div>').attr({'className':'jScrollPaneDrag'}).css({'width':settings.scrollbarWidth+'px'}).append($('<div></div>').attr({'className':'jScrollPaneDragTop'}).css({'width':settings.scrollbarWidth+'px'}),$('<div></div>').attr({'className':'jScrollPaneDragBottom'}).css({'width':settings.scrollbarWidth+'px'}))));var $track=$('>.jScrollPaneTrack',$container);var $drag=$('>.jScrollPaneTrack .jScrollPaneDrag',$container);var currentArrowDirection;var currentArrowTimerArr=[];var currentArrowInc;var whileArrowButtonDown=function()
	{if(currentArrowInc>4||currentArrowInc%4==0){positionDrag(dragPosition+currentArrowDirection*mouseWheelMultiplier);}
	currentArrowInc++;};if(settings.enableKeyboardNavigation){$container.bind('keydown.jscrollpane',function(e)
	{switch(e.keyCode){case 38:currentArrowDirection=-1;currentArrowInc=0;whileArrowButtonDown();currentArrowTimerArr[currentArrowTimerArr.length]=setInterval(whileArrowButtonDown,100);return false;case 40:currentArrowDirection=1;currentArrowInc=0;whileArrowButtonDown();currentArrowTimerArr[currentArrowTimerArr.length]=setInterval(whileArrowButtonDown,100);return false;case 33:case 34:return false;default:}}).bind('keyup.jscrollpane',function(e)
	{if(e.keyCode==38||e.keyCode==40){for(var i=0;i<currentArrowTimerArr.length;i++){clearInterval(currentArrowTimerArr[i]);}
	return false;}});}
	if(settings.showArrows){var currentArrowButton;var currentArrowInterval;var onArrowMouseUp=function(event)
	{$('html').unbind('mouseup',onArrowMouseUp);currentArrowButton.removeClass('jScrollActiveArrowButton');clearInterval(currentArrowInterval);};var onArrowMouseDown=function(){$('html').bind('mouseup',onArrowMouseUp);currentArrowButton.addClass('jScrollActiveArrowButton');currentArrowInc=0;whileArrowButtonDown();currentArrowInterval=setInterval(whileArrowButtonDown,100);};$container.append($('<a></a>').attr({'href':'javascript:;','className':'jScrollArrowUp','tabindex':-1}).css({'width':settings.scrollbarWidth+'px'}).html('Scroll up').bind('mousedown',function()
	{currentArrowButton=$(this);currentArrowDirection=-1;onArrowMouseDown();this.blur();return false;}).bind('click',rf),$('<a></a>').attr({'href':'javascript:;','className':'jScrollArrowDown','tabindex':-1}).css({'width':settings.scrollbarWidth+'px'}).html('Scroll down').bind('mousedown',function()
	{currentArrowButton=$(this);currentArrowDirection=1;onArrowMouseDown();this.blur();return false;}).bind('click',rf));var $upArrow=$('>.jScrollArrowUp',$container);var $downArrow=$('>.jScrollArrowDown',$container);if(settings.arrowSize){trackHeight=paneHeight-settings.arrowSize-settings.arrowSize;$track.css({'height':trackHeight+'px',top:settings.arrowSize+'px'})}else{var topArrowHeight=$upArrow.height();settings.arrowSize=topArrowHeight;trackHeight=paneHeight-topArrowHeight-$downArrow.height();$track.css({'height':trackHeight+'px',top:topArrowHeight+'px'})}}
	var $pane=$(this).css({'position':'absolute','overflow':'visible'});var currentOffset;var maxY;var mouseWheelMultiplier;var dragPosition=0;var dragMiddle=percentInView*paneHeight/2;var getPos=function(event,c){var p=c=='X'?'Left':'Top';return event['page'+c]||(event['client'+c]+(document.documentElement['scroll'+p]||document.body['scroll'+p]))||0;};var ignoreNativeDrag=function(){return false;};var initDrag=function()
	{ceaseAnimation();currentOffset=$drag.offset(false);currentOffset.top-=dragPosition;maxY=trackHeight-$drag[0].offsetHeight;mouseWheelMultiplier=2*settings.wheelSpeed*maxY/contentHeight;};var onStartDrag=function(event)
	{initDrag();dragMiddle=getPos(event,'Y')-dragPosition-currentOffset.top;$('html').bind('mouseup',onStopDrag).bind('mousemove',updateScroll);if($.browser.msie){$('html').bind('dragstart',ignoreNativeDrag).bind('selectstart',ignoreNativeDrag);}
	return false;};var onStopDrag=function()
	{$('html').unbind('mouseup',onStopDrag).unbind('mousemove',updateScroll);dragMiddle=percentInView*paneHeight/2;if($.browser.msie){$('html').unbind('dragstart',ignoreNativeDrag).unbind('selectstart',ignoreNativeDrag);}};var positionDrag=function(destY)
	{destY=destY<0?0:(destY>maxY?maxY:destY);dragPosition=destY;$drag.css({'top':destY+'px'});var p=destY/maxY;$this.data('jScrollPanePosition',(paneHeight-contentHeight)*-p);$pane.css({'top':((paneHeight-contentHeight)*p)+'px'});$this.trigger('scroll');if(settings.showArrows){$upArrow[destY==0?'addClass':'removeClass']('disabled');$downArrow[destY==maxY?'addClass':'removeClass']('disabled');}};var updateScroll=function(e)
	{positionDrag(getPos(e,'Y')-currentOffset.top-dragMiddle);};var dragH=Math.max(Math.min(percentInView*(paneHeight-settings.arrowSize*2),settings.dragMaxHeight),settings.dragMinHeight);$drag.css({'height':dragH+'px'}).bind('mousedown',onStartDrag);var trackScrollInterval;var trackScrollInc;var trackScrollMousePos;var doTrackScroll=function()
	{if(trackScrollInc>8||trackScrollInc%4==0){positionDrag((dragPosition-((dragPosition-trackScrollMousePos)/2)));}
	trackScrollInc++;};var onStopTrackClick=function()
	{clearInterval(trackScrollInterval);$('html').unbind('mouseup',onStopTrackClick).unbind('mousemove',onTrackMouseMove);};var onTrackMouseMove=function(event)
	{trackScrollMousePos=getPos(event,'Y')-currentOffset.top-dragMiddle;};var onTrackClick=function(event)
	{initDrag();onTrackMouseMove(event);trackScrollInc=0;$('html').bind('mouseup',onStopTrackClick).bind('mousemove',onTrackMouseMove);trackScrollInterval=setInterval(doTrackScroll,100);doTrackScroll();return false;};$track.bind('mousedown',onTrackClick);$container.bind('mousewheel',function(event,delta){initDrag();ceaseAnimation();var d=dragPosition;positionDrag(dragPosition-delta*mouseWheelMultiplier);var dragOccured=d!=dragPosition;return!dragOccured;});var _animateToPosition;var _animateToInterval;function animateToPosition()
	{var diff=(_animateToPosition-dragPosition)/settings.animateStep;if(diff>1||diff<-1){positionDrag(dragPosition+diff);}else{positionDrag(_animateToPosition);ceaseAnimation();}}
	var ceaseAnimation=function()
	{if(_animateToInterval){clearInterval(_animateToInterval);delete _animateToPosition;}};var scrollTo=function(pos,preventAni)
	{if(typeof pos=="string"){$e=$(pos,$this);if(!$e.length)return;pos=$e.offset().top-$this.offset().top;}
	$container.scrollTop(0);ceaseAnimation();var maxScroll=contentHeight-paneHeight;pos=pos>maxScroll?maxScroll:pos;$this.data('jScrollPaneMaxScroll',maxScroll);var destDragPosition=pos/maxScroll*maxY;if(preventAni||!settings.animateTo){positionDrag(destDragPosition);}else{_animateToPosition=destDragPosition;_animateToInterval=setInterval(animateToPosition,settings.animateInterval);}};$this[0].scrollTo=scrollTo;$this[0].scrollBy=function(delta)
	{var currentPos=-parseInt($pane.css('top'))||0;scrollTo(currentPos+delta);};initDrag();scrollTo(-currentScrollPosition,true);$('*',this).bind('focus',function(event)
	{var $e=$(this);var eleTop=0;while($e[0]!=$this[0]){eleTop+=$e.position().top;$e=$e.offsetParent();}
	var viewportTop=-parseInt($pane.css('top'))||0;var maxVisibleEleTop=viewportTop+paneHeight;var eleInView=eleTop>viewportTop&&eleTop<maxVisibleEleTop;if(!eleInView){var destPos=eleTop-settings.scrollbarMargin;if(eleTop>viewportTop){destPos+=$(this).height()+15+settings.scrollbarMargin-paneHeight;}
	scrollTo(destPos);}})
	if(location.hash){setTimeout(function(){scrollTo(location.hash);},$.browser.safari?100:0);}
	$(document).bind('click',function(e)
	{$target=$(e.target);if($target.is('a')){var h=$target.attr('href');if(h&&h.substr(0,1)=='#'){setTimeout(function(){scrollTo(h,!settings.animateToInternalLinks);},$.browser.safari?100:0);}}});function onSelectScrollMouseDown(e)
	{$(document).bind('mousemove.jScrollPaneDragging',onTextSelectionScrollMouseMove);$(document).bind('mouseup.jScrollPaneDragging',onSelectScrollMouseUp);}
	var textDragDistanceAway;var textSelectionInterval;function onTextSelectionInterval()
	{direction=textDragDistanceAway<0?-1:1;$this[0].scrollBy(textDragDistanceAway/2);}
	function clearTextSelectionInterval()
	{if(textSelectionInterval){clearInterval(textSelectionInterval);textSelectionInterval=undefined;}}
	function onTextSelectionScrollMouseMove(e)
	{var offset=$this.parent().offset().top;var maxOffset=offset+paneHeight;var mouseOffset=getPos(e,'Y');textDragDistanceAway=mouseOffset<offset?mouseOffset-offset:(mouseOffset>maxOffset?mouseOffset-maxOffset:0);if(textDragDistanceAway==0){clearTextSelectionInterval();}else{if(!textSelectionInterval){textSelectionInterval=setInterval(onTextSelectionInterval,100);}}}
	function onSelectScrollMouseUp(e)
	{$(document).unbind('mousemove.jScrollPaneDragging').unbind('mouseup.jScrollPaneDragging');clearTextSelectionInterval();}
	$container.bind('mousedown.jScrollPane',onSelectScrollMouseDown);$.jScrollPane.active.push($this[0]);}else{$this.css({'height':paneHeight+'px','width':paneWidth-this.originalSidePaddingTotal+'px','padding':this.originalPadding});$this.parent().unbind('mousewheel').unbind('mousedown.jScrollPane').unbind('keydown.jscrollpane').unbind('keyup.jscrollpane');}})};$.fn.jScrollPaneRemove=function()
	{$(this).each(function()
	{$this=$(this);var $c=$this.parent();if($c.is('.jScrollPaneContainer')){$this.css({'top':'','height':'','width':'','padding':'','overflow':'','position':''});$c.after($this).remove();}});}
	$.fn.jScrollPane.defaults={scrollbarWidth:10,scrollbarMargin:5,wheelSpeed:18,showArrows:false,arrowSize:0,animateTo:false,dragMinHeight:1,dragMaxHeight:99999,animateInterval:100,animateStep:3,maintainPosition:true,scrollbarOnLeft:false,reinitialiseOnImageLoad:false,tabIndex:0,enableKeyboardNavigation:true,animateToInternalLinks:false};$(window).bind('unload',function(){var els=$.jScrollPane.active;for(var i=0;i<els.length;i++){els[i].scrollTo=els[i].scrollBy=null;}});})(jQuery);




// custom code

$(document).ready(function(){

	$('html').addClass('js-enabled');
	
	//add corners to all modules
	$('.module').css('border-top-color','#999999').append('<div class="corner_tl"></div><div class="corner_tr"></div><div class="corner_bl"></div><div class="corner_br"></div>');

	$('.module h2, .summary_list h1, .searchform h1, .search_results h1').append('<span class="grad"></span>');

	showsNav();
	linksNav();
	gallery();
	selectMenu();
	textBoxTabs();
	loginOverlay();
	initScrollers();
	footer();
	recommend();
	shelf();
	noSubmitOverlay();
	redeemForm();
	poll();
	faq();
	externalLinks();
	centerer();
	deleteLink();
	ieSelectFix();
	$(window).resize(function(){centerer();});


});

function externalLinks(){

	$("a[rel='external']").click(function() { window.open($(this).attr('href')); return false; });

}

function _enable_keyboard_navigation() {
	if( $('.overlay').length ) {
		$(document).keydown(function(objEvent) {
			_keyboard_action(objEvent);
		});
	}
}

function _disable_keyboard_navigation() {
	$(document).unbind();
}

function _keyboard_action(objEvent) {
	// To ie
	if ( objEvent == null ) {
		keycode = event.keyCode;
		escapeKey = 27;
	// To Mozilla
	} else {
		keycode = objEvent.keyCode;
		escapeKey = 27;
	}
	// Get the key in lower case form
	key = String.fromCharCode(keycode).toLowerCase();
	// Verify the keys to close the ligthBox
	if ( ( key == 'x' ) || ( keycode == escapeKey ) ) {
		$('a.close').trigger('click');
	}
}

function ieSelectFix() {

	if($.browser.msie) {
	
		$('select#question').css({'width':'auto','position':'absolute','left':'170px'}).parent('div').css({'position':'relative'});		
	
	}

}

function initScrollers(){

	$('.scroller').jScrollPane({scrollbarWidth:20,scrollbarMargin:0,showArrows:true,arrowSize:10,dragMinHeight:19,maintainPosition:false});
	$('.scroller2').jScrollPane({scrollbarWidth:14,scrollbarMargin:0,showArrows:false,dragMinHeight:19,maintainPosition:false});


}

function gallery() {

	$('.gallery a').click(function(){
	
		//first remove any existing overlays
		$('.overlay').remove();
	
		var imgurl = $(this).attr('href');
		imgurl = 'http://www.warnertv.com/'+imgurl;
		//console.log('imgurl:'+imgurl);
		//load in overlay component.
		
		$.get('/components/overlay_gallery.php', function(data){
			
			$('.main>.inner').append(data);
			_enable_keyboard_navigation();
			//next get requested image and hide loading image
			var img = new Image();
	
			$(img).load(function () {
	
				var imgWidth = img.width;
				var ovrMargin = parseInt(-1*(imgWidth + 2*(10+1+10) )/2);
				$('.overlay .img596').append(img);
				$('.overlay').animate({'marginLeft':ovrMargin + 'px'}, { queue:false, duration:500 });
				$('.overlay .img596').animate({'width':imgWidth + 'px'}, { queue:false, duration:500, complete:function(){
	
					$('.overlay .img596 img').css({opacity: 0, visibility: "visible"}).animate({opacity: 1});
				
				} });
				
				
			}).error(function () {
					alert('<p>There seems to have been a problem loading that image. Please try again later.</p>');
		    }).attr('src',imgurl);


			//add close button functionality
			$('.overlay a.close').click(function(){
				
				$('.overlay').remove();
				_disable_keyboard_navigation();
				return false;
			
			});
			
		});

		return false;

		});
	
}

function textBoxTabs(){
	
	$('.text_box .tabs a').click(function(){
	
		var linkurl = $(this).attr('href');
		var cnttype = $(this).attr('class');
		$('.text_box .tabs li').removeClass('selected');
		$(this).parents('li').addClass('selected');
		$('.text_box .jScrollPaneContainer, .text_box .scroller').remove();
		$('.text_box .tabs').after("<div class='scroller'><div class='module_inner episode_guide'><img src='images/content/content_loading.gif' alt='' /></div></div>");
		
		$.get(linkurl,function(data){
		
			setTimeout(function(){
				var newContent = $(data).find('.text_box .scroller').html();
				
				
				if($.browser.msie) {
					//weird bug with clear type means we can't animate opacity in ie.
					$('.text_box .scroller').animate({'opacity':0},'fast',function(){$(this).html(newContent);
						$('.text_box .scroller').css({'opacity':1}).jScrollPane({scrollbarWidth:20,scrollbarMargin:0,showArrows:true,arrowSize:10,dragMinHeight:19,maintainPosition:false});
						$('.text_box .scroller').get(0).style.removeAttribute('filter');
						if(cnttype == 'gallery') {gallery();}
					});
				} else {
					$('.text_box .scroller').animate({'opacity':0},'fast',function(){$(this).html(newContent);});
					$('.text_box .scroller').animate({'opacity':1},'fast',function(){	
						$('.text_box .scroller').jScrollPane({scrollbarWidth:20,scrollbarMargin:0,showArrows:true,arrowSize:10,dragMinHeight:19,maintainPosition:false});
						if(cnttype == 'gallery') {gallery();}
					});

				}
			},500);
		
		},'html');
		
		
		
		return false;
	
	
	});
	
}

function selectMenu(){

	//replace form with a div, anchor tag and ul - retaining info
	$('form.selector').each(function(){
	
		var selectorForm = $(this);
		var selectorLabelText = selectorForm.find('label').text();
		selectorForm.after('<div class="selector"><a href="" class="drop_button"><span>'+selectorLabelText+'</span></a><ul></ul></div>');
		selectorForm.find('select').children().clone().appendTo( selectorForm.siblings('div.selector').children('ul') );
		selectorForm.siblings('div.selector').children('ul').children('option').each(function(i, ele){
			$(ele).replaceWith('<li><a href="'+$(ele).attr('value')+'">'+$(ele).text()+'</a></li>');		
		});						
		selectorForm.remove();
	
	});
	
	//add in drop down functionality on click
	$('a.drop_button').click(function(){
		//$(this).siblings('ul').show().parents('.selector').mouseleave(function(event){$(this).children('ul').hide();});
		var drop_button = $(this);
		drop_button.siblings('ul').show().parents('.selector').mouseout(function(event){
			$(document).mousedown(function(){drop_button.siblings('ul').hide();});
		}).mouseover(function(event){
			$(document).unbind('mousedown');
		});
		return false;
	});

}

function loginOverlay(){

	$('#header .user_info button').click(function(){
	
		$('.overlay').remove();
		$.get('/components/overlay.php', function(data){
			$('.main>.inner').append(data);
			$('.overlay .module').prepend('<h2>Login</h2>');
			$('#header .user_info').clone().prependTo('.overlay .module_inner');
			
			$('.overlay a.close').click(function(){
				$('.overlay').remove();
				return false;
			});
			//Cufon.replace('.overlay h2');
			$('.user_info a.whatwbid').click(function(){
				$('.overlay').remove();
				$.get('/components/overlay.php', function(data){
					$('.main>.inner').append(data);
					$('.overlay .module').prepend('<h2>Login</h2>');
					$('#header .user_whatwbid').clone().prependTo('.overlay .module_inner');
					$('.overlay a.close').click(function(){
						$('.overlay').remove();
						$('#header .user_info button').click();
						return false;
					});
					//Cufon.replace('.overlay h2');
				});
				
				return false;
			});
			
			$('.user_info a.forget').click(function(){
				$('.overlay').remove();
				$.get('/components/overlay.php', function(data){
					$('.main>.inner').append(data);
					$('.overlay .module').prepend('<h2>Reminder</h2>');
					$('#header .user_reminder').clone().prependTo('.overlay .module_inner');
					$('.overlay a.close').click(function(){
						$('.overlay').remove();
						return false;
					});
					//Cufon.replace('.overlay h2');
				});
				
				return false;
			});
			
			return false;
		});
		return false;
	
	});

}

function noSubmitOverlay(){
	
	$('.no-submit').hide();
	
	$('.disable-submit').click(function(){
	
		$('.overlay').remove();
		$.get('/components/overlay.php', function(data){
		
			$('.main>.inner').append(data);
			var noSubmitMsg = $('div.no-submit').html();			
			$('.overlay .scroller').html(noSubmitMsg);
			
			$('.overlay a.close').unbind('click').click(function(){
				$('.overlay').remove();
				return false;
			});
			$('.overlay a.login').click(function(){
				$('#header .user_info button').trigger('click');
				return false;
			});
			//Cufon.replace('.overlay h2');
		});
		window.scroll(100,0);
		return false;

	});

}

function messageOverlay(title, msg){
	
	$('.overlay').remove();
	$.get('/components/overlay.php', function(data){
	
		$('.main>.inner').append(data);
		$('.overlay .module').prepend(title);
		$('.overlay .module_inner').prepend(msg);
		
		$('.overlay a.close').unbind('click').click(function(){
			$('.overlay').remove();
			return false;
		});
		
		//Cufon.replace('.overlay h2');
	});

	return false;
}

function deleteLink(){

	$('.delete_link a.linker').click(function(){
	
		$("html").scrollTop(0);
	
		msghtml = '<p>Are you sure you want to delete your account? All your current <span class="warnertv">W<span>arner</span>TV</span> loyalty points will be lost. This cannot be undone.</p>';
		msghtml += '<form action="delete.php" method="post"><div><label for="email">Email:</label><input type="text" class="text" name="email" /></div>';
		msghtml += '<div><label for="password">Password:</label><input type="text" class="text" name="password" /></div>';
		msghtml += '<button type="submit" name="submit" class="linker_alt"><span>DELETE ACCOUNT</span></button></form>';
		
		messageOverlay('<h2>Delete Account? Are you sure?</h2>', msghtml);		
		return false;
	
	});

}

function linksNav(){

	$('.mainnav .subnav span').click(function(){
	
		
		$('.showsnav').hide(); //hide the shows subnav menu.
	
		if($(this).siblings('ul:visible').length > 0) { //if it's currently open: hide all subnav menus
			
			$('.mainnav .subnav ul').hide();
		
		} else { //if it's currently closed: hide all sub nav menus and show this one
			 
			$('.mainnav .subnav ul').hide();
			$(this).siblings('ul').show();
			
		}
		
	});


}

function showsNav(){

	/* Change colour on hover
	$('.showsnav .genrelist li').hover(function(){
		var className = $(this).attr('class');
		var hexColor = $(this).css('background-color');	
		$('.showsnav .showlists a.'+className).css('color',hexColor);		 
	},function(){
		$('.showsnav .showlists a').css('color','#ffffff');
	});
	*/
	$('.showsnav .genrelist li').click(function(){
		
		//window.console.log ($('.showlists a').css('color'));
		
		var className = $(this).attr('class').replace('-hover','');
		var hexColor = $(this).css('background-color');	
		
		if($('.showsnav .showlists a.'+className).css('color') == hexColor) {
		
			$('.showsnav .showlists a').css({'color':'#ffffff'});
		
		} else {

			$('.showsnav .showlists a').css({'color':'#444444'});
			$('.showsnav .showlists a.'+className).css({'color':hexColor});
		
		}
				 	
	}).hover(function(){
		var className = $(this).attr('class');
		$(this).attr('class',className+'-hover')
	},function(){
		var className = $(this).attr('class');
		$(this).attr('class',className.replace('-hover',''));
	});
	
	$('.mainnav li.shows a').click(function(){
	
		$('.mainnav .subnav ul, .mainnav .subnav a.close').hide();
		$('.showsnav').toggle();
		return false;
	
	});

	$('.showsnav a.close').click(function(){
	
		$('.showsnav').hide();
		return false;
		
	});

}

function footer(){

	$('#footer .footer_info>div').hide();
	$('#footer .footer_info_menu a').click(function(){
		
		var className = $(this).parents('li').attr('class');
		
		$('#footer .footer_info>div:not(.'+className+')').hide();
		
		if($('#footer .footer_info>div.'+className).css('display') == 'none') {
		
		
			$('#footer .footer_info>div.'+className).slideToggle(200);
			
			var footOffset = $('#footer').offset();
			var currOffset = $(document).scrollTop();		
		
			var from = {property: currOffset};
			var to = {property: footOffset.top};
			 
			$(from).animate(to, {
			    duration: 600,
			    step: function() {
					//console.log( 'Currently @ ' + this.property );
			        $(document).scrollTop(this.property);
			    }
			});	
		
		} else {
			
			$('#footer .footer_info>div.'+className).stop().hide();
	
		}
		
		
		return false;
	});
	
	$('#footer .footer_links li:not(.ralph) a').click(function(){
	
		//first remove any existing overlays
		$('.overlay').remove();
	
		var href = $(this).attr('href');
	
		if(href == 'http://wwws.ww.warnerbros.com/portal_uk/#/privacy/' || href == 'http://wwws.ww.warnerbros.com/portal_uk/#/terms/') {return true;}
		if(href == '/terms_and_conditions.php') {return true;}
		
		//load overlay html
		$.get('components/overlay.php',function(overlayHtml){
		
			//load the content to go inside it		
			$.get(''+href,function(contentHtml){
			
				//insert overlay
				$('.main .inner').append(overlayHtml);
			
				//put content inside it
				var headHtml = $(contentHtml).find('.module>h2').html();
				var bodyHtml = $(contentHtml).find('.module>.module_inner').html();
			
				$('.overlay .module').prepend('<h2>'+headHtml+'</h2>').find('.module_inner').prepend(bodyHtml);
				$('.overlay .scroller').height(300);
				//Cufon.replace('.overlay h2');
				$('.overlay .scroller').jScrollPane({scrollbarWidth:20,scrollbarMargin:0,showArrows:true,arrowSize:10,dragMinHeight:19,maintainPosition:false});			
				
				//close button			
				$('.overlay a.close').click(function(){
					$('.overlay').remove();
					return false;
				});
				
				//scroll to overlay
				window.scroll(100,0);
				
			});
		
		});	
		return false;
	
	});
	$('#footer .sitemap_links a').click(function(){
	
		//first remove any existing overlays
		$('.overlay').remove();
	
		var href = $(this).attr('href');
		if(href == 'terms_and_conditions.php') {return true;}
	
		//load overlay html
		$.get('components/overlay.php',function(overlayHtml){
		
			//load the content to go inside it		
			$.get('components/'+href,function(contentHtml){
			
				//insert overlay
				$('.main .inner').append(overlayHtml);
			
				//put content inside it
				var headHtml = $(contentHtml).find('h2').html();
				var bodyHtml = $(contentHtml).find('.module_inner').html();
			
				$('.overlay .module').prepend('<h2>'+headHtml+'</h2>').find('.module_inner').prepend(bodyHtml);
				$('.overlay .scroller').height(300);
				//Cufon.replace('.overlay h2');
				$('.overlay .scroller').jScrollPane({scrollbarWidth:20,scrollbarMargin:0,showArrows:true,arrowSize:10,dragMinHeight:19,maintainPosition:false});			
				
				//close button			
				$('.overlay a.close').click(function(){
					$('.overlay').remove();
					return false;
				});
				
				//scroll to overlay
				window.scroll(100,0);
				
			});
		
		});	
		return false;
	
	});
	$('.tandcs a').click(function(){
	
		//first remove any existing overlays
		$('.overlay').remove();
	
		var href = $(this).attr('href');
	
		//load overlay html
		$.get('components/overlay.php',function(overlayHtml){
		
			//load the content to go inside it		
			$.get(''+href,function(contentHtml){
			
				//insert overlay
				$('.main .inner').append(overlayHtml);
			
				//put content inside it
				var headHtml = $(contentHtml).find('h2').html();
				var bodyHtml = $(contentHtml).find('.module_inner').html();
			
				$('.overlay .module').prepend('<h2>'+headHtml+'</h2>').find('.module_inner').prepend(bodyHtml);
				$('.overlay .scroller').height(300);
				//Cufon.replace('.overlay h2');
				$('.overlay .scroller').jScrollPane({scrollbarWidth:20,scrollbarMargin:0,showArrows:true,arrowSize:10,dragMinHeight:19,maintainPosition:false});			
				
				//close button			
				$('.overlay a.close').click(function(){
					$('.overlay').remove();
					return false;
				});
				
				//scroll to overlay
				window.scroll(100,0);
				
			});
		
		});	
		return false;
	
	});
	
} 

/*
function ajaxform(thisform, phpPage)
{
    // Set up data variable
    var formdata = "";

    // Loop through form fields
    for (i=0; i < thisform.length; i++)
    {
         //Build Send String
         if(thisform.elements[i].type == "text"){ //Handle Textbox's
                  formdata = formdata + thisform.elements[i].name + "=" + escape(thisform.elements[i].value) + "&";
         }else if(thisform.elements[i].type == "textarea"){ //Handle textareas
                  formdata = formdata + thisform.elements[i].name + "=" + escape(thisform.elements[i].value) + "&";
         }else if(thisform.elements[i].type == "checkbox"){ //Handle checkbox's
                 if(thisform.elements[i].checked==true){
                     formdata = formdata + thisform.elements[i].name + "=" + thisform.elements[i].value + "&";
                  }
				 //formdata = formdata + thisform.elements[i].name + "=" + thisform.elements[i].checked + "&";
         }else if(thisform.elements[i].type == "radio"){ //Handle Radio buttons
                  if(thisform.elements[i].checked==true){
                     formdata = formdata + thisform.elements[i].name + "=" + thisform.elements[i].value + "&";
                  }
         }else{
                  //finally, this should theoretically this is a select box.
                  formdata = formdata + thisform.elements[i].name + "=" + escape(thisform.elements[i].value) + "&";
         }
    }
	//alert(formdata);	
	$.post(phpPage, formdata, function(postHTML){
		var headHtml = $(postHTML).find('h2').html();
		var bodyHtml = '<div class="module_inner">'+$(postHTML).find('.module_inner').html()+'</div>';
		$('.overlay .module').find('.module_inner').replaceWith(bodyHtml);
	}
	);

	
	return false;
}
*/
function recommend(){

	$('a.tell_a_friend').click(function(){
		
		//first remove any existing overlays
		$('.overlay').remove();
	
		var href = $(this).attr('href');
	
		//load overlay html
		$.get('components/overlay.php',function(overlayHtml){
		
			//load the content to go inside it		
			$.get('components/'+href,function(contentHtml){
			
				//insert overlay
				$('.main .inner').append(overlayHtml);
			
				//put content inside it
				var headHtml = $(contentHtml).find('h2').html();
				var bodyHtml = $(contentHtml).find('.module_inner').html();
			
				$('.overlay .module').prepend('<h2>'+headHtml+'</h2>').find('.module_inner').prepend(bodyHtml);
				//$('.overlay .scroller').height(300);
				$('.overlay .module').addClass('recommend');
				//Cufon.replace('.overlay h2');
				//$('.overlay .scroller').jScrollPane({scrollbarWidth:20,scrollbarMargin:0,showArrows:true,arrowSize:10,dragMinHeight:19,maintainPosition:false});			
				
				//close button			
				$('.overlay a.close').click(function(){
					$('.overlay').remove();
					return false;
				});
				
				//scroll to overlay
				window.scroll(100,0);
				
			});
		
		});	
		
		return false;
	
	});

}



(function($) {

	$.fn.shelf = function(options){
	
		var opts = $.extend({}, $.fn.shelf.defaults, options);
	
		return this.each(function() {
			
			var $this = $(this);
			var o = $.meta ? $.extend({}, opts, $this.data()) : opts;
			
			//get the individual item width (should be defined in the css)
			var itemWidth = $this.find('li').innerWidth();
		
			//total no. of items
			var itemCount = $this.find('li').length;
			if(itemCount < 1) {			
				$this.after('<div class="shelf_controls"></div>');			
			} else {
			
			//theorecital absolute offset of current item = (containerWidth - itemWidth)/2
			var theoOffset = ($this.width() - itemWidth)/2;
		
			//set the itemsToShow that we're aiming for
			var itemsToShow = itemCount*o.portionToShow/100;
		
			//default left margins - this defines how close each item gets squashed up to its neighbour. default right margin should be set to zero 
			var defLeft = ((itemsToShow*itemWidth) + o.selectedSpace - theoOffset)/(1 - itemsToShow);
			if(defLeft > o.maxDL){defLeft = o.maxDL;} else if (defLeft < o.minDL){defLeft = o.minDL;}
			var defRight = 0;
		
			//now need to calculate itemsToShow to take into account the min and max defLeft values
			itemsToShow = (theoOffset + defLeft - o.selectedSpace) / (itemWidth + defLeft);
				
			//current item's left margin
			var currLeft = theoOffset - (itemsToShow * (itemWidth + defLeft)) + defLeft;
			var currRight = theoOffset - (itemsToShow * (itemWidth + defLeft));

			//leftOffset gets applied to the shelf_list
			//var leftOffset = (itemCount - (itemsToShow+1)) * (-(itemWidth + defLeft)) - defLeft;
			var leftOffset = theoOffset - currLeft;
			
			//set up the shelf:
			$this.wrap('<div class="shelf_holder"></div>');
			$this.find('li').each(function(i,ele){
				var itemTitle = $(ele).children('img').attr('title');	
				var itemMarkup = $(ele).html();
    			itemMarkup = $.fn.shelf.format(itemMarkup,itemTitle);
				$(ele).html(itemMarkup);			
			});		
			$this.find('.shelf_item_title').css('opacity',0).show();			
			$this.find('ul').css({'margin-left':leftOffset,'width':(itemWidth*itemCount)+(o.selectedSpace*2)}).addClass('shelf_list');
			$this.find('li').css('margin-left',defLeft);
			$this.find('li:first').css({'margin-left':currLeft,'margin-right':currRight}).addClass('current').find('.shelf_item_title').css('opacity',0.99);
			if(itemCount < 2) {			
				$this.after('<div class="shelf_controls"></div>');			
			} else {
				$this.after('<div class="shelf_controls"><ul><li class="back"><a href="">Back</a></li><li class="more"><a href="">More</a></li></ul><div class="shelf_scrollbar"><div class="shelf_scrollbar_handle"><div class="shelf_scrollbar_handle_left"></div><div class="shelf_scrollbar_handle_right"></div></div></div></div>');
			}
			var currItemIndex = 0;
						
			//scrollbar 
			var minHandleWidth = 100;
			var scrollBarWidth = $this.next('.shelf_controls').find('.shelf_scrollbar').width();
			
			var scrollUnit = 20;
			var handleWidth = scrollBarWidth-(scrollUnit*(itemCount-1));

			for(scrollUnit = 20;handleWidth < minHandleWidth;scrollUnit--) {
				if(scrollUnit == 0){break;}
				var handleWidth = scrollBarWidth-(scrollUnit*(itemCount-1));
			}
			if(scrollUnit == 0) {$this.next('.shelf_controls').find('.shelf_scrollbar_handle').hide();}
			
			//window.console.log("scroll unit = "+scrollUnit+"; handle width = "+handleWidth);
			$this.next('.shelf_controls').find('.shelf_scrollbar_handle').width(handleWidth+'px');
			
			$this.next('.shelf_controls').find('.shelf_scrollbar_handle').draggable({ 
				axis: 'x',
				containment: 'parent',
				drag: function(event,ui) {
					var scrollVal = parseInt(parseInt($(this).css('left'))/scrollUnit);
					if(scrollVal != currItemIndex) { goToItem(scrollVal); }
				}					
			});
			
			//back and forth arrows
			$this.next('.shelf_controls').find('.back a').click(function(){				
				if($this.find('li.current').prevAll('li').length > 0) {
					var itemIndex = currItemIndex - 1;
					goToItem(itemIndex);
					scrollPosition = itemIndex * scrollUnit;
					$this.next('.shelf_controls').find('.shelf_scrollbar_handle').animate({'left':scrollPosition+'px'},'fast','swing');
				}
				return false;			
			});
			$this.next('.shelf_controls').find('.more a').click(function(){			
				if($this.find('li.current').nextAll('li').length > 0) {
					var itemIndex = currItemIndex + 1;
					goToItem(itemIndex);
					scrollPosition = itemIndex * scrollUnit;
					$this.next('.shelf_controls').find('.shelf_scrollbar_handle').animate({'left':scrollPosition+'px'},'fast','swing');
				}
				return false;			
			});
	
			function goToItem(itemIndex){
				
				leftOffset = theoOffset - currLeft - (itemIndex * (itemWidth + defLeft));
				
				$this.find('li.current .shelf_item_title').stop().fadeTo('fast',0);
				$this.find('li.current').stop().animate({'marginLeft':defLeft+'px','marginRight':defRight+'px'},o.speed,o.easing).removeClass('current')
				$this.find('li:eq('+itemIndex+')').addClass('current').stop().animate({'marginLeft':currLeft+'px','marginRight':currRight+'px'},o.speed,o.easing);
				$this.find('ul').stop().animate({'marginLeft':leftOffset},o.speed,o.easing);
				$this.find('li.current .shelf_item_title').fadeTo(o.speed,0.99);		
				
				currItemIndex = itemIndex;
				
				return false;
			
			}
			}
		});
	
	}
	
	
	// format the markup inside each list item
	$.fn.shelf.format = function(itemMarkup, itemTitle) {
		return '<div class="shelf_item_holder">' + itemMarkup + '<div class="shelf_item_mask"></div></div><span class="shelf_item_title">'+itemTitle+'</span>';
	};

	//plugin defaults
	$.fn.shelf.defaults = {
		easing: 'swing',
		speed: 'slow',
		//proportion of the total number of items to show on each side (percentage).
		portionToShow: 60,
		//space (in px) to put around selected object
		selectedSpace: 30,
		//minimun & maximum defLeft values
		minDL: -107,
		maxDL: -40
	};

})(jQuery);

function shelf(){
	
	$('.shelf').shelf();
	
	$('.theshelf a.add').click(function(){
	
		//first remove any existing overlays
		$('.overlay').remove();
	
		var href = $(this).attr('href');
	
		//load overlay html
		$.get('components/overlay.php',function(overlayHtml){
		
			//load the content to go inside it	
			$.get('components/'+href,function(contentHtml){
			
				//insert overlay
				$('.main .inner').append(overlayHtml);
			
				//put content inside it
				var headHtml = $(contentHtml).find('h2').html();
				var bodyHtml = $(contentHtml).find('.module_inner').html();
			
				$('.overlay .module').prepend('<h2><span class="grad"></span>'+headHtml+'</h2>').find('.module_inner').prepend(bodyHtml);
				$('.overlay .module').addClass('shelf_add');
				$('.overlay').addClass('push_overlay');
				$('.overlay .module div.help').hide();
				//Cufon.replace('.overlay h2');
				
				//close button			
				$('.overlay a.close').click(function(){
					$('.overlay').remove();
					refreshShelf();
					return false;
				});
				//help button			
				$('.overlay a.help').click(function(){
					$('.overlay div.help').slideToggle();
					return false;
				});				
								
			});
		
		});	

	
		return false;
	
	});	
}

function refreshShelf(){

	$.get('hub.php',function(updatedHubHtml){
					
		var shelfHtml = $(updatedHubHtml).find('.theshelf').html();
		$('.theshelf').html(shelfHtml);
		shelf();
						
	});

}

function redeemForm(){

	//disable all check boxes
	$('.redeem input[type=checkbox]').attr('disabled','disabled');
	
	//on active label click
	$('.redeem label.linker').live('click',function(){
	
		//deactivate button	
		$(this).removeClass('linker').children('span').text('added to basket').parents('.dvd').stop().animate({'opacity':0.5});
		
		//add to basket
		var showname = $(this).siblings('.show').text();
		var seriesname = $(this).siblings('.series').text();
		var points = parseInt($(this).siblings('.points').text());
		var img = $(this).siblings('.img70').html();
		var inputVal = $(this).siblings('input').val();
		var basketHtml = '<li><span class="title">'+showname+' '+seriesname+'</span><span class="img30">'+img+'</span><span class="points">'+points+'pts</span><a href="" class="remove linker"><span>Remove</span></a><input type="hidden" name="dvds[]" value="'+inputVal+'" /></li>';		
		$('.redeem .basket_list').append(basketHtml);

		//update Total points spent
		updatePointTotal(points);		
		
		return false;
	
	});
	
	//on remove click
	$('.redeem .basket a.remove').live('click', function(){
	
		//reactivate button
		var inputVal = $(this).siblings('input').val();
		$('.redeem_dvds input[value='+inputVal+']').siblings('label').addClass('linker').children('span').text('Get this').parents('.dvd').stop().animate({'opacity':1});
		
		var points = parseInt($(this).siblings('.points').text());
		
		//remove from basket
		$(this).parent('li').remove();
		
		//update Total points spent
		updatePointTotal(-points);		

		return false;
		
	});
	
	//update Total points spent
	function updatePointTotal(points){
	
		var userpoints = $('#userpoints').text()*1;
		var newTotalSpent = $('.basket_total .val span').text()*1 + points;
		
		//update basket total
		$('.basket_total .val span').text(newTotalSpent);

		//re-assess if the user has enough points to get each dvd not currently in the basket
		var pointsAvailable = userpoints - newTotalSpent;
		//window.console.log(pointsAvailable +' points available');
		
		$('.redeem .dvd').each(function(i, ele){
		
			//first check if it's in the basket already
			if($(ele).children('label').children('span').text() == 'added to basket') {return true;}
		
			var value = parseInt($(ele).children('.points').text());
			if(pointsAvailable - value < 0) {
				//make unavailable
				$(ele).children('label').removeClass('linker').children('span').text('not enough points')
			} else {
				//make available
				$(ele).children('label').addClass('linker').children('span').text('Get this')
			}
			
		
		});
		
	
	}

}

function poll(){

	//replace radio buttons with ul
	$('.poll form').append('<ul></ul>');
	$('.poll fieldset input[type=radio]').each(function(i,ele){
	
		var fieldvalue = $(ele).val();
		var fieldlabel = $(ele).siblings('label').text();
	
		$(ele).parents('form').find('ul').append('<li><a href="'+fieldvalue+'">'+fieldlabel+'</a></li>');
		
	
	});
	
	//add click functionality to 'ul li a'
	$('.poll ul a').live('click',function(){
	
		var pollForm = $(this).parents('form')

		var formAction = pollForm.attr('action');
		var answerVal = $(this).attr('href');
		var actionVal = pollForm.find('input[name=action]').val();
		var poll_idVal = pollForm.find('input[name=poll_id]').val();
		
		//on submit - send form, get results and replace the poll.
		$.post(formAction, {'action':actionVal,'poll_id':poll_idVal,'answer':answerVal},function(data){
		
			var pollResults = $(data).find('.poll form').html();
			$('.poll form').html(pollResults);
			//Cufon.replace('.poll h3');
		
		},'html');	
		return false;
		
	});

}

function pushPVT(userId, pushResponse) {           

	$('.profile_summary .module_inner').prepend('<p>item validated</p>');

} 

function faq (){

	$('.vod_faq dt').click(function(){
		$(this).toggleClass('open');
		$(this).next('dd').slideToggle('fast');
		return false;
	
	});

}

function centerer(){

	//needed to fix firefox3.6 1px-centering-flash-bug -- https://bugzilla.mozilla.org/show_bug.cgi?id=550246
	var width =	$('body').width();
	var margin = parseInt((width-1010)/2);
	if(margin < 0) {margin = 0;}
	$('div.main').children('div.inner').css({'margin':'0 '+margin+'px'})


}

//digital smith video player
var Digitalsmiths = {
	defaultBannerAction: "navigate",
	autoScrollPage: false,
	autoScrollTarget: "maindiv_top"
};
var currentMediaKey = null;
var currentMedia = null;
function getDefineMedia() {
    return currentMediaKey;
}
function defineMedia(a,b,c) {
    currentMediaKey = a;
    swfobject.getObjectById("vid_player").defineMedia(a,b,c);
    //showDefaultBanner();
    if (Digitalsmiths.autoScrollPage)
            document.getElementById(Digitalsmiths.autoScrollTarget).scrollIntoView(true);
}
function displayMedia (x) {
    currentMedia = x;
    var playlist = swfobject.getObjectById("vid_player");
    if (playlist)
            playlist.displayMedia(x);
}
function displayStillImage(a) {
    swfobject.getObjectById("vid_player").displayStillImage(a);
}
var alist = null;
function onDemandSkip(action) {
    var plist = $("a[data-id]");
    alist = $.makeArray(plist);
    key = (currentMediaKey == null) ? alist[0].attributes['data-id'].value : currentMediaKey;

    for (i=0;i<alist.length;i++) {
        dataid = alist[i].attributes['data-id'].value;

        if (dataid == key) {
            nexti = (action=='next') ? i+1 : i-1;
            if (action=='next') {
                nextdataid =  (nexti < alist.length) ? alist[nexti].attributes['data-id'].value : alist[0].attributes['data-id'].value;

            } else {
                nextdataid =  (nexti > 0) ? alist[nexti].attributes['data-id'].value : alist[0].attributes['data-id'].value;

            }
            defineMedia(nextdataid);
            break;
        }
    }
}

function mediaComplete(key) {
    var plist = $("a[data-id]");
    var title = null;
    var desc = null;
    alist = $.makeArray(plist);

    var vtype =  alist[0].attributes['data-vtype'];

    if (typeof vtype  == "undefined") {
        //main vid player calling
        for (i=0;i<alist.length;i++) {
            dataid = alist[i].attributes['data-id'].value;

            if (dataid == key) {
                nexti = i+1;
                if (nexti < alist.length) {
                    nextdataid = alist[nexti].attributes['data-id'].value;
                    title = alist[nexti].innerText;
                    if (typeof title  == "undefined") {
                        title = alist[nexti].text;
                    }
                    desc =  alist[nexti].attributes['data-desc'].value;
                    img = alist[nexti].attributes['data-img'].value;
                } else {
                    nextdataid = alist[0].attributes['data-id'].value;
                    title = alist[0].innerText;
                    if (typeof title  == "undefined") {
                        title = alist[0].text;
                    }
                    desc =  alist[0].attributes['data-desc'].value;
                    img = alist[0].attributes['data-img'].value;
                }
                $("#dsvidtitle").html(title);
                $("#dsviddesc").html(desc);
                //displayStillImage(img);
                defineMedia(nextdataid);
                break;
            }
        }
    } else {
        //ondemand vid player calling
        for (i=0;i<alist.length;i++) {
            dataid = alist[i].attributes['data-id'].value;

            if (dataid == key) {
                nexti = i+1;
                if (nexti < alist.length) {
                    nextdataid = alist[nexti].attributes['data-id'].value;
                } else {
                    nextdataid = alist[0].attributes['data-id'].value;
                }
                defineMedia(nextdataid);
                break;
            }
        }
    }

    
}
function setTitleDesc(key) {
    var title = $("a[data-id='"+key+"']").text();
    var desc = $("a[data-id='"+key+"']").attr('data-desc');

    if (typeof title == "undefined") {
        $("#dsvidtitle").html('');
        $("#dsviddesc").html('');
    } else {
        $("#dsvidtitle").html(title);
        $("#dsviddesc").html(desc);
    }

}
function loadMedia(key) {
    var title = $("a[data-id='"+key+"']").text();
    var desc = $("a[data-id='"+key+"']").attr('data-desc');

    if (typeof title == "undefined") {
        $("#dsvidtitle").html('');
        $("#dsviddesc").html('');
    } else {
        $("#dsvidtitle").html(title);
        $("#dsviddesc").html(desc);
    }
    defineMedia(key);
}
Digitalsmiths.embedSwf = function (swf, id, width, height, flashVars, params, attributes) {
    swfobject.embedSWF(swf, id, width, height, "9.0.0", "/flash/expressInstall.swf", flashVars, params, attributes);
}
