// new version controlled jquery.tlavideo.js

(function($){

	$.extend({

		tlavideo: {

			/* Content begins here */

			updateVMB: function() {
				var objMinute = $("#vodMinuteBalance");
				if (!objMinute.length) return false;
				$.ajax({
					type: "GET",
					data: {ts:new Date().getTime()},
					url: "../ajax/ajax_getVodMinutes.cfm",
					dataType: "xml",
					complete: function(xml) {
						var minutes = $("minutes",xml.responseXML).text();
						if (minutes == "error") return false;
						objMinute.text(minutes+((minutes!=1)?" Minutes ":" Minute ")+"Available");
					}
				});
			},

			tglInfoTabs: function(e) {
				var objTab = $(e);
				var objTabContent = $("#"+objTab.attr("id").replace(/-tab/,""));
				objTab.addClass("current");
				objTabContent.show();
				objTab.siblings().each(function(i) {
					var thisContent = $("#"+$(this).attr("id").replace(/-tab/,""));
					$(this).removeClass("current");
					thisContent.hide();
				});
				return false;
			}, /* end tglInfoTabs */

			/* Content ends here */


			/* TLA Lightbox functionality added 2008-06-02 (Pierre) */
			lightbox: {

				lightbox: null,
				overlay: $('#overlay'),

				init: function(obj) {

					this.lightbox = $('#'+obj);

					if (!this.overlay.length) {
						$(document.body).append('<div id="overlay"></div>');
						this.overlay = $('#overlay');
					}

					$(document.body).append(this.overlay).append(this.lightbox);
					this.lightbox.center();

					this.close();

					this.overlay.width($(document).width()).height($(document).height());

				},

				open: function(obj) {

					this.init(obj);
					this.overlay.show();
					this.lightbox.show().center();

				},

				close: function() {

					$('.lightbox').add('#overlay').hide();

				}

			} /* end lightbox */


		}, /* end tlavideo */


/* Copyright (c) 2006 Mathias Bank (http://www.mathias-bank.de)
 * 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 Hinnerk Ruemenapf - http://hinnerk.ruemenapf.de/ for bug reporting and fixing.
 */

		getURLParam: function(strParamName){
			var strReturn = "";
			var strHref = window.location.href;
			var bFound=false;

			var cmpstring = strParamName + "=";
			var cmplen = cmpstring.length;

			if ( strHref.indexOf("?") > -1 ) {
				var strQueryString = strHref.substr(strHref.indexOf("?")+1);
				var aQueryString = strQueryString.split("&");
				for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
					if (aQueryString[iParam].substr(0,cmplen)==cmpstring){
						var aParam = aQueryString[iParam].split("=");
						strReturn = aParam[1];
						bFound=true;
						break;
					}

				}
			}
			if (bFound==false) return null;
			return strReturn;
		}


	});

	$.fn.extend({

		center: function() {
			return this.each(function() {

				var myWidth		= $(this).outerWidth(),
					myHeight	= $(this).outerHeight(),
					winWidth	= $(window).width(),
					winHeight	= $(window).height(),
					leftScroll	= $(window).scrollLeft(),
					topScroll	= $(window).scrollTop();

				var newTop = ((winHeight/2)-(myHeight/2))+topScroll,
					newLeft = ((winWidth/2)-(myWidth/2))+leftScroll;

				if (newTop < 0) {
					newTop = 0;
				} else if (newTop < topScroll) {
					newTop = topScroll;
				}

				if (newLeft < 0) {
					newLeft = 0;
				} else if (newLeft < leftScroll) {
					newLeft = leftScroll;
				}

				$(this).css('position','absolute').css('top',newTop).css('left',newLeft);

			});
		}

	});

	$(function() {
		/* onloads begin here */
		
		$('td#lside form#advancedSearch h3').html('<a href="#" id="newAdvHeadingLink" style="display:block; font-weight:bold; font-size:12px; width:124px;">Refine Your Search +</a>').siblings().hide();
		$('a#newAdvHeadingLink').toggle(function(){
			$(this).parents('h3').siblings().show();
			$(this).html('Refine Your Search -');
		}, function() {
			$(this).parents('h3').siblings().hide();
			$(this).html('Refine Your Search +');
		});
		
		if ($(document.forms).filter("[name=TheLoginForm]").length) {
			
			var inputEm = $(document.forms).filter("[name=TheLoginForm]").children("input").filter("[name=email]");
			
			if (inputEm.length) {
				inputEm.css("background", "#fff url(../skins/graphics/header/header-bg_login_email.gif) no-repeat 4px 4px");
				if (inputEm.val().length) {
					inputEm.css("background", "#fff");
				}
				inputEm.focus(function(){
					$(this).css("background", "#fff");
				});
				inputEm.blur(function(){
					$(this).css("background", "#fff url(../skins/graphics/header/header-bg_login_email.gif) no-repeat 4px 4px");
					if ($(this).val().length) {
						$(this).css("background", "#fff");
					}
				});
			}
			
			var inputPw = $(document.forms).filter("[name=TheLoginForm]").children("input").filter("[name=password]");
			if (inputPw.length) {
				inputPw.css("background", "#fff url(../skins/graphics/header/header-bg_login_password.gif) no-repeat 4px 4px");
				if (inputPw.val().length) {
					inputPw.css("background", "#fff");
				}
				inputPw.focus(function(){
					$(this).css("background", "#fff");
				});
				inputPw.blur(function(){
					$(this).css("background", "#fff url(../skins/graphics/header/header-bg_login_password.gif) no-repeat 4px 4px");
					if ($(this).val().length) {
						$(this).css("background", "#fff");
					}
				});
			}
		} 
		
		if ($(document.forms).filter("[name=affliate-login-form]").length) {
			var inputSn = $("input").filter("[name=store_name]");
			if (inputSn.length) {
				inputSn.css("background", "#fff url(../skins/graphics/header/header-bg_login_store-name.gif) no-repeat 4px 4px");				
				if (inputSn.val().length) {
					inputSn.css("background", "#fff");
				}
				inputSn.focus(function(){
					$(this).css("background", "#fff");
				});
				inputSn.blur(function(){
					$(this).css("background", "#fff url(../skins/graphics/header/header-bg_login_store-name.gif) no-repeat 4px 4px");
					if ($(this).val().length) {
						$(this).css("background", "#fff");
					}
				});
			}
			
			var inputPw = $("input").filter("[name=affl_password]");
			if (inputPw.length) {
				inputPw.css("background", "#fff url(../skins/graphics/header/header-bg_login_password.gif) no-repeat 4px 4px");
				if (inputPw.val().length) {
					inputPw.css("background", "#fff");
				}
				inputPw.focus(function(){
					$(this).css("background", "#fff");
				});
				inputPw.blur(function(){
					$(this).css("background", "#fff url(../skins/graphics/header/header-bg_login_password.gif) no-repeat 4px 4px");
					if ($(this).val().length) {
						$(this).css("background", "#fff");
					}
				});
			}
		} 
		
		if ($(document.forms).filter("[name=thesearchform]").length) {
			var input = $("input").filter("[name=searchtext]");
			if (input.length) {
				input.css("background", "#fff url(../skins/graphics/header/header-bg_login_search.gif) no-repeat 4px 4px");
				if (input.val().length) {
					input.css("background", "#fff");
				}
				input.focus(function(){
					$(this).css("background", "#fff");
				});
				input.blur(function(){
					$(this).css("background", "#fff url(../skins/graphics/header/header-bg_login_search.gif) no-repeat 4px 4px");
					if ($(this).val().length) {
						$(this).css("background", "#fff");
					}
				});
			}
		}
		
		// Need keypress for the search input since it's the first 
		// one on the page the page will sometimes load with it focused.
		
		var searchInput = $("input");
   		var filteredinput = searchInput.filter("[name=searchtext]");
    	
  	 	$(filteredinput).keypress(function (e) {
  		  filteredinput.css("background", "#fff");
    	});
    	
    	// IE doesn't execute javascript on keypress in input boxes 
    	// using modifiers like the ctrl btn. This fixes ctrl + paste.
    	$(filteredinput).keydown( function (e){
		var key = e.charCode || e.keyCode || e.which;
		if(key == 86) {
			filteredinput.css("background", "#fff");
			}
		});
		
		
		$.tlavideo.updateVMB();

		// Update Minutes Only-If User is Logged In
		if ( $("#login-email","#login") || $("#login-password","#login") ) { }
		else {
			if ($("#vodMinuteBalance").length) window.setInterval($.tlavideo.updateVMB,60000);
		}
		
		
		// Click event handlers for adult links on new portal page
		$('#container .adultVerifyLinkGA').click(function(){
			adultVerifyLightbox($(this).attr('href'),0);
			return false;
		});
		$('#container .adultVerifyLinkSA').click(function(){
			adultVerifyLightbox($(this).attr('href'),1);
			return false;
		});

		// Trailer banner for the VOD Gay page begins
			$('#VODTrailerBanner').bind('mouseover',function(){
				var trailerContent = $(this).find('.trailerBannerContent');
				if (trailerContent.width() == 159) {
					trailerContent.animate({width:761},750,function(){
						trailerContent.find('.trailerWrapper').html('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="247" height="205" id="viddler_9b1879fa"><param name="flashvars" value="autoplay=t&wmode=transparent" /><param name="movie" value="http://www.viddler.com/simple/9b1879fa/" /><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="true" /><embed src="http://www.viddler.com/simple/9b1879fa/" width="247" height="205" type="application/x-shockwave-flash" allowScriptAccess="always" flashvars="autoplay=t&wmode=transparent" allowFullScreen="true" name="viddler_9b1879fa" ></embed></object>');
						trailerContent.find('.trailerBannerClose').show();
					});
					$('.trailerBanner').fadeOut(750);
				}
			});
			$('.trailerBannerClose').click(function(){
				$('#VODTrailerBanner .trailerBannerContent .trailerWrapper').empty();
				$('#VODTrailerBanner .trailerBannerContent').animate({width:159},750);
				$(this).hide();
				$('.trailerBanner').fadeIn(750);
				return false;
			});
		// Trailer banner for the VOD Gay page ends

		// Dynamic email signup
		if ($('#a1_email').length && $('#dynamicEmailSignupContainer').length) {
			$('#a1_email').bind('change',function(){
				getDynamicEmailListResults($(this).val());
			});
		}
		
		$('.lp_trailerBanner a').click(function(){
			var banner = $(this).parent();
			banner.toggleClass('lp_trailerBannerOpen');
			lpTrailerBanner(banner.get(0),banner.hasClass('lp_trailerBannerOpen'));
			return false;
		});
		
		// Portal cycle code
		$('.photolist').each(function(i){
			var photoLabel = $(this).attr('id').split('-')[1];
			var photoList = $(this).val().split(',');
			var photoContainer = $('#photo-'+photoLabel+' a');
			for (var i = 1; i < photoList.length; i++) {
				photoContainer.append('<img src="'+photoList[i]+'" width="237" height="127" border="0" alt="" style="display:none;" />');
			}
		});
		$('.imgTop-left a img:eq(2)').load(function() {
			$('.imgTop-left a').cycle({	fx:'fade',timeout:5000,random:0,delay:-4000});
		});			
		$('.imgTop-right a img:eq(2)').load(function() {
			$('.imgTop-right a').cycle({	fx:'fade',timeout:6200,random:0,delay:-5000});
		});			
		$('.imgBtm-left a img:eq(2)').load(function() {
			$('.imgBtm-left a').cycle({	fx:'fade',timeout:6500,random:0,delay:-4000});
		});			
		$('.imgBtm-center a img:eq(2)').load(function() {
			$('.imgBtm-center a').cycle({	fx:'fade',timeout:5800,random:0,delay:-2000});
		});			
		$('.imgBtm-right a img:eq(2)').load(function() {
			$('.imgBtm-right a').cycle({	fx:'fade',timeout:5500,random:0,delay:-1000});
		});
		
		$('#raw-container a').each(function(i){
			this.href = this.href + '&adult_pass=y';
		});
		
		//suckerfish
		var $sfLi = $('ul.suckerfish li');
		
		$sfLi.hover(function(){
			$(this).addClass('sfhover');
		}, function() {
			$(this).removeClass('sfhover');
		});
		
		$sfLi.each(function(){
			if ($(this).children('ul').length) {
				$(this).addClass('sf-arrow');
			} else {
				$(this).addClass('no-sub-ul');
			}
		});
		
		var $midUl = $('ul.suckerfish ul');
		
		$midUl.each(function(){
			var ulWidth = $(this).width();
			$(this).children('li').css({width: ulWidth});
		});
			
	}); /* onloads end here */


	function lpTrailerBanner(e,tgl) {
		var banner = $(e);
		var controls = banner.parent().parent().find('div.ctrlpad');
		var nextbanner = banner.parent().next();
		var pauseEventPars = controls.find('a.play').attr('rel').split(',');
		var pauseRE = /(pause)+/i;
		// Open
		if (tgl) {
			if (pauseRE.test(controls.find('a.play img').attr('src'))) skipArticle(pauseEventPars[0],pauseEventPars[1],'stop');
			var trailerPath = banner.find('a').attr('rel');
			var detailsPath = banner.find('a').attr('href');
			banner.animate({height:420},750,function(){
				banner.css('background-position','right top');
				banner.append('<div class="lp_trailerContainer"></div>');
				banner.find('.lp_trailerContainer').html('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="247" height="205"><param name="flashvars" value="autoplay=t&amp;wmode=transparent" /><param name="movie" value="http://www.viddler.com/simple/'+trailerPath+'/" /><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="true" /><!--[if !IE]>--><object type="application/x-shockwave-flash" data="http://www.viddler.com/simple/'+trailerPath+'/" width="247" height="205"><!--<![endif]--><div class="alternative-content"><div class="background"></div><a href="http://www.adobe.com/go/getflashplayer" target="_blank"><strong>In order to view the trailer for this film, you need to have Adobe Flash Player version 9.0 or higher. Please download it now by clicking on this link.</strong><br/><br/><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash Player" border="0" /></a></div><!--[if !IE]>--></object><!--<![endif]--></object>');
				banner.append('<a href="'+detailsPath+'" class="lp_trailerBannerMoreInfo">Click here for more info</a>');
			});
		// Close
		} else {
			skipArticle(pauseEventPars[0],pauseEventPars[1],'stop');
			banner.find('.lp_trailerContainer').remove();
			banner.find('lp_trailerBannerMoreInfo').remove();
			banner.animate({height:175},750,function(){
				$(this).css('background-position','left top');
			});
		}
	}

})(jQuery);




function getDynamicEmailListResults(email) {
	var container = $('#dynamicEmailSignupContainer');
	container.html('<p>Loading results...</p>');
	$('#staticEmailSignup').remove();
	$.ajax({
		type: 'GET',
		url: '/ajax/ajaxHandler.cfm',
		data: 'method=getEmailLists&email=' + escape(email),
		dataType: 'json',
		success: function(data) {
			container.empty().css({'padding-left' : '0'});
			for (i = 0; i < data.DATA.length; i++) {
				container.append('<div id="checkbox"><input type="checkbox" name="list_'+data.DATA[i][0]+'" id="list_'+data.DATA[i][0]+'" class="checkbox" /> '+data.DATA[i][1]+'</div>');
			}
		}
	});
}

function adultVerifyLightbox(url,vagina) {
	var newURL = url.replace(/\?+/,'{}').replace(/\&+/g,"|");
	var bgimage = vagina?$('#imgSplashStraight').val():$('#imgSplashGay').val();
	$('#adultVerifyContainer').css('background-image','url('+bgimage+')');
	$.tlavideo.lightbox.open('adultVerifyContainer');
	$('#adultVerifyContinue').attr('href','/adult_splash/pass.cfm?go='+newURL);
}


var articleInterval = new Array();
var articleIntervalCount = new Array();
var odBannerPos = 0;

function rotateArticle(seq) {
	var rowCount = 0;
	var curRow = 1;
	// figure out how many rows this SEQ has and set the display style
	while (document.getElementById("seq" + seq + "_row" + curRow)) {
		if (curRow == 1) {
			document.getElementById("seq" + seq + "_row" + curRow).style.display = "block";
		} else {
			document.getElementById("seq" + seq + "_row" + curRow).style.display = "none";
		}
		rowCount++;
		curRow++;
	}
	// set the rotation interval for this sequence
	articleInterval[seq] = window.setInterval("switchArticle(" + seq + "," + rowCount + ",'next')", 7000);
	articleIntervalCount[seq] = 0;
}

function switchArticle(seq,rowCount,action) {
	var curVisible = 0;
	var nextVisible = 0;
	// figure out which row is currently visible
	for (i=1; i <= rowCount; i++) {
		if (document.getElementById("seq" + seq + "_row" + i).style.display == "block") {
			curVisible = i;
			break;
		}
	}
	// based on current visible article, find the next article in the list to show
	if (action == 'next') {
		if (curVisible < rowCount) {
			nextVisible = curVisible + 1;
		} else if (curVisible == rowCount) {
			nextVisible = 1;
		}
	} else {
		if (curVisible <= rowCount && curVisible > 1) {
			nextVisible = curVisible - 1;
		} else if (curVisible == 1) {
			nextVisible = rowCount;
		}
	}
	// switch the display parameter on current and next visible articles
	document.getElementById("seq" + seq + "_row" + curVisible).style.display = "none";
	document.getElementById("seq" + seq + "_row" + nextVisible).style.display = "block";
	articleIntervalCount[seq]++;
	if (articleIntervalCount[seq] > 41) {
		skipArticle(seq,rowCount,'stop');
	}
}

function skipArticle(seq,rowCount,action) {
	if (action == 'next' || action == 'prev') {
		window.clearInterval(articleInterval[seq]);
		switchArticle(seq,rowCount,action);
		document.images['stopArticle' + seq].src = '../skins/graphics/icon_play.gif';
		//articleInterval[seq] = window.setInterval("switchArticle(" + seq + "," + rowCount + ",'next')", 7000);
		articleInterval[seq] = 0;
	} else if (action == 'stop') {
		if (articleInterval[seq]) {
			window.clearInterval(articleInterval[seq]);
			articleInterval[seq] = 0;
			document.images['stopArticle' + seq].src = '../skins/graphics/icon_play.gif';
		} else {
			articleInterval[seq] = window.setInterval("switchArticle(" + seq + "," + rowCount + ",'next')", 7000);
			articleIntervalCount[seq] = 0;
			document.images['stopArticle' + seq].src = '../skins/graphics/icon_pause.gif';
		}
	}
	return false;
}

function tglDVDinfo(tgl) {
	var myTab = "info";
	switch(tgl) {
		case 1:
			myTab = "keyword";
			break;
		case 2:
			myTab = "review";
			break;
		case 3:
			myTab = "gallery";
			break;
		case 4:
			myTab = "scene";
			break;
		case 5:
			myTab = "preview";
			break;
	}
	var tabRef = {
		info: document.getElementById("product-info-tab"),
		keyword: document.getElementById("keywords-tab"),
		review: document.getElementById("user-reviews-tab"),
		gallery: document.getElementById("image-gallery-tab"),
		scene: document.getElementById("scenes-tab"),
		preview: document.getElementById("preview-tab")
	}
	var contentRef = {
		info: document.getElementById("product-info"),
		keyword: document.getElementById("thekeywords"),
		review: document.getElementById("user-reviews"),
		gallery: document.getElementById("image-gallery"),
		scene: document.getElementById("scenes"),
		preview: document.getElementById("film-preview")
	}
	// reset tab-state and denote current
	if (tabRef.info) { tabRef.info.parentNode.className = ""; }
	if (tabRef.keyword) { tabRef.keyword.parentNode.className = ""; }
	if (tabRef.review) { tabRef.review.parentNode.className = ""; }
	if (tabRef.gallery) { tabRef.gallery.parentNode.className = ""; }
	if (tabRef.scene) { tabRef.scene.parentNode.className = ""; }
	if (tabRef.preview) { tabRef.preview.parentNode.className = ""; }
	tabRef[myTab].parentNode.className = "current";
	// reset content and show current
	if (contentRef.info) { contentRef.info.style.display = "none"; }
	if (contentRef.keyword) { contentRef.keyword.style.display = "none"; }
	if (contentRef.review) { contentRef.review.style.display = "none"; }
	if (contentRef.gallery) { contentRef.gallery.style.display = "none"; }
	if (contentRef.scene) { contentRef.scene.style.display = "none"; }
	if (contentRef.preview) { contentRef.preview.style.display = "none"; }
	contentRef[myTab].style.display = "block";
}

function tglHistory(tgl) {
	var myTab = "download";
	switch(tgl) {
		case 1:
			myTab = "rental";
			break;
		case 2:
			myTab = "ppm";
			break;
	}
	var tabRef = {
		download: document.getElementById("download-tab"),
		rental: document.getElementById("rental-tab"),
		ppm: document.getElementById("ppm-tab")
	}
	var contentRef = {
		download: document.getElementById("download-history"),
		rental: document.getElementById("rental-history"),
		ppm: document.getElementById("ppm-history")
	}
	// reset tab-state and denote current
	if (tabRef.download) { tabRef.download.parentNode.className = ""; }
	if (tabRef.rental) { tabRef.rental.parentNode.className = ""; }
	if (tabRef.ppm) { tabRef.ppm.parentNode.className = ""; }
	tabRef[myTab].parentNode.className = "current";
	// reset content and show current
	if (contentRef.download) { contentRef.download.style.display = "none"; }
	if (contentRef.rental) { contentRef.rental.style.display = "none"; }
	if (contentRef.ppm) { contentRef.ppm.style.display = "none"; }
	contentRef[myTab].style.display = "block";
}

function ondemandBannerSkip(d) {
	if (odBanner.length > 1) {
		var objBanner = $("#header-banner h2:eq(0) img:eq(0)");
		var objBannerLink = objBanner.parent();
		var i = 0;
		if (d) {
			if (eval(odBannerPos+1) == odBanner.length) {
				odBannerPos = 0;
			} else {
				odBannerPos++;
			}
		} else {
			if (odBannerPos == 0) {
				odBannerPos = eval(odBanner.length - 1);
			} else {
				odBannerPos--;
			}
		}
		if (odBanner && odBanner[odBannerPos]) {
			objBanner.attr("src",(d)?odBanner[odBannerPos].imgpath:odBanner[odBannerPos].imgpath);
			objBannerLink.attr("href",odBanner[odBannerPos].link);
		}
	}
}

function viewGallery(gid) {
	tglDVDinfo(3);
	//myURL = "../viewGallery.cfm?gid=" + gid;
	//myNewWindow = "view_gallery";
	//myWindowProperties = "width=380,height=500,toolbar=no,status=no,scrollbars=no,location=no,menubar=no,directories=no";
	//window.open(myURL,myNewWindow,myWindowProperties);
}
//the following dsp_gallery function has been deprecated and is not recommended, please use viewGallery() instead
function dsp_gallery(gid) {
	viewGallery(gid);
}

// legacy functions
function replaceText(el, text) {
	if (el != null) {
		clearText(el);
		var newNode = document.createTextNode(text);
		el.appendChild(newNode);
	}
}

function clearText(el) {
	if (el != null) {
		if (el.childNodes) {
			childLength = el.childNodes.length;
			for (var i = 0; i < childLength; i++) {
				el.removeChild(el.firstChild);
			}
		}
	}
}

function getText(el) {
	var text = "";
	if (el != null) {
		if (el.childNodes) {
			for (var i = 0; i < el.childNodes.length; i++) {
				var childNode = el.childNodes[i];
				if (childNode.nodeValue != null) {
					text = text + childNode.nodeValue;
				}
			}
		}
	}
	return text;
}

function RTrim(str) {
	while(str.charAt((str.length -1))==" "){
		str = str.substring(0,str.length-1);
	}
	return str;
}

function LTrim(str){
	while(str.charAt(0)==" "){
		str = str.replace(str.charAt(0),"");
	}
	return str;
}

function Trim(str){
	str = LTrim(str);
	return RTrim(str);
}

function addLoadEvent(func) {
   var oldonload = window.onload;
   if (typeof window.onload != 'function') {
       window.onload = func;
   }
   else {
       window.onload = function() {
           oldonload();
           func();
       }
   }
}




function VODFavorite() {

    this.add = function(curuserID, prodID) {
    	// alert(curuserID + " : " + prodID);
		$.ajax({
			type: "GET",
			url: "../ajax/ajax_VODFavorite.cfm",
			data: {a:"add",cid:curuserID,pid:prodID,ts:new Date().getTime()},
			complete: function(request) {
				var vodFaveLink = new VODFavorite;
				vodFaveLink.get(curuserID, prodID);
			}
		});
    }

    this.get = function(curuserID, prodID) {
        // Make sure the passed var is a number
		$.ajax({
			type: "GET",
			url: "../ajax/ajax_VODFavorite.cfm",
			data: {a:"view",cid:curuserID,pid:prodID,ts:new Date().getTime()},
			complete: function(request) {
				var XMLTableOutput = $(request.responseXML);
				var listFave = XMLTableOutput.find("favelist");
				var custid = XMLTableOutput.find("custid:eq(0)").text();
				var prodid = XMLTableOutput.find("prodid:eq(0)").text();
				var isfave = XMLTableOutput.find("isfave:eq(0)").text();
				// if not already a fave, show "add" link. If already a link, display "watch" message
				$('#vodFavoriteText').empty()
				if (isfave != 0) {
					$('#vodFavoriteText').append('<a href="javascript:void(0);"><img src="../skins/graphics/btns/remove.gif" border="0" alt="" /></a>');
				} else {
					$('#vodFavoriteText').append('<a href="javascript:void(0);"><img src="../skins/graphics/btns/favorites.gif" border="0" alt="" /></a>');
				}
				var vodFaveLink = new VODFavorite;
				if (isfave != 0) {
					$('#vodFavoriteText a:last-child').click(function() {
						vodFaveLink.remove(custid,prodid);
					});
				} else {
					$('#vodFavoriteText a:last-child').click(function() {
						vodFaveLink.add(custid,prodid);
					});
				}
			}
		});
    }

	this.remove = function(curuserID, prodID) {
		$.ajax({
			type: "GET",
			url: "../ajax/ajax_VODFavorite.cfm",
			data: {a:"remove",cid:curuserID,pid:prodID,ts:new Date().getTime()},
			complete: function(request) {
				var vodFaveLink = new VODFavorite;
				vodFaveLink.get(curuserID, prodID);
			}
		});
	}

}

function wmdlFlag($this) {
	
	// stock vs. vod - figure out where to put the message
	if ($('.vod-pricing').length) {
		$theContainer = $this.parent('div').parent('td');
	} else { 
		$theContainer = $this.parent('td');
	}
	
	// store the original href & title attributes
	var thisHref = $this.attr('href');
	var thisTitle = $this.attr('title')
	
	//final link text in message below
	
	if (thisTitle == 'wishlist') {
		wmdlMessageText = 'CONTINUE ADDING TO WISHLIST';
	} else {
		wmdlMessageText = 'CONTINUE WITH PURCHASE';
	}
	
	//beginining of message
	var wmdlMessage = ''
		+ 'Please note: TLA On-Demand Downloads can only be played on Windows systems - '
		+ 'please see our <a href="/support/supportOption.cfm?v=4&sn=40&supID=43#faq17" target="_blank" class="highlight">FAQ</a> for more details.'
		+ '<br /><a href="#" class="highlight wmdlCancel">CANCEL</a> | '
		+ '<a href="'+ thisHref +'" class="highlight">'+ wmdlMessageText +'</a>'
	;
	
	// get the container tr height, this is only a variable on the stock side
	var containerHeight = $theContainer.parent('tr').height();
	
	// jQuery helper CSS
	var wmdlCSS = {
		height : containerHeight,
		opacity : 0
		};
		
	//add the message
	$theContainer.prepend('<div class="wmdl-message-bkg"></div><p class="wmdl-message">'+ wmdlMessage +'</p>');
	
	//fade it in
	$theContainer.find('.wmdl-message-bkg, .wmdl-message').css(wmdlCSS).animate({opacity:1}, 500);
	
	//cancel click function
	$('.wmdlCancel').click(function(){
		$theContainer.find('.wmdl-message-bkg, .wmdl-message').remove();
		return false;
	});
}

function PPMOverlay() {

	var self = this;



	// a fail-safe to keep a user from clicking rapidly and launching
	// numerous overlays.
	var toggled = 0;



	// init();
	// Check to see if an item with the class .PPMoverlayImage exists
	// (this class will only exist on VOD scene images where PPM
	// isn't available, and the user doesn't have an active rental.)
	// Assign click functions to all such links.
	// Create our overlays.
	this.init = function() {

		var overlayClass = $(".PPMoverlayLink");
		if (overlayClass.length) {
			this.create();

			// on click, toggle between
			// showing/hiding our overlay.
			$(".PPMoverlayLink")
				.click( function(e) {

					// capture event, fix it for IE
					var event = self.fixEvent(e);

					var pdOffset = $("#info-cont").offset();
					var pdHeight = $("#info-cont").outerHeight();
					var ovOffset = $("#PPMoverlay").offset();
					var ovHeight = $("#PPMoverlay").outerHeight();

					var newTop = (event.pageY-pdOffset.top)-(ovHeight/2);
					if (newTop < 1) { newTop = 1; }
					else if ((event.pageY-pdOffset.top)+(ovHeight/2) > pdHeight) {
						newTop = pdHeight-ovHeight;
					}

					if (toggled == 0) {
						$("#PPMoverlay").css("top", newTop);
						$("#PPMoverlay").fadeIn("normal");
						toggled = 1;
					} else {
						$("#PPMoverlay").hide();
						toggled = 0;
					}

					return false;
				});
			$("#scenes-tab")
				.click( function() {
					if (toggled == 1) {
						$("#PPMoverlay").show();
					}
				});
			$("#product-info-tab")
				.add("#user-reviews-tab")
				.click( function() {
					if (toggled == 1) {
						$("#PPMoverlay").hide();
					}
				});

		}
	}; // end init();


	// fixEvent();
	// apparently IE doesn't have a pageX or pageY
	// return proper values in this
	this.fixEvent = function(e) {
		if ( e.pageX == null && e.clientX != null ) {
      		var e = document.documentElement, b = document.body;
      		e.pageX = e.clientX + (e && e.scrollLeft || b.scrollLeft || 0);
      		e.pageY = e.clientY + (e && e.scrollTop || b.scrollTop || 0);
   		}
   		return e;
	} // end fixEvent();

	// create();
	// Specify the error message.
	// Generate our overlays.
	// Determine the size and placement of our target div ("#scenes")
	// Center the overlays in the div.
	this.create = function() {

		var parentDiv = $("#info-cont");
		var error = "<p>Sorry, this title is not available for Pay-Per-Minute.<br /> " +
					"To purchase a rental of this title, click the link above.</p>" +
					"<p style='text-align: right'><img src='../skins/graphics/icon_close.gif' /></p>";

		$("<div id='PPMoverlay'>" + error + "</div>")
			.prependTo(parentDiv);

		var overlayValues = {
			position: "absolute",
			left: 0,
			top: 0,
			height: "45px",
			"z-index": "5000",
			opacity: "0.9",
			"-moz-opacity": "0.9",
			filter: "alpha(opacity=90)"
		}
		$("#PPMoverlay")
			.css(overlayValues);
		$("#PPMoverlay")
			.click( function() {
				if (toggled == 1) {
					$(this).hide();
					toggled = 0;
				}
				return false;
			})
			.css("display", "none");


	}; // end create();

}


// TLA Star Rating UI
// coded by: msb
// final draft date: [unknown]


function tlaRating() {

	// configurable user variables
	// sets the name of the containers that display
	// either a rating interface or the average
	// rating for current product.
	var userCont = ".user-rating";
	var avgCont = ".average-rating";

	// script variables.
	var self = this;
	var logged;

	if (typeof(window["globalProductID"]) != "undefined") {
		var productID = globalProductID;
	}

	var rater = 1;
	var finalRating = 0;

	var userSaved;

	// init function
	this.activate = function() {
		if (logged == undefined && typeof(window["globalProductID"]) != "undefined") {
			logged = $.ajax({
				type: "GET",
				url: "../ajax/ajax_UserRatings.cfm",
				data: { method: "getLoginStatus" },
				complete: function(request) {
					return request.responseText;
				}
			});
		}

		if ($("span.stars", userCont).length) {
			rater = 1;
			$("span.stars", userCont).each( function() {
				self.build(1, this);
				rater++;
			});
		}
		if ($("span", avgCont).length) {
			rater = 1;
			$("span", avgCont).each( function() {
				self.build(2, this);
				rater++;
			});
		}
	};

	// if javascript is enabled, overwrite the
	// degradable rating interface with swanky
	// ajax-powered interface.
	this.build = function(set, cont) {
		if (userSaved <= 0 || !userSaved ) {
			$("label", userCont).html("Rate this:");
		} else {
			$("label", userCont).html("Your rating:");
		}
		if (set == 1) { var type = "user"; } else { var type = "avg"; }

		$(cont).empty();

		if (!logged && set == 1) {
			$(cont.parentNode).html("Please log in to rate this item.");
		} else {
			for (var i = 1; i <= 8; i++) {
				if (i%2) { starHalf = "lstar"; }
				else { starHalf = "rstar"; }
				if (i < 3) { ender = " Star' />"; }
				else { ender = " Stars' />"; }
				$(cont).append("<img border='0' src='../skins/graphics/elements/" + starHalf + "_" + set + ".gif' class='stars off' name='star" + set + "_" + i + "' alt='" + type + rater + ": star" + set + "_" + i + "' title='" + i/2 + ender);


			}
			if (set == 1) {
				$(cont).prepend("<img border='0' src='../skins/graphics/elements/0stars.gif' class='zerostars off' alt='0 stars' title='Cancel rating'>");
				$(".zerostars").hover( function() { $(this).addClass("on"); $(this).removeClass("off"); },
										function() { $(this).addClass("off"); $(this).removeClass("on"); })
								.css("cursor", "pointer")
								.click( function() { userSaved = 0; self.setUserRating(0); });
				$("img[ @alt *= '" + type + rater + ":']", cont).each( function() {
					$(this).css("cursor", "pointer");
					var starAlt = $(this).attr("alt");
					var starBuild = starAlt.substring(4, 5);
					var set = starAlt.substring(starAlt.length-2, starAlt.length-3);
					var rating = starAlt.substring((starAlt.length-1), starAlt.length);

				//alert("img[ @alt *= '" + type + rater + ":']");


					$(this).mouseover( function() { self.emptyStars(starBuild); self.lightStars(set, rating, starBuild); });
					$(this).mouseout( function() { self.emptyStars(starBuild); self.lightStars(set, userSaved, starBuild); });
					$(this).click( function() { userSaved = rating; alert(userSaved); self.setUserRating(rating); });
				});
				
				self.getUserRating(rater);
			} else {
				self.getAvgRating(rater); }
		}

	};

	// these functions handle the highlighting/mouseover actions of the stars

	this.emptyStars = function(rater) {
		$("img[ @alt *= 'user" + rater + "' ]").removeClass("on").addClass("off").end();
	};

	this.lightStars = function(set, rating, build) {
		for (var i = 1; i <= rating; i++) {
			if (set == 1) { var tempStar = "user" + build + ": star" + set + "_" + i; }
			else { var tempStar = "avg" + build + ": star" + set + "_" + i; }
			$("img[ @alt = " + tempStar + " ]").removeClass("off").addClass("on").end();
		}
	};

	this.setUserRating = function(rating) {
		$("span", userCont).html("Saving...");
		finalRating = rating;
		$.ajax({
			type: "GET",
			cache: false,
			url: "../ajax/ajax_UserRatings.cfm?output=true&random=" + (Math.random() * Date.parse(new Date())),
			data: { method: "setUserRating", id: productID, rating: finalRating },
			complete: function() {
				self.activate();
			}

		});
	};

	this.getAvgRating = function(build) {
		$.ajax({
			type: "GET",
			dataType: "html",
			cache: false,
			url: "../ajax/ajax_UserRatings.cfm?output=true&random=" + (Math.random() * Date.parse(new Date())),
			data: { method: "getAvgRating", id: productID },
			complete: function(request) {
				var myint = Math.round(request.responseText);
				self.lightStars(2, myint, build);
			}
		});
	};

	this.getUserRating = function(build) {
		if (userSaved != undefined) {
			self.lightStars(1, userSaved, build);
		} else {
			$.ajax({
				type: "GET",
				dataType: "html",
				cache: false,
				url: "../ajax/ajax_UserRatings.cfm?output=true&random=" + (Math.random() * Date.parse(new Date())),
				data: { method: "getUserRating", id: productID },
				complete: function(request) {
					var myint = Math.round(request.responseText);
					userSaved = myint;
					self.lightStars(1, myint, build);
				}
			});
		}
	};

};


$(document).ready(function() {

	var newOverlay = new PPMOverlay;
	newOverlay.init();
	//var wee = new tlaRating();
	//wee.activate();
	
	// for the movie trailers on the details page | Yay! it works in IE again!
	$('#openTrailerLink').click(function(){
		$(document.body).append('<div id="trailerContainer2" class="lightbox"><a href="javascript:void(0);" class="lightboxClose" title="Close Window">close window</a></div>');
		var TrailerContent = $('#trailerContentWrapper').html();
		$.tlavideo.lightbox.open('trailerContainer2');
		$('#trailerContainer2').append(TrailerContent).center();
		$('#trailerContainer2 .lightboxClose').click(function(){
			$('#trailerContainer2').remove();
			$.tlavideo.lightbox.close();
		});
		return false;
	});
	
	
	if (navigator.appVersion.indexOf('Mac') != -1) {
		$(".wmdl-flag").click(function(){
			$this = $(this);
			wmdlFlag($this);
			return false;
		});
	}
	

});
