


	// used to format the preferences

	jQuery(function() {
		jQuery(".preferences-grouping tr td:first-child").css("width","250px");
	});
	

	/* Media Player*/

	/* author: scott.
	 * note:   logic has been reworked for QA purposes.  they needed 2 buttons, a play and a stop button,
	 *			instead of 1 dynamically changing play/stop button
	 * for reference: http://www.jeroenwijering.com/?item=Javascript_interaction
	 */
	// global vars
	var body;

	var currentlyPlaying = "";
	var previewObj = null;

	var previewLength = 14;
	var silentmp3 = "/bxss-portal/media/silent.mp3";
	var isPlaying =null;
	
	var previewAnimId = "previewAnim";
	var previewAnimObj = null;
	var previewAnimPathLarge ="/bxss-portal/media/UMGPurchasePreviewPlayAnim.gif";
	var previewAnimPathSmall ="/bxss-portal/media/UMGbrowseByGenrePreviewPlayAnim.gif";
	var previewAnimImgLarge=null;
	var previewAnimImgSmall=null;
	

	var previewCloseId = "previewClose";
	var previewCloseObj = null;
	var previewClosePath ="/bxss-portal/media/close.gif";
	var focusCatalogItem;
	
	var swfId = "scootFlvMediaPlayer";
	var mediaPlayerExpression = "#mediaPlayer";					// dynamically inserted just after the <body> tag
	var mediaPlayerId = "mediaPlayer";
	var mediaPlayerPath = "/bxss-portal/media/mediaplayer.swf";	// path to the swf file (update this if you change the war folder name)
	var mediaPlayerObj = null;
	var swfObj=null;

	var audioStartExpr = ".audio-preview-start-button";
	var audioStopExpr = ".audio-preview-stop-button";
	var videoStartExpr = ".video-preview-start-button";
	var videoStopExpr = ".video-preview-stop-button";
	var videoThumbnailExpr = ".video-preview-thumbnail";
	var thumbnail_link = ".thumbnail_link";

	// generic media player methods

	var sendEvent = function(swf,typ,prm) {
	  thisMovie(swf).sendEvent(typ,prm);
	};

	var getUpdate = function(typ,pr1,pr2,swf) {
	  if(navigator.appName.indexOf("Microsoft") != -1) {
		//no logging
	  } else {
	  	console.log(typ + ":" + pr1 + ":" + pr2 + ":" + swf);
	  }
	
	  if (typ =='time' && pr1 > previewLength)  {
	  	//alert('stop the music!');
	  	jQuery(isPlaying).siblings().click();
	  }
	};

	var thisMovie = function(swf) {
	  if(navigator.appName.indexOf("Microsoft") != -1) {
		return window[swf];
	  } else {
		return document[swf];
	  }
	};

	var loadFile = function(swf,obj) {
		var swfplayer=thisMovie(swf);
		swfplayer.loadFile(obj);
	};

	
	function makePlayer () {

		// create the div for media player. if not already there
		
			
			//previewAnimObj.hide();
			
			// convert div to actual media player
	
			var so = new SWFObject(mediaPlayerPath,swfId,'138','138','8');
			so.addParam('allowscriptaccess','always');
			so.addParam('allowfullscreen','true');
			so.addVariable('width','138');
			so.addVariable('height','138');
			so.addVariable('file','/bxss-portal/media/test.mp3');
			so.addVariable('enablejs','true');
			so.addVariable('javascriptid',swfId);
			so.write(mediaPlayerId);
			mediaPlayerObj = jQuery('#'+mediaPlayerId);
			swfObj=jQuery('#'+swfId);
			swfObj.height(0);
			//applyMediaActions(audioStartExpr+","+videoStartExpr,audioStopExpr+","+videoStopExpr);

			jQuery('.closebtn',previewObj).click(function(){
				mediaStop(jQuery(audioStopExpr+","+videoStopExpr));
				previewObj.hide();
				});
		
		
		
		jQuery('.catalog-Featured .catalog-item .thumbnail').hover(
			function() {
				showMediaPreview(this);
			},
			
			function() {
			//moved to mediaPreview
			}
		);
		
		
		jQuery('.mediaPreview').mouseout(function(e){
			if (!e) var e = window.event;
			var t= jQuery(e.target);
			var inPreview = t.parents('.mediaPreview').length>0 ;
			if (isPlaying==null && !inPreview ) {
				clearTimeout(focusCatalogItem);
				previewObj.hide();

			}
		});
		


	};
	
	jQuery(function(){
			if (jQuery(mediaPlayerExpression).length==0 ) {
			var previewer ='<div id="mediaPreview" class="mediaPreview" style="position:absolute; z-index:200;"><img class="closebtn" src="'+previewClosePath+'"/><div class="holder"></div></div>';
			body=jQuery("body").eq(0);
			body.append(previewer);

			previewObj = jQuery("#mediaPreview");
			previewObj.hide();

			body.append("<div id='" + mediaPlayerId + "' style='position: absolute; z-index:200; top:10px;left:10px; visibility: visible; height:0px; width:0px; overflow:hidden;'>Embed Code exists to prompt install of flash if not installed<embed src='" + mediaPlayerPath + "' width='1' height='1' /></div>");
			body.append("<div id='" + previewAnimId + "' style='position: absolute; z-index:200; top:-1000px;left:0px; visibility: visible;' width='0' height='0' ><img class='anim-large' src='" + previewAnimPathLarge + "' width='138px'/><img class='anim-small' src='" + previewAnimPathSmall + "'  width='44px'/></div>");
			previewAnimObj = jQuery('#'+previewAnimId);
			previewAnimImgLarge = previewAnimObj.find('.anim-large');
			previewAnimImgSmall = previewAnimObj.find('.anim-small');
			setTimeout('makePlayer();',1000);
		}
	});
	
		// toggle

		function toggleButton(jQueryElement) {
			// stop all
			jQuery(audioStartExpr + "," + videoStartExpr).css("visibility", "visible").css("display", "inline");
			jQuery(audioStopExpr + "," + videoStopExpr).css("visibility", "hidden").css("display", "none");

			// hide self
			jQueryElement.css("visibility", "hidden").css("display", "none");

			// show siblings
			jQueryElement.siblings("img").css("visibility", "visible").css("display", "inline");
		}



	// used to change values like.. itemsPerPage

	function loadUrl(value) {
		window.location = value;
	}

	function showMediaPreview(targetobj) {
		if (isPlaying==null) {
			clearTimeout(focusCatalogItem);
			var item = jQuery(targetobj).parents('.catalog-item');
			focusCatalogItem=setTimeout(
				function(){
					var offset = item.offset();
					previewObj.css("top",offset.top-20);
					previewObj.css("left",offset.left-20);
					var holder = previewObj.find('.holder');
					holder.html(item.html());
					//item.addClass('active');
					//applyMediaActions(audioStartExpr+","+videoStartExpr,audioStopExpr+","+videoStopExpr,previewObj);
					previewObj.fadeIn();

				},400);
		}
	}

	
	function mediaSetup(btn,type) {
		var holder = jQuery(btn).parents('.catalog-item,.mediaPreview,.item-row');
		if (holder.length>0) {
			var tn = holder.find('.thumbnail');
			//tn.parent().prepend(previewAnimObj);
			if (holder.is('.mediaPreview')) {
				
			} else {
			
			}
			var disp = null;
			if (type=='audio') {
				//disp=previewAnimObj;		
				var previewimg;
				if (tn.width()>=114) {
					previewimg=previewAnimImgLarge;
					previewAnimImgLarge.show();
					previewAnimImgSmall.hide();
				} else {
					previewimg=previewAnimImgSmall;
					previewAnimImgLarge.hide();
					previewAnimImgSmall.show();				
				}
				previewimg.show();
				previewAnimObj.height(tn.height());
				previewAnimObj.width(tn.width());
				previewimg.height(tn.height());
				previewimg.width(tn.width());
								
				previewAnimObj.css("top",tn.offset().top);
				previewAnimObj.css("left",tn.offset().left);
			} else if (type=='video') {
				swfObj.height(tn.height());
				swfObj.width(tn.width());
				mediaPlayerObj.height(tn.height());
				mediaPlayerObj.width(tn.width());
				mediaPlayerObj.css("top",tn.offset().top+1);
				mediaPlayerObj.css("left",tn.offset().left+1);
			}
			
		}
		
	}
	

	
	function mediaTeardown(btn,type) {
		var holder = jQuery(btn).parents('.catalog-item,.mediaPreview,.item-row');
		if (holder.length>0) {
			var tn = holder.find('.thumbnail');
			//tn.parent().prepend(previewAnimObj);
			if (holder.is('.mediaPreview')) {

			} else {

			}
			var disp = null;
			if (type=='audio') {
				//disp=previewAnimObj;		
				previewAnimObj.height(0);
				previewAnimObj.width(0);
				previewAnimObj.css("top",0);
				previewAnimObj.css("left",0);
				previewAnimImgLarge.hide();
				previewAnimImgSmall.hide();
				
			} else if (type=='video') {
				swfObj.height(0);
				swfObj.width(0);
				mediaPlayerObj.height(0);
				mediaPlayerObj.width(0);
				mediaPlayerObj.css("top",0);
				mediaPlayerObj.css("left",0);
			}

		}

	}


	function mediaPlay(obj,filename) {
		jqobj = jQuery(obj);
		if (isPlaying==null) {
			//todo fix CR for clicking play on page and preview window.
			if (jqobj.parents('.catalog-Featured').length>0 ) {
				//if a person clicks this play button, show the Preview window, then play 
				showMediaPreview(jqobj);

				//if (startbtn!=null) {
					setTimeout("var startbtn = previewObj.find('.audio-preview-start-button');startbtn.click();",500);
				//} else {
				//	alert('Cant find start button in preview window');
				//}
			} else {

				mediaPlayerObj.show();
				if (jqobj.is(audioStartExpr)) {
					mediaSetup(jqobj,'audio');
				} else if (jqobj.is(videoStartExpr)){
					mediaSetup(jqobj,'video');
				} else {
					//alert("error");
				}

				if (filename==null) var filename = jqobj.attr("title");
				loadFile(swfId, {file: filename});
				toggleButton(jqobj);
				setTimeout("sendEvent(swfId,'playpause');",100);
				isPlaying=obj;			
			}
		}
	
	}

	function mediaStop(obj) {
		if (obj==null && isPlaying!=null) obj=isPlaying;
		if (obj!=null) {
			jqobj = jQuery(obj);
			sendEvent(swfId,'stop');
			mediaPlayerObj.css("visibility","hidden");
			setTimeout('mediaPlayerObj.css("visibility","visible")',100);
			if (jqobj.is(audioStopExpr) || jqobj.is(audioStartExpr)) {
				mediaTeardown(jqobj,'audio');
			} else if (jqobj.is(videoStopExpr) || jqobj.is(videoStartExpr)){
				mediaTeardown(jqobj,'video');
			} else {
				//alert("error");
			}

			toggleButton(jqobj);
		}
		isPlaying=null;

	}
	
	function changeImage(curElem,img)
	{
		curElem.src=img;
	}
	
	function changeStyle(curElem,style)
	{
	        curElem.className=style;
        }
	
	
	/*Banner Java script*/
	
	function BannerChanger(listid, autorun, addPaginateText, customNextText){
		var list=document.getElementById(listid)
		if (typeof addPaginateText!="undefined" && addPaginateText!="") //Do we want to add pagination to it - Y to add pagination
			list.paginateText=addPaginateText
		if (typeof customNextText!="undefined" && customNextText!="") //Custom HTML for "Next" link defined?
			list.nextText=customNextText
	
		bannernodes[listid]=[] //Array to store references to this banner lists' DIV containers (<div class="bannerdiv">)
	
		var alldivs=list.getElementsByTagName("div")
		for (var i=0; i<alldivs.length; i++){
			if (alldivs[i].className=="opacitylayer")
				list.opacitylayer=alldivs[i]
			else if (alldivs[i].className=="bannerdiv"){
				bannernodes[listid].push(alldivs[i]) //add this DIV reference to array			
			}
		}
		
		BannerChanger.buildpagination(listid)
		
		var loadfirstcontent=true
		if (enablepersist && getCookie(listid)!=""){ //if enablepersist is true and cookie contains corresponding value for list
			var cookieval=getCookie(listid).split(":") //process cookie value ([listid, int_pagenumber (div content to jump to)]
			
			if (document.getElementById(cookieval[0])!=null && typeof bannernodes[listid][cookieval[1]]!="undefined"){ //check cookie value for validity
				BannerChanger.turnpage(cookieval[0], parseInt(cookieval[1])) //restore content list's last shown DIV
				loadfirstcontent=false
			}
		}
		
		if (loadfirstcontent==true) //if enablepersist is false, or cookie value doesn't contain valid value for some reason (ie: user modified the structure of the HTML)
			BannerChanger.turnpage(listid, 0) //Display first DIV within list
			
		if (typeof autorun=="number" && autorun>0) //if autorun parameter (int_miliseconds) is defined, fire auto run sequence
			window[listid+"timer"]=setTimeout(function(){BannerChanger.autoturnpage(listid, autorun)}, autorun)
	}
	
	BannerChanger.buildpagination=function(listid){
		var list=document.getElementById(listid)
		var paginatediv=document.getElementById("paginate-"+listid) //reference corresponding pagination DIV for list
		var pcontent=""
		pcontent+='<a href="#" onClick=\"BannerChanger.turnpage(\''+listid+'\', parseInt(this.getAttribute(\'prev\'))); return false\">'+( "<img src='/bxss-portal/media/carousel_left.gif' onmouseover=\"changeImage(this,\'/bxss-portal/media/UMGHome_Carousel_RedArrowLeft.gif\')\" onmouseout=\"changeImage(this,\'/bxss-portal/media/carousel_left.gif\')\" border='0'/>")+'</a> '
		
		if (list.paginateText) {
			for (var i=0; i<bannernodes[listid].length; i++) //For each DIV within list, generate a pagination link
				pcontent+='<a href="#" style="display: none" onClick=\"BannerChanger.turnpage(\''+listid+'\', '+i+'); return false\">'+(i+1)+'</a> '
		
		}
		pcontent+='<a href="#" onClick=\"BannerChanger.turnpage(\''+listid+'\', parseInt(this.getAttribute(\'next\'))); return false\">'+( "<img src='/bxss-portal/media/carousel_right.gif' onmouseover=\"changeImage(this,\'/bxss-portal/media/UMGHome_Carousel_RedArrowRight.gif\')\" onmouseout=\"changeImage(this,\'/bxss-portal/media/carousel_right.gif\')\" border='0'/>")+'</a> '
		
		paginatediv.innerHTML=pcontent
		paginatediv.onclick=function(){ //cancel auto run sequence (if defined) when user clicks on pagination DIV
		if (typeof window[listid+"timer"]!="undefined")
			clearTimeout(window[listid+"timer"])
		}
	}
	
	
	BannerChanger.turnpage=function(listid, thepage){
		var paginatelinks=document.getElementById("paginate-"+listid).getElementsByTagName("a") //gather pagination links
		for (var i=0; i<bannernodes[listid].length; i++){ //For each DIV within list
			paginatelinks[i].className="" //empty corresponding pagination link's class name
			bannernodes[listid][i].style.display="none" //hide DIV
		}
		paginatelinks[thepage].className="selected" //for selected DIV, set corresponding pagination link's class name
		if (enablefading){
			if (window[listid+"fadetimer"])
				clearTimeout(window[listid+"fadetimer"])
			this.setopacity(listid, 0.1)
		}
		bannernodes[listid][thepage].style.display="block" //show selected DIV
		if (enablefading)
			this.fadeup(listid, thepage)
		//Set "Next" pagination link's (last link within pagination DIV) "rel" attribute to the next DIV number to show
		var thenextpage=(thepage<paginatelinks.length-3)? thepage+1 : 0
		var theprevpage=(thepage>0)? thepage-1 : paginatelinks.length-3
		//alert(thepage + " - " + thenextpage + " - " + theprevpage);
		paginatelinks[paginatelinks.length-1].setAttribute("next",thenextpage )
		paginatelinks[0].setAttribute("prev", theprevpage)
		if (enablepersist)
			setCookie(listid, listid+":"+thepage)
	}
	
	
	BannerChanger.autoturnpage=function(listid, autorunperiod){
		var paginatelinks=document.getElementById("paginate-"+listid).getElementsByTagName("a") //Get pagination links
		var nextpagenumber=parseInt(paginatelinks[paginatelinks.length-1].getAttribute("next")) //Get page number of next DIV to show
		BannerChanger.turnpage(listid, nextpagenumber) //Show that DIV
		window[listid+"timer"]=setTimeout(function(){BannerChanger.autoturnpage(listid, autorunperiod)}, autorunperiod)
	}
	
	BannerChanger.setopacity=function(listid, value){ //Sets the opacity of targetobject based on the passed in value setting (0 to 1 and in between)
		var targetobject=document.getElementById(listid).opacitylayer || null //reference list container itself
		if (targetobject && targetobject.filters && targetobject.filters[0]){ //IE syntax
			if (typeof targetobject.filters[0].opacity=="number") //IE6
				targetobject.filters[0].opacity=value*100
			else //IE 5.5
				targetobject.style.filter="alpha(opacity="+value*100+")"
			}
		else if (targetobject && typeof targetobject.style.MozOpacity!="undefined") //Old Mozilla syntax
			targetobject.style.MozOpacity=value
		else if (targetobject && typeof targetobject.style.opacity!="undefined") //Standard opacity syntax
			targetobject.style.opacity=value
		targetobject.currentopacity=value
	}
	
	BannerChanger.fadeup=function(listid){
		var targetobject=document.getElementById(listid).opacitylayer || null //reference list container itself
		if (targetobject && targetobject.currentopacity<1){
			this.setopacity(listid, targetobject.currentopacity+0.1)
			window[listid+"fadetimer"]=setTimeout(function(){BannerChanger.fadeup(listid)}, 100)
		}
	}
	
	function getCookie(Name){
		var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
		if (document.cookie.match(re)) //if cookie found
			return document.cookie.match(re)[0].split("=")[1] //return its value
		return ""
	}
	
	function setCookie(name, value){
		document.cookie = name+"="+value
	}
