// Global variables

refreshOnFocus = false;


// Load in JS CSS file
new Asset.css('/assets/style/hasJS.css');

// Extend Element for universal 'safe' click event
Element.extend({
	addClick: function(fn){				
			this.onclick=function(){
				return false;
			}
			this.addEvent("click",fn);
	}
});

Custom = {
		showClass:'show',
		hideClass:'hide',
		convertArrayOfClassesToCss:function(arry){
			ret='';
			arry.each(function(e,index){
				ret=index<arry.length-1 ? ret+'.'+e+',' : ret+'.'+e;
			});
			return ret;
		},
		setupAll:function(){		
		    window.addEvent('domready', Custom.doLayers);				
			window.addEvent('domready',Custom.setupDom);
			window.addEvent('load',Custom.setupLoad);
			toggleButton='enabled'
		},
		setupDom: function(){
			Custom.pngFix();
			currentDiscView="";
			Custom.winPopsInitialize();
			// fix for IE loading issues
			if($('browseGames')){
				if(Custom.getStringQueries(document.location.href).disc){
					disc=Custom.getStringQueries(document.location.href).disc;
					firstTime="no";
				}else{
				// default to pop
					disc=DEFAULT_DISC_ID;
				}
				//XML_Disc='/upload/xml/disc/structure.xml';
				currentDiscView=disc;
				Custom.Views.checkView();
				Custom.Grid.initialize();
			}
			if($('languageSelector')){
				Custom.Rollovers.initialize('#selectLanguage ul li a');
			}
			if($('competitionPanel')){
				Custom.Quiz.initialize();
			}
			if($('home')){
			    //XML_Home='/upload/xml/home/structure.xml';
				if(Custom.gotFlash(9)){
				if(refreshOnFocus==true){   
				    homeLoad = function(){
						Custom.Flash.load('/assets/flash/home/CarouselApp' + (!_ph2 ? '_old' : '') + '.swf','carousel','980','510','?xml_url='+XML_Home+'&image_path=/assets/flash/home/images');
						window.removeEvents('focus');
					}
					window.addEvent('blur',function(){
						//$('carousel').empty();
						window.addEvent('focus',homeLoad);
					})
					homeLoad();
				}else{
					Custom.Flash.load('/assets/flash/home/CarouselApp' + (!_ph2 ? '_old' : '') + '.swf','carousel','980','510','?xml_url='+XML_Home+'&image_path=/assets/flash/home/images');
				}
				
				}
				
			}
			
			if($('whatIsBuzz')&&$$('.heroPanel')[0]){
				//Additions for new What is Buzz page
				$$('.heroPanel')[0].removeClass("hide");
				//Custom.Flash.load('/assets/flash/home/CarouselApp.swf','carousel','980','510','?xml_url='+XML_Home+'&image_path=/assets/flash/home/assets&menu=false'); // final xml=XML_Home
			}
			if($('browseQuizPacks')) {
				Custom.Quizpacks.init();
			}
		},
		setupLoad: function(){
			Custom.pngFix();
			if ($('whatIsBuzz') && $$('.heroPanel')[0] && _ph2) { 
			// Inline script on WhatIsBuzz.aspx adds hidden class to whyBuzz element to allow content to load (IE6 fix) - this checks if it has happened and takes it off if so
				var removeHidden = function(panelCont){
					Custom.Carosel.initializeBasicPanels();
					panelCont.removeClass('hidden');
				}
				var panelContainer = $('whyBuzz');
				if (panelContainer !== null && panelContainer.className.indexOf('hidden') !== -1) {
					removeHidden(panelContainer);
				}
				else {
					window.setTimeout('function(){' + removeHidden(panelContainer) + '}', 1000);
				}
			}
		},
		gotFlash: function(minVersion) {
			//detect if the user has at least the minimum version of Flash using SWFObject
			//default to version 8 if no version is specified
			minVersion=$pick(minVersion,9);
			var instFlashVersion = deconcept.SWFObjectUtil.getPlayerVersion(minVersion,false);
			if(instFlashVersion.major>=minVersion){
				return true;
			}
			return false;
		},	
		getStringQueries: function(theString) {
			if(theString.indexOf('?')>-1) {
				theString = theString.split('?')[1];
			}
			var qs = theString, qsKey, qsValue, stringElements = {};
			qs = qs.split("&");
			for (var i = qs.length-1; i>=0; i--) {
				qsKey = qs[i].split("=")[0];
				qsValue = qs[i].split("=")[1];
				stringElements[qsKey] = qsValue;
			}
			return stringElements;
		},
		getQuery : function(theHref) {
			if(theHref.indexOf('?') > -1) {
				return theHref.split('?')[1];
			} else return false;
		},
		pngFix: function(el){
		// PNG fix for ie6 based on mootools - Dom Hoare

			if(window.ie6){
			$ES("img",(el||'')).each(function(e){
				if(e.src.indexOf('.png')>=0&&!e.hasClass("pngIgnore")&&!e.getParent().hasClass('pngSpan')){
					te = new Element('span');
					str='progid:DXImageTransform.Microsoft.AlphaImageLoader(src="'+e.src+'", sizingMethod="scale")';
					//str='progid:DXImageTransform.Microsoft.AlphaImageLoader(src="'+e.src+'")';
					// copy the following properties over to png fix span - style follows (inherited classes cannot be carried over!)
					['id','class'].each(function(s){
						te.setProperty(s,e.getProperty(s));
					})
					e.id="";
					te.addClass('pngSpan');
					te.setStyles({'display':'none','filter':str,'background':'none','width':e.getStyle('width'),'height':e.getStyle('height')});
					te.injectAfter(e);
					e.setStyle("display","none");
					te.adopt(e);
					te.setStyle("display","inline-block");
				}
			})
			}
		},
		winPopsInitialize: function(){
			document.getElementsBySelector('.popupSmall,.popupMedium,.popupLarge,.popupExtraLarge').each(function(el){
				w=h=0;
				if(el.hasClass('popupSmall')){el.w=150;el.h=150;}
				if(el.hasClass('popupMedium')){el.w=500;el.h=500;}
				if(el.hasClass('popupLarge')){el.w=950;el.h=750;}
				if(el.hasClass('popupExtraLarge')){el.w=1050;el.h=795;}
				el.addClick(Custom.winPopsOpen);
			});
		},
		winPopsOpen: function(ev){
			url=this.href;
			w=this.w;
			h=this.h;
			if(typeof(winPop)!='undefined'){
				winPop.close();
			}
			winPop = window.open(url,'Sony_Buzz','width='+w+',height='+h+',resizable=no,status=no,menubar=no,toolbar=no,address=no')					
		},
		/*
	Function: doLayers
		set up and handle the layers that appear over the main page and a semi-transparent layer
*/
	doLayers: function(){
		var layerLinks=$$('a.layerOpen');
		var layers=$$('.layer');
		var layersClose=$$('a.layerFinish');

		layers.each(function(layer){
			layer.injectTop(document.getElementsByTagName('form')[0]);

			layer.setStyles({
				'position':'absolute',
				'zIndex':'1000000',
				'left':'0',
				'top':'-10000px'
			});

			if(layer.hasClass('openOnLoad')){
				var lLeft=window.getWidth()/2 - layer.getCoordinates().width/2 - layer.getLeft();
				if(lLeft<0){lLeft=0;}
				var lTop=window.getHeight()/2 - layer.getCoordinates().height/2;
				if(lTop<0){lTop=0;}
				layer.setStyles({
					'left':lLeft,
					'top':lTop
				});
				window.scrollTo(0,0);
				Custom.tintWindow();
				$$('.filterChannels').addClass('noshow'); 
			}
			else{layer.addClass('noshow');}

			//title bar and close link		
			var closeLink=document.getElementById('closeX');
			layersClose.push(closeLink);
					
			
			/*
			var layerTitle=layer.getElement('.head');
			if(!$chk(layerTitle)){
				layerTitle=new Element("div");
				layerTitle.className="head";
				layerTitle.injectBefore(layer.getElement('.innerCont'));
			}
			var closeImg=new Element('img');
				closeImg.src='/assets/img/buttons/popup_X.gif';
				closeImg.alt='X';
			var closeLink=new Element('a');
				closeLink.href='#';
				closeLink.addClass('closeX');
			layersClose.push(closeLink);
			closeImg.injectInside(closeLink);
			closeLink.injectTop(layerTitle);
			if(layer.getElement('input[type=reset]')){
				var reset=layer.getElement('input[type=reset]');
				var cancelLink=new Element('a');
					cancelLink.href='#';
					cancelLink.appendText(reset.value);
					cancelLink.addClass('cancel');
					layersClose.push(cancelLink);
					reset.replaceWith(cancelLink);
			}*/
			
			
		});
		layersClose.each(function(layerFin){
			layerFin.onclick=function(){
				var windowTint=$E('div.tintedWindow');
				var tabClose = $('closeX');
			//	if(tabClose) {tabClose.parentNode.removeChild(tabClose);}
				if(windowTint){windowTint.parentNode.removeChild(windowTint);}
				layers.each(function(layer){layer.addClass('noshow');});
				tabClose.addClass('noshow');	
				 $$('.filterChannels').removeClass('noshow'); 
				
				
				return false;
			}
		});
		//set up links opening layers
		layerLinks.each(function(layerLink){
			layerLink.onclick=function(){
				var windowTint=$E('div.tintedWindow');
				if(windowTint){windowTint.parentNode.removeChild(windowTint);}
				layers.each(function(layer){
					if(!layer.hasClass('noshow')){layer.addClass('noshow');}
				});
				var layerToOpen=layerLink.href.substring(layerLink.href.lastIndexOf("#")+1);
				$(layerToOpen).toggleClass('noshow');
				$(layerToOpen).setStyle('left',0);
				var lLeft=window.getWidth()/2 - $(layerToOpen).getCoordinates().width/2 - $(layerToOpen).getLeft();
				if(lLeft<0){lLeft=0;}
				var lTop=window.getHeight()/2 - $(layerToOpen).getCoordinates().height/2  + window.getScrollTop();
				if(lTop<0){lTop=0;}
				$(layerToOpen).setStyles({
					'left':lLeft,
					'top':lTop
				});
				Custom.tintWindow();
				return false;
			}
		});
	},
	
	/*
	Function: tintWindow
		creates a semi-transparent div that sits between any pop-over layers and the main page, covers the whole page
	Returns:
		injects the div just before the layer that is appearing on top so that their z-indices relate to one another.
	*/
	tintWindow:function(){
		var windowTint=new Element('div');
		//get visible layer
		var layerDiv=$$('.layer').filter(function(layer){
			return !(layer.hasClass('noshow'));
		})[0];
		windowTint.className='tintedWindow';
		windowTint.setStyles({
			'opacity':0.7,
			'height':window.getScrollHeight(),
			'width':$('wrapper').getCoordinates().width
		});
		windowTint.injectBefore(layerDiv);
		
		
	}
	

}

Custom.Flash = {
		load: function(putThis,there,width,height,props) {
		    if($(there)){
				$(there).empty();
				objId=there+"_movie";
			    var so = new SWFObject(putThis, objId, width, height, 9, '#336699');
			    obj=Custom.getStringQueries(props)	
			    for (objprop in obj) {
				    so.addVariable(objprop,obj[objprop]);
			    }
			    so.addParam('wmode', 'transparent');
			    so.write(there);
				window[objId] = document.getElementById(objId); //externalinterface hack for IE
		    }
		},	
		loadVideo: function(divID,videoPath,loadOnInvoke) {
		    if($(divID)){
			    var so = new SWFObject('/assets/flash/video/buzz_videoplayer2.swf', divID, '551','310', 9, '#336699', false);	
			    so.addParam('wmode', 'transparent');
			    so.addVariable("video", videoPath);  
			    so.addVariable("skin", "/assets/flash/video/buzz_skin.swf");
				if($(divID).innerHTML!=""){
			    	$(divID).empty();
				}
				if (arguments.length < 3) { // added to allow invocation onload and when swapping videos in and out
				    window.addEvent('domready',function(){
						so.write($(divID));
					});
				} else {
					if(loadOnInvoke === true) { so.write($(divID)) };
				}
		    }
		},	
		loadVideoWhatIsBuzz: function(divID,videoPath) {
		    if($(divID)){
			    var so = new SWFObject('/assets/flash/video/buzz_videoplayer2.swf', divID, '397','223', 9, '#336699', false);	
			    so.addParam('wmode', 'transparent');
			    so.addVariable("video", videoPath);  
			    so.addVariable("skin", "/assets/flash/video/buzz_skin.swf");
				if($(divID).innerHTML!=""){
			    	$(divID).empty();
				}
					window.addEvent('domready', function(){
						so.write($(divID));
					});				
		    }
		},			
		loadVideoPacks: function(divID,xmlPath){
			if($(divID)){
			    var so = new SWFObject("/assets/flash/packs/swf/buzzpacks.swf", "BuzzPacks", '800', '215', '8', '#FFFFFF');
			    so.addParam("menu", false);
				so.addParam("wmode", "transparent"); 
	            so.addVariable("content_xml",xmlPath);
				
				if($(divID).innerHTML!=""){
			    	$(divID).empty();
				}
				    window.addEvent('domready', function(){
						so.write($(divID));
					});				
		    }
		},
		
		loadVideoQuiz: function(divID, xmlPath){
			if($(divID)){
			    var so = new SWFObject("/assets/flash/quiz/online.swf", "BuzzQuiz", '950', '562', '9.0.0', '#000000'); 
				so.addParam("flashVars", xmlPath);
			 			if($(divID).innerHTML!=""){
			    	$(divID).empty();
				}
				    window.addEvent('domready', function(){
						so.write($(divID));
					});				
		    }
		},
		
		loadSampleQuiz: function(divID, swfPath){
			if($(divID)){
			    var so = new SWFObject(swfPath, "BuzzSampleQuiz", '950', '562', '9.0.0', '#000000'); 
                if($(divID).innerHTML!=""){
                    $(divID).empty();
                }
			    window.addEvent('domready', function(){
					so.write($(divID));
				});				
		    }
		},
		
		loadVideoQuiz: function(divID, xmlPath){
			if($(divID)){
			    var so = new SWFObject("/assets/flash/quiz/online.swf", "BuzzQuiz", '950', '562', '9.0.0', '#000000'); 
				so.addParam("flashVars", xmlPath);
			 			if($(divID).innerHTML!=""){
			    	$(divID).empty();
				}
				    window.addEvent('domready', function(){
						so.write($(divID));
					});				
		    }
		},		
			
		switchView: function(){
		
		}
}
Custom.Carosel = {
		highlightedThumb			:0,
		screenThumbNumber			:4,
		sliderSpeed					:1500,
		sliderPause					:200,
		sliderDelay					:100,
		activeSlider				:false,
		activeThumb					:false,
		screenThumbUpButtonSelector	:'#upButton',
		screenThumbDownButtonSelector	:'#downButton',
		screenThumbHighlightClass	:'highlight_temp',
		screenThumbWinSelector		:'#thumbnails ul',
		screenThumbSelector			:'#thumbnails ul li a img',
		subNavQuery					:'tab',
		screenThumbImgQuery			:'img',
		screenBigSelector			:'#screenshotImage a img',
		subNavButtonSelector		:'#overviewNavigation li a',
		subNavAjax					: Ajax_DiscPage,
		subNavAjaxOutput			:'gameInfo',
		screenShotPanelID			:'tab1',
		subNavPagesSelector			:'.panel',
		
		initializeBasicPanels: function() {
		
		    //alert($$(Custom.Carosel.subNavPagesSelector).length);
		
			$$(Custom.Carosel.subNavPagesSelector).each(function(subnav){
				subnav.addClass(Custom.hideClass);
			});
			
			if ($('tab0'))
			    $('tab0').removeClass(Custom.hideClass);
			    
			$$(Custom.Carosel.subNavButtonSelector).addClick(function(event){
				Custom.Carosel.showBasicSubNavPage(event, this);
			});
		},		
		initializeSubNavPage: function() {
			$$(Custom.Carosel.subNavButtonSelector).addClick(function(event){Custom.Carosel.showSubNavPage(event,this)});
			Custom.pngFix($(Custom.Carosel.subNavAjaxOutput));
			//if($defined(Custom.Flash.flashID) && $defined(Custom.Flash.flashURL)) {
			//	Custom.Flash.loadVideo(Custom.Flash.flashID, Custom.Flash.flashURL)
			//}
		},
		showSubNavPage: function(event,el,page){
			event = new Event(event).stop();
			def=Custom.getStringQueries(el.href)[Custom.Carosel.subNavQuery];
			if($(def)){
				
				$$(Custom.Carosel.subNavButtonSelector).getParent().each(function(elem, idx){ // clear out the video in the last panel (unless it's the current panel)
					if(elem.hasClass('selected')) {
						var clickedIdx = parseInt(def[def.length-1]); // the numeric value at the end of the def string
						if (idx !== clickedIdx) {
							if (($(Custom.Carosel.subNavQuery + idx).getElementsByTagName('EMBED').length > 0) || ($(Custom.Carosel.subNavQuery + idx).getElementsByTagName('OBJECT').length > 0)) {
								$$('div#' + Custom.Flash.flashID)[0].empty();
							};
						};
					};
				});
				var videoContainer = $$("#"+def+" div#"+Custom.Flash.flashID); // if new panel is video one & empty, inject video
				//var heir = videoContainer[0].getChildren().length > 0;
				if(videoContainer.length >= 1/* && !heir*/) { 
					if($defined(Custom.Flash.flashID) && $defined(Custom.Flash.flashURL)) {
						Custom.Flash.loadVideo(Custom.Flash.flashID, Custom.Flash.flashURL, true)
					}
				}
				$$(Custom.Carosel.subNavButtonSelector).getParent().removeClass('selected');
				el.getParent().addClass('selected');
				$$(Custom.Carosel.subNavPagesSelector).addClass(Custom.hideClass);
				
				$(def).removeClass(Custom.hideClass);

				
				Custom.Carosel.initializeScreenThumbs();
			
			}
		},
		showBasicSubNavPage: function(event,el,page){
			var panelParent = $('firstPanel');
			if(panelParent.className.indexOf('hasJS') !== -1) {
				panelParent.removeClass('hasJS');
			}
			event = new Event(event).stop();
			def=Custom.getStringQueries(el.href)[Custom.Carosel.subNavQuery];
			if($(def)){
				$$(Custom.Carosel.subNavButtonSelector).getParent().removeClass('selected');
				el.getParent().addClass('selected');
				$$(Custom.Carosel.subNavPagesSelector).addClass(Custom.hideClass);
				var hider = Custom.hideClass; //IE doesn't like receiving this variable directly
				$(def).removeClass(hider);
			}
		},
		removeContent:function(){
		Custom.Grid.removeMooEls();	
		/*
			if($(Custom.Carosel.subNavAjaxOutput)){
				$(Custom.Carosel.subNavAjaxOutput).remove();
			}
			*/
		},
		getSubPage:function(url,event){
			//if (event != undefined) {
			//	event = new Event(event).stop();
			//	alert("hi")
			//}

			
			if(Custom.Carosel.activeSlider==true){return false;}
			Custom.Flash.loadVideo()
			Custom.Carosel.highlightedThumb=0;
			Custom.Carosel.removeContent();
			ne=new Element('div');
			ne.setProperty("id",Custom.Carosel.subNavAjaxOutput);
			ne.addClass(Custom.Carosel.subNavAjaxOutput);
			ne.injectAfter($('carousel'));
			Custom.Carosel.busy();
			$(Custom.Carosel.subNavAjaxOutput).empty();
			Custom.Carosel.activeSlider=true;
			currentDiscView=Custom.getStringQueries(url).disc;
			trimmedQuery='?'+(url.split('?'))[1];
			newPath=Custom.Carosel.subNavAjax+trimmedQuery;

			//$(Custom.Carosel.subNavAjaxOutput).setStyle("visibility","hidden");			
			Custom.Carosel.faderWindow = new Fx.Style($(Custom.Carosel.subNavAjaxOutput), 'opacity', {
				duration: 500,
				onComplete:function(){
					(function(){Custom.Carosel.activeSlider=false;}).delay(Custom.Carosel.sliderPause);
				}
			}).set(0);
			var rateVid = new Ajax(newPath, {
				method: 'get',				
				evalScripts: true,
				update:$(Custom.Carosel.subNavAjaxOutput),
				onFailure: function(){
					$$('.bigSpinner').each(function(e){e.remove()});
					Custom.Carosel.removeContent();
					Custom.Carosel.activeSlider=false
				},
				onStart: function(){

				},
				onComplete: function(){
					//Custom.Carosel.faderWindow = new Fx.Style($$("#"+Custom.Carosel.subNavAjaxOutput+" div h1")[0], 'opacity', {duration: 800}).set(0);

					/*
					Custom.Carosel.sliderWindow = new Fx.Slide($$("#"+Custom.Carosel.subNavAjaxOutput + " div")[0],{
						transition: Fx.Transitions.Quint.easeOut,
						duration:Custom.Carosel.sliderSpeed,
						onComplete: function(){
							(function(){Custom.Carosel.activeSlider=false;}).delay(Custom.Carosel.sliderPause);
							Custom.Carosel.initializeScreenThumbs();
							//Custom.Carosel.faderWindow.start(0,1);							
					}}).hide();
					
					$(Custom.Carosel.subNavAjaxOutput).setStyle("visibility","visible");
					
					(function(){Custom.Carosel.sliderWindow.slideIn()}).delay(Custom.Carosel.sliderDelay);
					*/
					$$('.bigSpinner').each(function(e){e.remove()});
					toggleButton='enabled';
					Custom.Carosel.faderWindow.start(0,1);	
					Custom.Carosel.initializeSubNavPage();					
				}
			}).request();
			return false;
		},
		initializeScreenThumbs:function(){
			if(!$(Custom.Carosel.screenShotPanelID)){return false;}
			if($('highlightEl')){$('highlightEl').remove();}
			if(!($(Custom.Carosel.screenShotPanelID).hasClass("hide"))&&$$(Custom.Carosel.screenThumbWinSelector+" li a")){
				downButtonEl=$$(Custom.Carosel.screenThumbDownButtonSelector)[0];
				upButtonEl=$$(Custom.Carosel.screenThumbUpButtonSelector)[0];
				Custom.Carosel.makeScreenButton(upButtonEl,1);
				Custom.Carosel.makeScreenButton(downButtonEl,-1);				
				Custom.Carosel.checkScreenButtons();	
				$$(Custom.Carosel.screenBigSelector)[0].addClick(function(event){
						Custom.Carosel.moveScreenHighlight(event,1)
				});
				$$(Custom.Carosel.screenThumbWinSelector+" li a").each(function(e,index){
					e.index=index;
					e.addClick(function(event){
						Custom.Carosel.moveScreenHighlight(event,this.index+2);	
					});
				})
				imgEl=$$(Custom.Carosel.screenThumbSelector)[Custom.Carosel.highlightedThumb];
				w=(imgEl.getStyle('width').toInt()||108)-10+"px";
				h=(imgEl.getStyle('height').toInt()||60)-10+"px";
				highlightEl=new Element('div');
				highlightEl.setProperty("id","highlightEl");
				highlightEl.setStyles({
					'position':'absolute',
					'border':'6px solid #d00',
					'background-color':'#000',
					'opacity':'0.5',
					'z-index':'10',			
					'height':h,
					'width':w
				});
				Custom.Carosel.thumbScroll = new Fx.Scroll($$(Custom.Carosel.screenThumbWinSelector)[0], {
					wait: false,
					duration: 800,
					transition: Fx.Transitions.Quad.easeInOut
				});
				
				highlightEl.injectBefore(imgEl);
				/// fixes for png ie floating img bug
				$$(Custom.Carosel.screenThumbWinSelector)[0].getParent().setStyle("position","relative");
				$$(Custom.Carosel.screenBigSelector)[0].setStyle("position","relative");
				$$(Custom.Carosel.screenThumbWinSelector)[0].setStyle("position","relative");
				///
				Custom.Carosel.thumbScroll.scrollTo(0,0);

				if($$(Custom.Carosel.screenThumbSelector)){	
					$$(Custom.Carosel.screenThumbSelector)[Custom.Carosel.highlightedThumb].addClass(Custom.Carosel.screenThumbHighlightClass);
				}
			}
		},
		moveScreenHighlight: function(event,i){
			if(Custom.Carosel.activeThumb==true){return false;}
			Custom.Carosel.activeThumb=true;
			if(i>1){
				Custom.Carosel.highlightedThumb=i-2;
				i=0;
			}

			thisWasInt=(Custom.Carosel.highlightedThumb/Custom.Carosel.screenThumbNumber).toInt()==Custom.Carosel.highlightedThumb/Custom.Carosel.screenThumbNumber;				
			t=Custom.Carosel.highlightedThumb+i;
			if(t<$$(Custom.Carosel.screenThumbSelector).length&&t>-1){
				oldHighlightEl = highlightEl;
				highlightEl = oldHighlightEl.clone();
				Custom.Carosel.highlightedThumb+=i;
				thisIsNewPage=(Custom.Carosel.highlightedThumb/Custom.Carosel.screenThumbNumber).toInt()==Custom.Carosel.highlightedThumb/Custom.Carosel.screenThumbNumber;
				thisIsOldPage=((Custom.Carosel.highlightedThumb+1)/Custom.Carosel.screenThumbNumber).toInt()==(Custom.Carosel.highlightedThumb+1)/Custom.Carosel.screenThumbNumber;
				callback = function(){
					el=$$(Custom.Carosel.screenThumbSelector)[Custom.Carosel.highlightedThumb];
					highlightEl.injectBefore(el);
					Custom.Carosel.changeImg(el.getParent());
					oldHighlightEl.remove();
					Custom.Carosel.activeThumb=false;				
				};
				if(thisIsNewPage&&i==1){
					Custom.Carosel.thumbScroll.toElement($$(Custom.Carosel.screenThumbSelector)[Custom.Carosel.highlightedThumb]).chain(callback);
				}else if(thisIsOldPage&&i==-1){
					Custom.Carosel.thumbScroll.toElement($$(Custom.Carosel.screenThumbSelector)[Custom.Carosel.highlightedThumb-3]).chain(callback);
				}else{
					callback();
				}
			}else{
				Custom.Carosel.activeThumb=false;						
			}
			Custom.Carosel.checkScreenButtons();
		},
		changeImg:function(e){
					//img=Custom.getStringQueries(e.href)[Custom.Carosel.screenThumbImgQuery]
					img=e.href;
					$$(Custom.Carosel.screenBigSelector)[0].src=img;		
		},
		checkScreenButtons:function(){
			downButtonEl.disable();
			upButtonEl.disable();	
			if(Custom.Carosel.highlightedThumb!=0&&$$(Custom.Carosel.screenThumbWinSelector+" li a")[1]){
				upButtonEl.enable(-1);
			}
			if(Custom.Carosel.highlightedThumb<$$(Custom.Carosel.screenThumbWinSelector+" li a").length-1&&$$(Custom.Carosel.screenThumbWinSelector+" li a")[1]){
				downButtonEl.enable(1);
			}
		},
		makeScreenButton:function(obj,inc){
				Object.extend(obj,{
					disable: function(){				
							this.removeEvents("click");
							this.setStyle("opacity","0.5");
					},
					enable: function(inc){
							this.removeEvents("click");	
							this.addClick(function(event){Custom.Carosel.moveScreenHighlight(event,inc)});
							this.setStyle("opacity","1");
					}
				});
		},
		busy:function(){
				busyEl=new Element('img');
				busyEl.setProperty('src','/assets/img/ProductHub_Flash.gif');
				busyEl.addClass("bigSpinner");
				busyEl.setStyles({
					'zoom':'1',
					'position':'absolute',
					'left':'475px'
				});
				
				busyEl.injectBefore($(Custom.Carosel.subNavAjaxOutput));
			}
}


Custom.Rollovers = {
		initialize: function(sel){
				$$(sel).each(function(el){
					next=el.getNext();
					if(el.getNext()){
						el.addEvent("mouseover",function(){
							Custom.Rollovers.nextDivRoll(this);
						});
						el.addEvent("mouseout",function(){
							(function(){Custom.Rollovers.nextDivRollOff(el)}).delay(1000);
						});	
						next.setStyle('visibility','visible');			
						next.addClass("hide");
						next.addClass("popUp");
						next.rolledOn=false;
						next.addEvent("mouseover",function(){
							this.rolledOn=true;
						});
						el.getNext().addEvent("mouseout",function(){
							this.rolledOn=false;
							(function(){Custom.Rollovers.nextDivRollOff(el)}).delay(1000);
						});
					}
				})
		},
		nextDivRoll: function(obj){
			$$('.popUp').addClass("hide");
			obj.getNext().removeClass("hide");
		},
		nextDivRollOff: function(obj){
			if(!obj.getNext().rolledOn){
				obj.getNext().rolledOn=false;
				obj.getNext().addClass("hide");
			}
		}
}


Custom.Quiz = {
		ready						:true,
		currentQ					: 0,
		qTemplateSel				:'#qTemplate',
		qSel						:'.question',
		buttonSel					:'.quizButton',
		questionUnitSel				:'ol li fieldset',
		quizWrapSelector			:'#competitionNoJS',
		initialize: function(){
			q=[];
			if($$(Custom.Quiz.quizWrapSelector).length>0&&!$ES(Custom.Quiz.questionUnitSel+" input",$$(Custom.Quiz.quizWrapSelector)[0])[0].getProperty('checked')){
				quizTemplate=$$(Custom.Quiz.qTemplateSel)[0];
				Custom.Quiz.qs = $ES(Custom.Quiz.questionUnitSel,$$(Custom.Quiz.quizWrapSelector)[0])
				$ES(".total",quizTemplate).setHTML(Custom.Quiz.qs.length);
				Custom.Quiz.qs.each(function(el,index){
						fullQ = quizTemplate.clone();
						fullQ.id="";
						$ES('label',el).each(function(e,i){
							newButton=fullQ.getElements(Custom.Quiz.buttonSel)[i]
							newButton.setHTML(e.getText());
							newButton.boundRadio=e.getNext();
							newButton.addClick(Custom.Quiz.nextQ)
						});
						$E(Custom.Quiz.qSel,fullQ).setHTML($E('legend',el).getText());
						fullQ.setStyle("position","absolute");
						fullQ.injectAfter($$(Custom.Quiz.quizWrapSelector)[0]);
						q[index] = new Fx.Style(fullQ, 'opacity', {duration: 1000}).set(0);
						$E(".count",fullQ).setHTML(index+1);	
						fullQ.removeClass("hide");
				})
				q[0].element.setStyle("position","static");
				q[0].start(0,1);
				$$(Custom.Quiz.quizWrapSelector)[0].addClass("hide");
				newForm = $('pageForm').addClass("hide");
			}
			
		},
		nextQ: function(){
			if(Custom.Quiz.ready){
				Custom.Quiz.ready=false;
				this.boundRadio.setProperty('checked','true');
				if(Custom.Quiz.currentQ<Custom.Quiz.qs.length-1){
					Custom.Quiz.currentQ++			
					q[Custom.Quiz.currentQ-1].start(1,0).chain(function(){
						q[Custom.Quiz.currentQ].start(0,1).chain(function(){
							Custom.Quiz.ready=true;
						});						
					});
				}else{
					q[Custom.Quiz.currentQ].start(1,0).chain(function(){
						newForm.removeClass("hide");
						newForm.injectAfter($$(Custom.Quiz.quizWrapSelector)[0]);
						finalForm = new Fx.Style($('pageForm'), 'opacity', {duration: 1000}).set(0);
						finalForm.start(0,1);	
					});
					//$E('.submitAll',$$(Custom.Quiz.quizWrapSelector)[0]).fireEvent("click");
					//$$('form')[0].submit();
					//Custom.Quiz.sendQuiz();
				}
			}
		},
		sendQuiz: function(){			
			thisUrl = document.location.href;
			conc=thisUrl.contains('?') ? "&" : "?";
			document.location=thisUrl + conc + $$(Custom.Quiz.quizWrapSelector)[0].toQueryString()
		}
}


Custom.Grid = {
			tabIdArr			:[],
			contentDivId			: 	'gameInfo',
			smallRows			: 	{
									selector		:'.smallRow',
									tabClasses		:['openLeft','openMiddle','openRight'],
									contClasses		:['leftOpen','middleOpen','rightOpen']
									},
			featureRows			: 	{
									selector:'.firstRow',
									tabClasses:['featureOpenLeft','featureOpenRight'],
									contClasses:['leftFeatureOpen','rightFeatureOpen']
									},									
			smallRowSel			:	'.smallRow',
			featureRowSel		:	'.firstRow',
			contentAjax			:	Ajax_DiscPage,  //Ajax_DiscPage
			initialize: function(){
				if(Custom.getStringQueries(unescape(location.search)).disc){
					var discFlag = Custom.getStringQueries(unescape(location.search)).disc;
				}
				$('toggleView').addClick(Custom.Views.toggleView);
				contSlider="";
				Custom.Grid.objArr=[this.smallRows,this.featureRows];
				Custom.Grid.objArr.each(function(obj){
					$$(obj.selector).each(function(e,i){
						e.getElements("ul li h2 a").each(function(ee,ii){
							ee.row=i;
							ee.col=ii;
							ee.tabClasses=obj.tabClasses;
							ee.contClasses=obj.contClasses;
							ee.parentRow=e;
							//ee.addClick(Custom.Grid.smallClick)
							ee.addClick(function(){
								Custom.Grid.smallClick(ee)
							})
							if (discFlag && discFlag == Custom.getStringQueries(ee.href).disc) {
								Custom.Grid.smallClick(ee)
							}
							Custom.Grid.tabIdArr[Custom.getStringQueries(ee.href).disc]=ee;
							Custom.Grid.injectImage('/assets/img/close_tab.gif',ee,'closeTab');
							ee.closeButton=busyEl;
							ee.closeButton.setStyle("cursor","pointer");
							ee.closeButton.addClass("hide");
							ee.closeButton.addClick(function(){
								Custom.Grid.removeMooEls();
								Custom.Grid.removeTabClasses();
								currentDiscView='';
								this.addClass("hide");
							})
						});
					});
				});
			},
			smallClick:function(trigger){
					//obj = this;						
					obj = trigger;
					col=obj.col;
					row=obj.row;
					rowEl=obj.parentRow;
					currentDiscView=Custom.getStringQueries(obj.href).disc;
					//Custom.Grid.tabIdArr[currentDiscView]=obj;	
					Custom.Grid.removeTabClasses();
					rowEl.addClass(obj.tabClasses[col]);
					trimmedQuery='?'+(obj.href.split('?'))[1]+'&epslanguage=' + CurrentLocale;
					cPath=Custom.Grid.contentAjax+trimmedQuery;
					Custom.Grid.busy(obj);
					callback=function(){
						Custom.Grid.ready(obj);
						Custom.Grid.busy(obj);
						Custom.Grid.removeMooEls();			
						var rateVid = new Ajax(cPath, {
							method: 'get',
							evalScripts: true,
							onFailure:function(){
								Custom.Grid.removeTabClasses();
								Custom.Grid.ready(obj);
							},
							onSuccess: function(){
									ne=new Element('div');
									ne.setProperty("id",Custom.Grid.contentDivId);
									ne.addClass(Custom.Grid.contentDivId);
									ne.addClass(obj.contClasses[col]);
									ne.setHTML(this.response.text)
									ne.injectAfter(rowEl);
									contSlider=new Fx.Slide(ne,{
										transition: Fx.Transitions.Quint.easeOut,
										duration:Custom.Carosel.sliderSpeed,
										onStart:function(){
											ne.getParent().setStyle("position","relative");
											Custom.pngFix(ne);
											$('outer').setStyle('height','3000px');
											/*
											var scroll = new Fx.Scroll(window, {
												wait: false,
												duration: 2500,
												transition: Fx.Transitions.Quad.easeInOut
											}).scrollTo(0,rowEl.getPosition().y-20);
											
											
											
											window.scrollTo(0,rowEl.getPosition().y-20);
											*/
										},
										onComplete: function(){	
											//fadeNe.start(0,1);
											ne.getParent().setStyle("position","");
											ne.getParent().setStyle("height","");
											Custom.Carosel.initializeSubNavPage();
											$('outer').setStyle('height','');
											//Custom.Flash.loadVideo(Custom.Flash.flashID, Custom.Flash.flashURL);
											Custom.Grid.ready(obj);
											
										}
									}).hide();
									contSlider.slideIn();
									
							}
						}).request();
					}		
					if($(Custom.Grid.contentDivId)){
						if(contSlider){
							if($('video')){
								$('video').remove();
							}
							contSlider.slideOut().chain(callback)
						}else{
							Custom.Grid.removeMooEls();
							callback();
						}					
					}else{
						callback();
					}		
					
			},
			removeTabClasses: function(){
				Custom.Grid.objArr.each(function(type){
					$$(type.selector).each(function(row){
						type.tabClasses.each(function(classStr){
							row.removeClass(classStr);
						});
					});
				});
			},
			injectIn:function(here){
				/*	
				oldEl = $(Custom.Grid.contentDivId);			
				newEl = $(Custom.Grid.contentDivId);	
				if (newEl) newEl.clone();
				if (oldEl) oldEl.remove();
				*/
				if(here=='tab'){
					if(Custom.Grid.tabIdArr.length>0){
						Custom.Grid.tabIdArr[currentDiscView].fireEvent('click');
						//newEl.injectAfter(Custom.Grid.tabIdArr[currentDiscView].parentRow);
					}
				}else{
					//if (newEl) newEl.injectAfter($('carousel'));
					
					Custom.Flash.load('/assets/flash/products/CarouselApp' + (!_ph2 ? '_old' : '') + '.swf','carousel','970','410','?xml_url='+XML_Disc+'&image_path=/assets/flash/products/images/&default='+currentDiscView);
				}	
			},
			busy:function(thisEl){
				if($$('.closeTab')){
					$$('.closeTab').addClass("hide");
				}			
				Custom.Grid.injectImage('/assets/img/ProductHub_Grid.gif',thisEl,'smallSpinner');
			},
			ready:function(thisEl){
				if($$('.smallSpinner')[0]){
					$$('.smallSpinner')[0].remove();
					if(thisEl.closeButton){
						thisEl.closeButton.removeClass("hide");
					}	
				}
				
			},
			removeMooEls:function(){
					$$('.'+Custom.Grid.contentDivId).each(function(el){		
						if(el.getParent().id==''){
							el.getParent().addClass("oldMOO");
							//el.getParent().remove();
						}else{
							//el.remove();
							el.addClass("oldMOO");
						}
						
					});
					
					$$(".oldMOO").each(function(el){
						if($('video')){
								$('video').remove();
						}
						el.remove();
					});
			},
			injectImage: function(url,thisEl,imgClass){
				busyEl=new Element('img');
				busyEl.setProperty('src',url);
				busyEl.addClass(imgClass);
				if(thisEl.col==0){
					tabClass="tabSmallLSPos";
				}else if(thisEl.col==1){
					tabClass="tabSmallMSPos";
				}else if(thisEl.col==2){
					tabClass="tabSmallRSPos";
				}
				if(thisEl.parentRow==$$(Custom.Grid.featureRows.selector)[0]){
					tabClass="tabLargeLSPos";
					if(thisEl.col==1){
						tabClass="tabLargeRSPos";
					}
				}
				busyEl.setStyles({
					'height':'22px',
					'width':'21px',
					'left':'0',
					'top':'0'
				});
				busyEl.addClass(tabClass);
				busyEl.injectTop(thisEl.getParent().getParent());
			}
}

Custom.Views = {						
			carouselID			:	'carousel',
			gridID				:	'contentGrid',
			contentAjax			:	Ajax_DiscPage,  //Ajax_DiscPage
			checkView:function(){
					which = Cookie.get('view')
					if(!which){
						which=Custom.Views.carouselID;
					}
					if(!Custom.gotFlash(9)){
						$('toggleView').setStyle("visibility","hidden");
						Custom.Views.setView('grid');
					}else{
						$('toggleView').setStyle("visibility","visible");
						Custom.Views.setView(which);
					}		
			},
			toggleView:function(){
						Custom.Grid.removeMooEls();
						if(view!=Custom.Views.carouselID){
							Custom.Views.setView("carousel");
						}else{
							Custom.Views.setView("grid");
						}
			},
			setView:function(which){
						if(which=='carousel'){
							view=Custom.Views.carouselID
							other=Custom.Views.gridID
							call='';
							
						}else{
							view=Custom.Views.gridID
							other=Custom.Views.carouselID
							call='tab';
						}
						$(view).removeClass("hide");
						$(view).setStyle('visibility','visible');
						$(other).addClass("hide");
						Custom.Grid.injectIn(call);
						Custom.Carosel.initializeSubNavPage();
						Custom.Carosel.initializeScreenThumbs();
						Cookie.set('view', view)
			}
}
Custom.Quizpacks = {
	
	/* On clicking on any quizpack element, a 'boxout' will appear below it. This is filled with content sourced by Ajax.
	 * If no JS, the default link's url will take it to the content.
	 */

	packQueryKey			:	'pack',
	currentPack 			: 	null,
	clickedPackLink			:	null,
	packCancelled			:	null,
	channelContainerClass	:	'.channelsContent',
	channelClass			:	'.channels',
	channelsIntroClass      :   '.channelsIntro',
	
	isBoxoutOpen			:	false,	
	boxoutCancelled			:	false,
	errorMessage			:	"<p style='padding:20px;'>Server not reponding</p>",
	
	init : function() {
		Custom.Quizpacks.defaultPack = ''; // DEFAULT_QUIZPACK_ID;
		Custom.Quizpacks.ajaxURL = Ajax_QuizpackPage;
		
	
		
		Custom.Quizpacks.defaultOverlay = Ajax_Overlay;
		Custom.Quizpacks.overlayURL = 'overlay='+ Ajax_Overlay_ID + '&epslanguage=' + CurrentLocale;;
		
	   
		if(Custom.Quizpacks.defaultPack !== '') {
			var links = document.getElementsByTagName('a');
			var defaultLink;
			$$(links).each(function(link) {
				if(link.href.indexOf(Custom.Quizpacks.packQueryKey + '=' + Custom.Quizpacks.defaultPack) > -1) {
					defaultLink  = link;
				};
			})
			if(defaultLink) { 
				Custom.Quizpacks.clickedPackLink = defaultLink;
				Custom.Quizpacks.currentPack = defaultLink.getParent().getParent();
				Custom.Quizpacks.packTabOn();
			    Custom.Quizpacks.showBoxout(); 
			}
			
		}
		
		//Custom.Flash.loadVideoPacks('video', '/assets/flash/packs/xml/data.xml');
		this.setUpPacks();
		this.setUpOverlay();
		// check the defaultPack and if it's not null, run showBoxOut with it's value as the packQuery
		// get all packs onscreen and assign onclicks to them: addClick(the a, showBoxOut(packQuery))
	},
	setUpOverlay : function(){
		var openOverlay = $$(this.channelsIntroClass + ' li a');
	     	
			for(i=0;i<openOverlay.length;i++){
				
			if(openOverlay[i].hasClass('openOverlay') == true){
				
				openOverlay[i].addClick(function(){	
				
					if (!$('overlay')) {
						var overlayPath = Custom.Quizpacks.defaultOverlay + '?' + Custom.Quizpacks.overlayURL;
				       Custom.Quizpacks.overlayAjax = new Ajax(overlayPath, {
							method: 'get',
							evalscripts: true,
							onRequest: function(){
								//Custom.Quizpacks.requestSuccess = false;
								//Custom.Quizpacks.ajaxTest = window.setTimeout("Custom.Quizpacks.errorMessageDisplay()", 20000);
							}, 
							onFailure: function(){
								alert(overlayPath);
							},
							onSuccess: function(){
								var newOverlay = new Element('div');
								var newPosition = document.getElementById('outer');
								//var newWapper = new Element('div');
								//    newWapper.id = 'overlayWapper';
								
								newOverlay.setHTML(this.response.text);								
								newOverlay.injectBefore(newPosition);
								
								var newClose = new Element('div');
								    newClose.className = 'closeOverlay';
								var layerPos=document.getElementById('overlay');
								var closeLink=new Element('a');
									closeLink.href='#';
									closeLink.id = 'closeX';
								var closeImg=new Element('img');
									closeImg.src='/assets/img/close_tab_overlay.gif';
									closeImg.alt='X';
				                					            
								closeImg.injectInside(closeLink);
								closeLink.injectInside(newClose);
								newClose.injectBefore(layerPos);
																
								Custom.pngFix(newOverlay);
								Custom.doLayers();
							},
							onComplete: function(){
								
							}
						}).request();												
						
					} else {					
							$('overlayWrapper').removeClass('noshow');		
							$('closeX').removeClass('noshow');	
						    $$('.filterChannels').addClass('noshow'); 					
							Custom.tintWindow();				
					}
	
			});	
		
		}
		}
		
	},
	
	setUpPacks : function() {		
		var quizpacks = $$(this.channelContainerClass + ' ' + this.channelClass + ' a');
		var packTitleLinks = $$(this.channelContainerClass + ' li h3 a');
		quizpacks.each(function(quizpack) { 
			quizpack.addClick(function(){
				Custom.Quizpacks.onPackClick(quizpack);
			});
		});
		packTitleLinks.each(function(packTitleLink) { 
			packTitleLink.addClick(function(){
				Custom.Quizpacks.onPackClick(packTitleLink);
			});
		});				
	},
	onPackClick : function(clickedPackLink) {

		if(Custom.Quizpacks.clickedPackLink !== null) {
			Custom.Quizpacks.lastPackLink = Custom.Quizpacks.clickedPackLink;
		}
		Custom.Quizpacks.clickedPackLink = clickedPackLink;
		Custom.Quizpacks.currentPack = clickedPackLink.getParent().getParent();
		
		Custom.Quizpacks.currentPack.getParent().getChildren().each(function(elem,idx) { // getting the index of the clicked li
			if (elem === Custom.Quizpacks.currentPack) { 
				Custom.Quizpacks.currentPackIdx = idx;
			}
		});
		
		if ($('quizpackBoxout')) {							// if there is a boxout
			if (Custom.Quizpacks.boxoutSlider) {
				Custom.Quizpacks.boxoutSlider.stop();	
		
				if (Custom.Quizpacks.cancelled !== true) {
					Custom.Quizpacks.packTabOff()					
				};
				
				Custom.Quizpacks.cancelled = false;
				Custom.Quizpacks.packTabOn();
				Custom.Quizpacks.boxoutSlider.slideOut().chain(Custom.Quizpacks.showBoxout);		// when done: show the currentPack (that which was clicked)
				
			} else {
				Custom.Quizpacks.showBoxout();
			}
		}
		else {
			Custom.Quizpacks.packTabOn();
			Custom.Quizpacks.showBoxout();					// if no boxout, show the one clicked
		}
	},
	onCancelClick : function() {
		Custom.Quizpacks.cancelled = true;
		Custom.Quizpacks.boxoutSlider.stop();
		Custom.Quizpacks.boxoutSlider.slideOut()			// slide the boxout out of view
		.chain(function(){
			Custom.Quizpacks.packTabOff();
			Custom.Quizpacks.clickedPackLink = null;
			Custom.Quizpacks.currentPack = null;
			Custom.Quizpacks.lastPackLink = null;
		});
	},
	packTabOff : function() {
		var cancelButton = $$('.tabPos')[0];
		var parentListItem = cancelButton.getParent();
		var packChannel = parentListItem.getElementsByTagName('div')[0];
		var listItemBacking = 'channelOpen';
		$$('.tabPos')[0].remove();
		parentListItem.removeClass(listItemBacking);
	},
	packTabOn : function() {
		var parentListItem = Custom.Quizpacks.clickedPackLink.getParent().getParent();
		var packHeader = parentListItem.getElementsByTagName('h3');
		var packChannel = parentListItem.getElementsByTagName('div')[0];
		var listItemBacking = 'channelOpen';
		this.createSpinner().injectAfter(packChannel);
		parentListItem.addClass(listItemBacking);
	},
	showBoxout : function() {	
		var existingBoxout = $('quizpackBoxout');
		if(existingBoxout !== null)	{
			existingBoxout.getParent().remove();
		}
		var packQuery = Custom.getQuery(Custom.Quizpacks.clickedPackLink.href);
		if (packQuery) {
		
			var ajaxPath = Custom.Quizpacks.ajaxURL + '?' + packQuery + '&epslanguage=' + CurrentLocale;
			Custom.Quizpacks.quizAjax = new Ajax(ajaxPath, {
				method: 'get',
				evalscripts: true,
				onRequest: function(){
					//Custom.Quizpacks.requestSuccess = false;
					//Custom.Quizpacks.ajaxTest = window.setTimeout("Custom.Quizpacks.errorMessageDisplay()", 20000);
				}, 
				onFailure: function(){
					Custom.Quizpacks.packTabOff();
				},
				onSuccess: function(){
					//Custom.Quizpacks.requestSuccess = true;
					//window.clearTimeout(Custom.Quizpacks.ajaxTest);
					var newBoxout = Custom.Quizpacks.createBoxout('quizpackBoxout', this.response.text);
			
					if(Custom.Quizpacks.currentPackIdx === 0) {
						newBoxout.addClass('leftPos');
					}; // adding a class to clicked li if it's first or last
					
					var numOfPackInList = Custom.Quizpacks.currentPack.getParent().getChildren().length;
					if((numOfPackInList > 1) && (Custom.Quizpacks.currentPackIdx === numOfPackInList - 1)) {
						newBoxout.addClass('rightPos')
					};					
					
					
					newBoxout.injectAfter(Custom.Quizpacks.currentPack.getParent());
					Custom.pngFix();
					var boxoutHeight = newBoxout.getSize().size.y;
					newBoxout.setStyle('height', boxoutHeight); // set the height of the boxout to that of the content injected in
					Custom.Quizpacks.boxoutSlideEffect(newBoxout);
				},
				onComplete: function(){
					var spinner = $$('.tabPos')[0];
					Custom.Quizpacks.createCloseButton().injectBefore(spinner);
					spinner.remove();
				}
			}).request();			
		}
	},
	errorMessageDisplay : function() {
		if(Custom.Quizpacks.requestSuccess === false) {
			var newBoxout = Custom.Quizpacks.createBoxout('quizpackBoxout', Custom.Quizpacks.errorMessage);
			newBoxout.injectAfter(Custom.Quizpacks.currentPack.getParent());
			var boxoutHeight = newBoxout.getSize().size.y;
			newBoxout.setStyle('height', boxoutHeight);
			Custom.Quizpacks.boxoutSlideEffect(newBoxout);
			var spinner = $$('.tabPos')[0];
			Custom.Quizpacks.createCloseButton().injectBefore(spinner);
			spinner.remove();
			Custom.Quizpacks.quizAjax.cancel();
		}
	},
	createBoxout : function(boxoutId, innerContent) {
		var newBoxout = new Element('div');
		newBoxout.setProperty("id", boxoutId);
		newBoxout.setHTML(innerContent);
		return newBoxout
	},
	createCloseButton : function() {
		var newCloseButton = new Element('a');
		newCloseButton.addClass('closeTab');
		newCloseButton.addClass('tabPos');	
		newCloseButton.href = 'href';
		newCloseButton.setHTML("<img src='/assets/img/close_tab.gif' />");
		newCloseButton.addClick(function() {
			Custom.Quizpacks.onCancelClick()
		})
		return newCloseButton;
	},
	createSpinner : function() {
		var spinner = new Element('img');
		spinner.src = '/assets/img/icons/spinner_upload.gif';
		spinner.addClass('closeTab');
		spinner.addClass('tabPos');
		return spinner;
	},
	boxoutSlideEffect : function(boxout) {
			Custom.Quizpacks.boxoutSlider = new Fx.Slide(boxout, {
				transition: Fx.Transitions.Quad.easeInOut,
				duration: Custom.Carosel.sliderSpeed,
				onStart: function(){
						if (boxout.getParent().getStyle('clear') === 'none') {
							boxout.getParent().setStyle('clear', 'both');
							boxout.getParent().setStyle('position', 'relative');
						};
						
				},
				onComplete: function() {	

				}
				
			}).hide();
			Custom.Quizpacks.boxoutSlider.slideIn();
	}
	
}



function popUpProperties(inobj) {
	op = window.open();
	op.document.open('text/plain');
	for (objprop in inobj) {
	op.document.write(objprop + ' => ' + inobj[objprop] + '\n');
	}
	op.document.close();
}   


function getProductPage(href)
{
    /*
	if(typeof(firstTime)!='undefined'){
		// dont load any details first time!
		toggleButton='disabled';
    	Custom.Carosel.getSubPage(href);
	}else{
		firstTime="no";
		currentDiscView="";
	}*/
	
    toggleButton='disabled';
    Custom.Carosel.getSubPage(href);
}

function toggleView(code){
 	if(toggleButton!='disabled'){
    	Custom.Views.toggleView();
	}
}
Custom.setupAll();

