﻿//useful functions
function changeStyle(el,style,css,dura,trans){
	el.set('tween',{duration:dura,transition:trans,link:'cancel'}).tween(style,css);
};

//when page is loaded
window.addEvent('domready', function(){

	//variables
	var divContainer = $$('#Container');
	var topMenuLinks = $$('#AccessMenu a','.col.one a','#Footer a','.Address a','ul#siteMap a');
	var formElements = $$('.form input','.form textarea','.form select');
	var submitBttn = $$('.form a.submitbutton');
	
	//call mooSIFR
	if($$('h1,h2,h3,h4,h5,h6').length > 0){//only triggered if 'h tags' are found on page
		var initSIFR1 = new sIFR({
			elements: 'h1,h2',
			font: 'bubblegum'
		});
	};
	
	//remove NoJavaScript class as we obv have javascript enabled
	divContainer.each(function(el,i){											   
		el.removeClass('NoJavaScript');
	});
	
	//sort top menu links into arrays
	topMenuLinks.each(function(el,i){
		//add event listener
		el.addEvents({
			'mouseenter': function(){
				changeStyle(el,'opacity',0.5,200,Fx.Transitions.Cubic.easeIn);
			},
			'mouseleave': function(){
				changeStyle(el,'opacity',1,400,Fx.Transitions.Cubic.easeOut);
			}
		});
	});
	
	//add event listener for form elements so focus will work in IE6 and add nice effects
	formElements.each(function(el,i){
		//get vlaue if any
		var initValue = el.value;

		//add event listener
		el.addEvents({
			'focus': function(){
				changeStyle(el,'background','#fff',200,Fx.Transitions.linear);
				if(el.value == initValue){
					el.value = '';
				};
			},
			'blur': function(){
				changeStyle(el,'background','#BCCFDC',400,Fx.Transitions.linear);
				if(el.value == ''){
					el.value = initValue;
				};
			}
		});
	});
	
	//load header banner
	if($$('#header-swf').length > 0){
		if(Browser.Plugins.Flash.version < 7){
			$('header-swf').set('html','<span>To view this content, please <a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash">download latest flash player</a>.</span>');
		}else{
			var obj = new Swiff('./Portals/Carlton/flash/header-banner.swf',{
				id: 'Carlton Bingo Flash header banner',
				container: $('header-swf'),
				width: 595,
				height: 165,
				vars: {
					setXML: 'http://www.carltonbingo.com/getClubXml.ashx',
					setCashMatch: '<font color="#FFDD00">£250</font><br><font color="#ffffff">Cash<br>Match</font>'
				}
			});
		};
	}else if($$('#header-swf-bounce').length > 0){
		if(Browser.Plugins.Flash.version < 7){
			$('header-swf').set('html','<span>To view this content, please <a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash">download latest flash player</a>.</span>');
		}else{
			var obj = new Swiff('./Portals/Carlton/flash/header-banner.swf',{
				id: 'Carlton Bingo Flash header banner',
				container: $('header-swf-bounce'),
				width: 595,
				height: 165,
				vars: {
					setXML: 'http://www.carltonbingo.com/getClubXml.ashx',
					setBounce: 'true',
					setCashMatch: '<font color="#FFDD00">£250</font><br><font color="#ffffff">Cash<br>Match</font>'
				}
			});
		};
	};
	
	//load ladies banner
	if($$('#ladies-swf').length > 0){
		if(Browser.Plugins.Flash.version < 7){
			$('ladies-swf').set('html','<span>To view this content, please <a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash">download latest flash player</a>.</span>');
		}else{
			var obj = new Swiff('./Portals/Carlton/flash/ladies-banner.swf',{
				id: 'Carlton Bingo Flash ladies banner',
				container: $('ladies-swf'),
				width: 734,
				height: 206,
				vars: {
					setXML: 'http://www.carltonbingo.com/getFlashxml.ashx'
				}
			});
		};
	};
	
	//load mini-schedule flash
	if($$('#mini-schedule').length > 0){
		if(Browser.Plugins.Flash.version < 7){
			$('mini-schedule').set('html','<span>To view this content, please <a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash">download latest flash player</a>.</span>');
		}else{
			var obj = new Swiff('./Portals/Carlton/flash/feeder_v2.swf',{
				id: 'Carlton Bingo Flash schedule ticker',
				container: $('mini-schedule'),
				width: 150,
				height: 100,
				vars: {
					setXML: 'http://www.carltonbingo.com/getClubXml.ashx?feedname=schedule',
					setURL: 'javascript:openSizedOnlineGamesPage(\'Clover Rollover SA\', \'\', \'optionalParamA\', 765, 560, \'CloverRolloverSAWindow\')\;',
					setSchedule: 'http://www.carltonbingo.com/Bingo/Schedule',
					setSpeed: '0.8'
				}
			});
		};
	};
	
	//call mooCollpasibles
	if($$('.collapsible').length > 0){//only triggered if 'collapsible' class found on page
		var initCollapsibles = new mooCollapsible({
			cllpsContainers: $$('.collapsible'),//passes content/contents to be collapsed
			cllpsHeaders: $$('.collapsible .header').reverse(),//the headers inside containers
			cllpsBodies: $$('.collapsible .body').reverse(),//the bodies inside containers
			buildToggler: true,//'expand all | collapse all' buttons will be generated if true
			expandDefault: false,//have the collapsibles open or closed by deafult
			sldDuratation: 350,//duration of slide effect
			sldTransition: Fx.Transitions.Cubic.easeOut,//transition type
			accordionEffect: false//will simulate MooTools Accordion
		}).start();
	};

	//call SlideItMoo
	if($('SlideItMoo_outer')){//only triggered if 'SlideItMoo_outer' id is found on page
		new SlideItMoo({
			overallContainer: 'SlideItMoo_outer',
			elementScrolled: 'SlideItMoo_inner',
			thumbsContainer: 'SlideItMoo_items',		
			itemsVisible:3,
			itemsSelector: '.SlideItMoo_element',
			itemWidth: 211,
			showControls:1,
			transition: Fx.Transitions.linear,
			duration: 400,
			direction: 1,
			autoSlide: 8000
		});
		//show it on page
		$('SlideItMoo_outer').setStyle('display','block');
	};
	
	//call multibox's
	if($$('.mb').length > 0){//only triggered if 'mb' class found on page
		var initMultiBox = new multiBox('mb', {
			descClassName: '',//the class name of the description divs
			path: './files/',//path to mp3 and flv players
			useOverlay: true,//use a semi-transparent background. default: false;
			maxWidth: 600,//max width (set to false to disable)
			maxHeight: 400,//max height (set to false to disable)
			addDownload: false,//do you want the files to be downloadable?
			pathToDownloadScript: './scripts/forceDownload.asp',//if above is true, specify download script
			addRollover: true,//add rollover fade to each multibox link
			addOverlayIcon: false,//adds overlay icons to images within multibox links
			addChain: false,//cycle through all images fading them out then in
			recalcTop: true//subtract the height of controls panel from top position
		});
	};
	
	if($$('.mb_2').length > 0){//only triggered if 'mb_2' class found on page
		var initMultiBox = new multiBox('mb_2', {
			descClassName: 'multiBoxDesc',//the class name of the description divs
			path: './files/',//path to mp3 and flv players
			useOverlay: false,//use a semi-transparent background. default: false;
			maxWidth: 600,//max width (set to false to disable)
			maxHeight: 400,//max height (set to false to disable)
			addDownload: false,//do you want the files to be downloadable?
			pathToDownloadScript: './scripts/forceDownload.asp',//if above is true, specify download script
			addRollover: true,//add rollover fade to each multibox link
			addOverlayIcon: true,//adds overlay icons to images within multibox links
			addChain: false,//cycle through all images fading them out then in
			recalcTop: true//subtract the height of controls panel from top position
		});
	};

	//call mooSwitch
	if($$('.mooSwitch').length > 0){//only triggered if 'mooSwitch' id is found on page
		var initSwitch = new mooSwitch({
			container: $('Container'),//inline font-size style will be applied to this
			linksContainer: $('AccessMenu'),//container that holds the links (error message will be output here)
			templateContainer: $('ChangeTemplate'),//container that holds the template links (error message will be output here)
			smallSize: '90%',//small font size
			mediumSize: '100%',//medium font size(should be your default size)
			largeSize: '110%',//large font size
			speed: 400
		}).start();
	};
});