//Public javascript functions


/*
	Slimbox v1.7 - The ultimate lightweight Lightbox clone
	(c) 2007-2009 Christophe Beyls <http://www.digitalia.be>
	MIT-style license.
*/
var Slimbox=(function(){var F=window,n=Browser.Engine.trident4,u,g,G=-1,o,w,E,v,y,M,s,m={},t=new Image(),K=new Image(),I,a,h,q,J,e,H,c,A,L,x,i,d,C;F.addEvent("domready",function(){$(document.body).adopt($$(I=new Element("div",{id:"lbOverlay",events:{click:D}}),a=new Element("div",{id:"lbCenter"}),H=new Element("div",{id:"lbBottomContainer"})).setStyle("display","none"));h=new Element("div",{id:"lbImage"}).injectInside(a).adopt(q=new Element("div",{styles:{position:"relative"}}).adopt(J=new Element("a",{id:"lbPrevLink",href:"#",events:{click:B}}),e=new Element("a",{id:"lbNextLink",href:"#",events:{click:f}})));c=new Element("div",{id:"lbBottom"}).injectInside(H).adopt(new Element("a",{id:"lbCloseLink",href:"#",events:{click:D}}),A=new Element("div",{id:"lbCaption"}),L=new Element("div",{id:"lbNumber"}),new Element("div",{styles:{clear:"both"}}))});function z(){var N=F.getScroll(),O=F.getSize();$$(a,H).setStyle("left",N.x+(O.x/2));if(v){I.setStyles({left:N.x,top:N.y,width:O.x,height:O.y})}}function l(N){["object",n?"select":"embed"].forEach(function(P){Array.forEach(document.getElementsByTagName(P),function(Q){if(N){Q._slimbox=Q.style.visibility}Q.style.visibility=N?"hidden":Q._slimbox})});I.style.display=N?"":"none";var O=N?"addEvent":"removeEvent";F[O]("scroll",z)[O]("resize",z);document[O]("keydown",p)}function p(O){var N=O.code;return u.closeKeys.contains(N)?D():u.nextKeys.contains(N)?f():u.previousKeys.contains(N)?B():false}function B(){return b(w)}function f(){return b(E)}function b(N){if(N>=0){G=N;o=g[N][0];w=(G||(u.loop?g.length:0))-1;E=((G+1)%g.length)||(u.loop?0:-1);r();a.className="lbLoading";m=new Image();m.onload=k;m.src=o}return false}function k(){a.className="";d.set(0);h.setStyles({backgroundImage:"url("+o+")",display:""});q.setStyle("width",m.width);$$(q,J,e).setStyle("height",m.height);A.set("html",g[G][1]||"");L.set("html",(((g.length>1)&&u.counterText)||"").replace(/{x}/,G+1).replace(/{y}/,g.length));if(w>=0){t.src=g[w][0]}if(E>=0){K.src=g[E][0]}M=h.offsetWidth;s=h.offsetHeight;var P=Math.max(0,y-(s/2)),N=0,O;if(a.offsetHeight!=s){N=i.start({height:s,top:P})}if(a.offsetWidth!=M){N=i.start({width:M,marginLeft:-M/2})}O=function(){H.setStyles({width:M,top:P+s,marginLeft:-M/2,visibility:"hidden",display:""});d.start(1)};if(N){i.chain(O)}else{O()}}function j(){if(w>=0){J.style.display=""}if(E>=0){e.style.display=""}C.set(-c.offsetHeight).start(0);H.style.visibility=""}function r(){m.onload=$empty;m.src=t.src=K.src=o;i.cancel();d.cancel();C.cancel();$$(J,e,h,H).setStyle("display","none")}function D(){if(G>=0){r();G=w=E=-1;a.style.display="none";x.cancel().chain(l).start(0)}return false}Element.implement({slimbox:function(N,O){$$(this).slimbox(N,O);return this}});Elements.implement({slimbox:function(N,Q,P){Q=Q||function(R){return[R.href,R.title]};P=P||function(){return true};var O=this;O.removeEvents("click").addEvent("click",function(){var R=O.filter(P,this);return Slimbox.open(R.map(Q),R.indexOf(this),N)});return O}});return{open:function(P,O,N){u=$extend({loop:false,overlayOpacity:0.8,overlayFadeDuration:400,resizeDuration:400,resizeTransition:false,initialWidth:250,initialHeight:250,imageFadeDuration:400,captionAnimationDuration:400,counterText:"Image {x} of {y}",closeKeys:[27,88,67],previousKeys:[37,80],nextKeys:[39,78]},N||{});x=new Fx.Tween(I,{property:"opacity",duration:u.overlayFadeDuration});i=new Fx.Morph(a,$extend({duration:u.resizeDuration,link:"chain"},u.resizeTransition?{transition:u.resizeTransition}:{}));d=new Fx.Tween(h,{property:"opacity",duration:u.imageFadeDuration,onComplete:j});C=new Fx.Tween(c,{property:"margin-top",duration:u.captionAnimationDuration});if(typeof P=="string"){P=[[P,O]];O=0}y=F.getScrollTop()+(F.getHeight()/2);M=u.initialWidth;s=u.initialHeight;a.setStyles({top:Math.max(0,y-(s/2)),width:M,height:s,marginLeft:-M/2,display:""});v=n||(I.currentStyle&&(I.currentStyle.position!="fixed"));if(v){I.style.position="absolute"}x.set(0).start(u.overlayOpacity);z();l(1);g=P;u.loop=u.loop&&(g.length>1);return b(O)}}})();

// AUTOLOAD CODE BLOCK (MAY BE CHANGED OR REMOVED)
Slimbox.scanPage = function() {
	$$(document.links).filter(function(el) {
		return el.rel && el.rel.test(/^lightbox/i);
	}).slimbox({/* Put custom options here */}, null, function(el) {
		return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
	});
};
window.addEvent("domready", Slimbox.scanPage);


/*
Mootools Content Slider Class v2
Daniel Stout
http://stoutlabs.com
*/
var SL_Slider=new Class({Implements:[Options],numNav:new Array(),timer:null,isSliding:0,direction:1,options:{slideTimer:8000,orientation:"horizontal",fade:false,isPaused:false,transitionTime:1100,transitionType:"cubic:out",container:null,items:null,itemNum:0,numNavActive:false,numNavHolder:null,playBtn:null,prevBtn:null,nextBtn:null},initialize:function(b){var a=this;this.setOptions(b);a.options.container.setStyle("overflow","hidden");if(a.options.playBtn!=null){a.options.playBtn.set("text","pause");a.options.playBtn.addEvents({click:function(){a.pauseIt()},mouseenter:function(){this.setStyle("cursor","pointer")},mouseleave:function(){}})}if(a.options.prevBtn&&a.options.nextBtn){a.options.prevBtn.addEvents({click:function(){if(a.isSliding==0){if(a.options.isPaused==false){$clear(a.timer);a.timer=a.slideIt.periodical(a.options.slideTimer,a,null)}a.direction=0;a.slideIt()}},mouseenter:function(){this.setStyle("cursor","pointer")},mouseleave:function(){}});this.options.nextBtn.addEvents({click:function(){if(a.isSliding==0){if(a.options.isPaused==false){$clear(a.timer);a.timer=a.slideIt.periodical(a.options.slideTimer,a,null)}a.direction=1;a.slideIt()}},mouseenter:function(){this.setStyle("cursor","pointer")},mouseleave:function(){}})}a.options.items.each(function(e,d){e.setStyle("position","absolute");var c=e.getSize().y;var j=e.getSize().x;if(a.options.orientation=="vertical"){e.setStyle("top",(-1*c));e.setStyle("left",0)}else{if(a.options.orientation=="none"){e.setStyle("left",0);e.setStyle("top",0);e.set("opacity",0)}else{e.setStyle("left",(-1*j))}}if(a.options.numNavActive==true){var h=new Element("li",{id:"num"+d});var g=new Element("a",{"class":"numbtn",html:(d+1)});h.adopt(g);a.options.numNavHolder.adopt(h);a.numNav.push(g);g.set("morph",{duration:100,transition:Fx.Transitions.linear,link:"ignore"});g.addEvents({click:function(){a.numPress(d)},mouseenter:function(){this.setStyle("cursor","pointer")}});if(d==a.options.itemNum){var f=a.numNav[d];f.addClass("active")}}})},start:function(){var a=this;a.slideIt(a.options.itemNum);if(a.options.isPaused==false){a.timer=a.slideIt.periodical(a.options.slideTimer,a,null);if(a.options.playBtn){a.options.playBtn.set("text","pause")}}else{if(a.options.playBtn){a.options.playBtn.set("text","play")}}},slideIt:function(i){var j=this;var l=j.options.items[j.options.itemNum];if(j.options.numNavActive==true){var h=j.numNav[j.options.itemNum]}if(i!=null){if(j.options.itemNum!=i){if(j.options.itemNum>i){j.direction=0}else{j.direction=1}j.options.itemNum=i}}else{j.changeIndex()}var e=j.options.items[j.options.itemNum];if(j.direction==0){var c=j.options.container.getSize().x;var a=(-1*e.getSize().x);var b=j.options.container.getSize().y;var k=(-1*e.getSize().y)}else{var c=(-1*j.options.container.getSize().x);var a=e.getSize().x;var b=(-1*j.options.container.getSize().y);var k=e.getSize().y}if(j.options.numNavActive==true){var g=j.numNav[j.options.itemNum];g.addClass("active")}var f=new Fx.Morph(e,{duration:j.options.transitionTime,transition:j.options.transitionType,link:"ignore",onStart:function(){j.isSliding=1},onComplete:function(){j.isSliding=0}});if(j.options.orientation=="vertical"){if(j.options.fade==true){f.start({opacity:[0,1],top:[k,0]})}else{f.start({top:[k,0]})}}else{if(j.options.orientation=="none"){f.start({opacity:[0,1]})}else{if(j.options.fade==true){f.start({opacity:[0,1],left:[a,0]})}else{f.start({left:[a,0]})}}}if(l!=e){var d=new Fx.Morph(l,{duration:j.options.transitionTime,transition:j.options.transitionType,link:"ignore"});if(j.options.numNavActive==true){h.removeClass("active")}if(j.options.orientation=="vertical"){if(j.options.fade==true){d.start({opacity:[0],top:[(b)]})}else{d.start({top:[(b)]})}}else{if(j.options.orientation=="none"){d.start({opacity:[1,0]})}else{if(j.options.fade==true){d.start({opacity:[0],left:[(c)]})}else{d.start({left:[(c)]})}}}}},pauseIt:function(){var a=this;if(a.isSliding==0){if(a.options.isPaused==false){a.options.isPaused=true;$clear(a.timer);a.options.playBtn.set("text","play")}else{a.options.isPaused=false;a.slideIt();a.timer=a.slideIt.periodical(a.options.slideTimer,this,null);a.options.playBtn.set("text","pause")}}},changeIndex:function(){var a=this;var b=a.options.items.length;if(a.direction==1){if(a.options.itemNum<(b-1)){a.options.itemNum++}else{a.options.itemNum=0}}else{if(a.direction==0){if(a.options.itemNum>0){a.options.itemNum--}else{a.options.itemNum=(b-1)}}}},numPress:function(b){var a=this;if((a.isSliding==0)&&(a.options.itemNum!=b)){if(a.options.isPaused==false){$clear(a.timer);a.timer=a.slideIt.periodical(a.options.slideTimer,this,null)}a.slideIt(b)}}});

/* ----------------------------------------------------------------------------------------------- End third party classes */




/* ----------------------------------------------------------------------------------------------- modalBox class */

//Display modal overlay box
var modalBox = new Class({
	
	Implements: Options,

	options: {
		closeOnClick:   true,
		showCloseButton:true,
		overlayOpacity: 0.8,
		titleText:      'Message',
		content:        $empty,
		width:          '500px'
	},
	
	
	initialize: function(options){
		this.setOptions(options);
		this.closeOnClick    = this.options.closeOnClick;
		this.showCloseButton = this.options.showCloseButton;
		this.overlayOpacity  = this.options.overlayOpacity;
		this.titleText       = this.options.titleText;
		this.width           = this.options.width;
		this.overlay         = $empty;
		this.contentBox      = $empty;
	},
	
	
	//Show the current modalBox
	show: function(){
		
		//Create an overlay
		this.overlay = new Element('div',{
		'id':'modalOverlay', 
		'class':'modalOverlay', 
		'styles':{
			'width':'100%',
			'height':window.getScrollSize().y,
			'position':'absolute',
			'top':0,
			'left':0,
			'z-index':1000,
			'opacity':0
			}
		});
		
		//Inject overlay into document body
		this.overlay.inject(document.body);
		
		//Create title bar
		var titleBar = new Element('div',{'id':'modalTitleBar'});
		
		//Create title
		var title = new Element('h1',{'id':'modalTitle','html':this.titleText});
		
		//Check if including close button
		if(this.showCloseButton){
		
			//Create close button
			var closeButton = new Element('a',{
				'id':'modalCloseButton',
				'href':'#',
				'html':'<span>Close</span>',
				'events':{
					'click': function(e){
						e.stop();
						this.hide();
					}.bind(this)
				}
			});
			//Inject close button into title bar
			titleBar.adopt(title, closeButton);
		}
		
		//Create content box
		this.contentBox = new Element('div',{
		'id':'modalContentBox',
		'styles':{
			'width':this.width,
			'position':'absolute',
			'z-index':1001
			}
		});
		
		//Inject title bar
		this.contentBox.adopt(titleBar);
		
		//Check if content is just a string
		if($type(this.options.content) == "string"){
			this.options.content = '<p>'+this.options.content+'</p>';
		}
		
		//Inject content into box
		this.contentBox.adopt(this.options.content);
		
		//Inject content box into document body
		this.contentBox.inject(document.body);
		
		//Get size of content box
		var contentBoxSize = this.contentBox.getSize();

		//Update content box position
		this.contentBox.setStyles({
			'top': (window.getScroll().y+((window.getSize().y/2)-(contentBoxSize.y/2))),
			'left': (window.getSize().x/2)-((this.width).toInt()/2)
		});
		
		//Hide things like select lists and embeded flash
		this.iframeShim(0);

		//Show the overlay
		this.overlay.set('opacity',this.overlayOpacity);
		
		//If closeOnClick is set to true
		if(this.closeOnClick){
			//Add click event to overlay
			this.overlay.addEvent('click',function(el){
				this.hide();
			}.bind(this));
		}
	
	},//End show the current modalBox
	
	
	//Hide (destroy) modalBox
	hide: function(){
		//Destroy content and overlay
		this.contentBox.destroy();
		this.overlay.destroy();
		//Bring select lists and embeded flash back
		this.iframeShim(1);
	},
	
	
	//Set the opacity of iframe shim objects
	iframeShim: function(overlayOpacity){
		if(Browser.Engine.trident4 || (Browser.Engine.gecko && Browser.Platform.mac)) {
			$$('select').each(function(select){
				select.setStyle('opacity', overlayOpacity);
			});
		}
	}
	
});//End modalBox



/* ----------------------------------------------------------------------------------------------- confirmationDialog class */

//Confirmation dialog, displays a modal box with a message and Yes/No buttons
var confirmationDialog = new Class({
	
	Implements: Options,

	options: {
		onConfirm: $empty,
		onDeny:    $empty
	},
	
	initialize: function(message,options){
		this.setOptions(options);
		this.message   = message;
		this.modal     = new modalBox({'closeOnClick':false,'titleText':'Are you sure?','width':'300px'});
	},
	
	
	//Show the dialog
	show: function(){

		var dialogWrapper = new Element('div');
		
		var messageContainer = new Element('p',{'html':this.message});
		
		var yesButton = new Element('button',{
			'id':'confirmButtonYes',
			'name':'confirmButtonYes',
			'class':'dialogButton',
			'html':'<span>Yes</span>',
			'events':{
				'click':this.options.onConfirm
			}
		});
		
		var noButton = new Element('button',{
			'id':'confirmButtonNo',
			'name':'confirmButtonNo',
			'class':'dialogButton',
			'html':'<span>No</span>',
			'events':{
				'click':this.options.onDeny
			}
		});

		messageContainer.inject(dialogWrapper);
		yesButton.inject(dialogWrapper);
		noButton.inject(dialogWrapper);
		
		this.modal.setOptions({'content':dialogWrapper});
		this.modal.show();
		
	},//End show the dialog
	
	
	//Hide (destroy) dialog
	hide: function(){
		this.modal.hide();
	}
	
});//End confirmationDialog



//Setup cs functions
var csFunctions = {//Start csFunctions

	
/* ----------------------------------------------------------------------------------------------- waitDialog function */
	
	//Display the please wait dialog
	waitDialog: function(triggers,message){
		
		//Stick message in paragraph
		var dialogMessage = new Element('p',{'html':message});
		
		//Create confirmation dialog
		var waitModal = new modalBox({'closeOnClick':false,'closeButton':false,'content':dialogMessage,'width':'100px'});
		
		triggers.each(function(el){
			el.addEvent('click',function(e){	
				waitModal.show();		   
			});					 
		});
	},
	
/* ----------------------------------------------------------------------------------------------- confirmDialog function */
	
	//Display a dialog confirming the user's choice
	confirmDialog: function(triggers,message){

		//Create confirmation dialog
		var confirmDialog = new confirmationDialog(message,{});
		
		triggers.each(function(el){
			el.addEvent('click',function(e){
				
				e.stop();
				
				confirmDialog.setOptions({
					'onConfirm':function(){ 
						//Continue to original link
						window.location = el.getProperty('href');
					},
					'onDeny':function(){ 
						confirmDialog.hide();
					}
				});
				
				confirmDialog.show();		   
			});					 
		});
		
	},//End confirmDialog

	
	/* ----------------------------------------------------------------------------------------------- wysiwyg_file_browser function */
	
	//Custom file browser for the wysiwyg editor
	wysiwyg_file_browser: function (field_name, url, type, win){
		
		//Absolute url to file browser
		var file_browser_url = 'http://www.tintmart.com.au/file-browser/type/'+type;
		
		//Open popup window containing the file browser
		tinyMCE.activeEditor.windowManager.open({
			file:           file_browser_url,
			title:          'File Browser',
			width:          745,
			height:         410,
			resizable:      false,
			scrollbars:     'yes',
			inline:         'yes',
			close_previous: 'yes'
		},
		{
			window: win,
			input:  field_name
		});
		
		return false;
		
	},//End wysiwyg_file_browser()

	
/* ----------------------------------------------------------------------------------------------- initWysiwygs function */
	
	//Initialise wysiwyg editors
	initWysiwygs: function(textarea,type,toggleEditorDisplay){
		
		//Get textarea id
		var textAreaId = textarea.get('id');
		
		//Toggle editor function
		function toggleEditor(id) {
			if(!tinyMCE.get(id)){	
				tinyMCE.execCommand('mceAddControl', false, id);
				$(textAreaId+'_toggler').addClass('wysiwygEnabled');
				$(textAreaId+'_toggler').set('html','Disable editor');
				$(textAreaId+'_prevButton').show();
			}else{
				tinyMCE.execCommand('mceRemoveControl', false, id);
				$(textAreaId+'_toggler').removeClass('wysiwygEnabled');
				$(textAreaId+'_toggler').set('html','Enable editor');
				$(textAreaId+'_prevButton').hide();
			}
		}
		
		
		//If toggling editor display
		if(toggleEditorDisplay == 'enabled'){
			//Create toggle button
			new Element('span',{
				'id':textAreaId+'_toggler',
				'class':'wysiwygToggle wysiwygEnabled',
				'html':'Disable editor',
				'events': {
					'click': function(){
						toggleEditor(textAreaId);
					}
				}
			}).inject(textarea,'before');
		}
		
		
		//Create preview button
		new Element('span',{
			'id':textAreaId+'_prevButton',
			'class':'wysiwygPreview',
			'html':'Preview',
			'events': {
				'click': function(){
					tinyMCE.execCommand('mcePreview', false, textAreaId);
				}
			}
		}).inject(textarea,'before');
		
		
		//Switch editor type
		switch(type){
			
			//Advanced editor, full functionality
			case 'advanced':
				var editor = new tinymce.Editor(textAreaId, {
					
					theme:                  'advanced',
					convert_urls:           false,
					width:                  '100%',
					accessibility_warnings : false,
					dialog_type:            'window',

					//Include plugins
					plugins: 'safari,style,table,advimage,emotions,preview,media,contextmenu,paste,fullscreen,noneditable,xhtmlxtras,codeprotect,spellchecker',
				
					//Theme options
					theme_advanced_buttons1:          'undo,redo,preview,fullscreen,cleanup,code,visualaid,spellchecker,|,removeformat',
					theme_advanced_buttons2:          'bold,italic,underline,strikethrough,sub,sup,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleprops,forecolor,backcolor,styleselect,formatselect,fontsizeselect',
					theme_advanced_buttons3:          'link,unlink,image,bullist,numlist,outdent,indent,blockquote,tablecontrols,emotions,charmap,media',
					theme_advanced_blockformats :     'p,div,h1,h2,h3,h4,h5,h6,blockquote,dt,dd,code,samp',
					theme_advanced_toolbar_location:  'top',
					theme_advanced_toolbar_align:     'left',
					theme_advanced_statusbar_location:'bottom',
				
					//Content CSS
					content_css: 'http://www.tintmart.com.au/_themes/public/css/wysiwyg_content.css',
					
					//Popup dialogs skin
					inlinepopups_skin: 'cs_cms',
					
					//Preview window size
					plugin_preview_width:  '800',
					plugin_preview_height: '450',
					
					//Paste dialog size
					paste_dialog_width:  '800',
					paste_dialog_height: '450',
					
					//Source editor size
					theme_advanced_source_editor_width: '800',
					theme_advanced_source_editor_height: '450',

					//Custom file browser
					file_browser_callback: this.wysiwyg_file_browser,
					
					extended_valid_elements : "iframe[src|width|height|name|align|marginheight|marginwidth]"
					
				});
			break;
			
			//Default basic functionality
			default:
				var editor = new tinymce.Editor(textAreaId, {
												
					theme:                  'advanced',
					convert_urls:           false,
					width:                  '100%',
					accessibility_warnings : false,
					dialog_type:            'window',
					
					//Include plugins
					plugins: 'safari,advimage,emotions,preview,media,paste,xhtmlxtras,spellchecker',
					
					//Theme options
					theme_advanced_buttons1:         'undo,redo,spellchecker,|,link,unlink,image,media,emotions,|,bold,italic,underline,strikethrough,bullist,numlist,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect,fontsizeselect,forecolor,removeformat',
					theme_advanced_buttons2:         '',
					theme_advanced_buttons3:         '',
					theme_advanced_blockformats :    'p,div,h1,h2,h3,h4,h5,h6,blockquote,dt,dd',
					theme_advanced_toolbar_location: 'top',
					theme_advanced_toolbar_align:    'left',

					//Content CSS
					content_css: 'http://www.tintmart.com.au/_themes/public/css/wysiwyg_content.css',
					
					//Popup dialogs skin
					inlinepopups_skin: 'cs_cms',
					
					//Preview window size
					plugin_preview_width:  '800',
					plugin_preview_height: '450',

					//Custom file browser
					file_browser_callback: this.wysiwyg_file_browser
					
				});
			break;
				
		}//End switch(type)
		
		//Display editor
		editor.render();
		
	},//End initWysiwygs
	
	
	
/* ----------------------------------------------------------------------------------------------- wysiwgPopups function */
	
	//Set wysiwg popups code
	wysiwgPopups: function(){
		
		//For each selectFileLink
		$$('.selectFileLink').addEvent('click',function(e){
			
			//Stop link click
			e.stop();
	
			//Get file url
			var fileUrl = this.get('href');
			
			//Get current popup window
			var win = tinyMCEPopup.getWindowArg("window");
	
			//Insert file url
			win.document.getElementById(tinyMCEPopup.getWindowArg("input")).value = fileUrl;
			
			//Images
			if(win.ImageDialog){
				if(win.ImageDialog.getImageData){ win.ImageDialog.getImageData(); }//Update image dimensions
				if(win.ImageDialog.showPreviewImage){ win.ImageDialog.showPreviewImage(fileUrl); }//Display image preview
			}
			
			//Media
			if($defined(win.switchType)){
				win.switchType(fileUrl);
			}
			
			//Preview
			if($defined(win.generatePreview)){
				win.generatePreview();					
			}
	
			//Close popup window
			tinyMCEPopup.close();
							   
		});//End .selectFileLink
	
	},//End wysiwgPopups

/* ----------------------------------------------------------------------------------------------- additionalFiles function */
	
	//Additional file fields
	additionalFiles: function(defaultFileBlock,name,id,defaultCount){//Start additionalFiles
		
		if(defaultFileBlock){//Start is field block

			//Check for name
			if(name == ''){
				name = 'file';
			}
		
			//Check for name
			if(id == ''){
				id = name;
			}
			
			//Check for count
			if(defaultCount == ''){
				defaultCount = 0;
			}
			
			//Create add choice label
			var addFile = new Element('dd',{'class':'input addFile','html':'<label>Add file</label>'});
			
			//Inject beneath last input
			addFile.inject(defaultFileBlock,'bottom');
			
			//Add on click event to add choice
			addFile.addEvent('click',function(e){
				
				//Increment count
				defaultCount++;
				
				//Create a new elements
				var newInputDd     = new Element('dd',{'class':'input'});
				var newInputField  = new Element('input',{'type':'file','name':name,'id':id+'_'+defaultCount,'class':'inputFileField'});
				var newInputDelete = new Element('label',{'class':'deleteInput','text':'Delete'});
								
				//Inject inputs into dd
				newInputDd.adopt(newInputField);
				newInputDelete.inject(newInputDd,'bottom');
				
				//Inject dd after existing inputs
				newInputDd.inject(addFile,'before');
				
				//Set delete onclick
				newInputDelete.addEvent('click',function(e){
					
					e.stop();
					
					//Delete dt and dd
					newInputDd.dispose();
					
				}.bind(this));
				
			}.bind(this));
		
		}//End is field block
		
	},//End additionalFiles

/* ----------------------------------------------------------------------------------------------- imageSlider function */
	
	//Turn image list into slider
	imageSlider: function(container){
		
		//Check container exists
		if(container){//Start container exists
			
			//Get container id
			var containerId = container.get('id');
			
			//Get array of content blocks
			var contentBlocks = container.getElements('.itemBlock');
		
			//Check blocks exist
			if(contentBlocks){//Start blocks exists
				
				//Change id of container
				container.set('id',containerId+'_slider');
				
				//Create wrapper
				var wrapper = new Element('div',{'id':containerId+'_slideWrapper'}).wraps(container);
				
				//Create and insert prev next controls
				var prevBtn = new Element('div',{'class':'prevButton','title':'View previous','html':'<span>Previous</span>'}).inject(wrapper);
				var nextBtn = new Element('div',{'class':'nextButton','title':'View next','html':'<span>Next</span>'}).inject(wrapper);
	
				//Create slider instance       
				var newImageSlider = new SL_Slider({
					slideTimer: 5000,
					orientation: 'none',
					fade: true,
					transitionTime: 1000,
					isPaused: false,
					container: container,
					items: contentBlocks,
					prevBtn: prevBtn,
					nextBtn: nextBtn
				});
				
				//Start slider
				newImageSlider.start();
				
			}//End blocks exists
			
		}//End container exists
		
	},//End imageSlider	

/* ----------------------------------------------------------------------------------------------- carVirtualTintSelector function */
	
	//Turn image list into slider
	carVirtualTintSelector: function(container){
		
		//Check container exists
		if(container){//Start container exists
			
			//Remove contents
			container.empty();
			
			//Create new elements
			var carContainer  = new Element('div',{'id':'carContainer','class':'carColour_default'}).inject(container);
			var tintContainer = new Element('div',{'id':'tintContainer','class':'carTint_default'}).inject(container);
			var colourList    = new Element('ul',{'id':'colourList'}).inject(container);
			var tintList      = new Element('ul',{'id':'tintList'}).inject(container);
			
			//Set car colours array
			var arr_carColours = ['white','red','blue','black','gold','silver'];
			
			//Set tints array
			var arr_carTints = ['bp_020','bp_035','inf_035','uv_advantage_35'];
			
			//Loop colours
			arr_carColours.each(function(colour,index){
				
				//Set colour thumbs
				var carColour = new Element('li',{'id':'colourList_'+colour,'title':'Change vehicle colour to '+colour,'html':'<span>'+colour+'</span>'}).inject(colourList);
				
				//Change colour on click
				carColour.addEvent('click',function(){
					carContainer.set('class','carColour_'+colour);					
				}.bind(this));
				
			}.bind(this));
			
			//Loop tints
			arr_carTints.each(function(tint,index){
				
				//Set tint nav buttons
				var tintType = new Element('li',{'id':'tintList_'+tint,'title':'Change tint type','html':'<span>'+tint+'</span>'}).inject(tintList);
				
				tintType.addEvent('click',function(){
					
					//Change tint
					tintContainer.set('class','carTint_'+tint);	
					
					//Set button classes
					tintList.getElements('li').removeClass('tintActive');
					tintType.addClass('tintActive');
					
				}.bind(this));
				
			}.bind(this));
			
		}//End container exists
		
	},//End carVirtualTintSelector
	
	//Initialise cs functions
	init: function(){
		this.waitDialog($$('.waitModal'),'Please wait...');
		this.confirmDialog($$('.linkDelete'),'Are you sure you want to delete this?');
		this.additionalFiles($('storePhotos'),'arr_store_photos[]','arr_store_photo',3);
		this.imageSlider($('brochuresList'));
		this.carVirtualTintSelector($('carFilmSelector'));
		
		
		//Advanced wysiwyg editors
		$$('.wysiwygAdvanced').each(function(textarea){
			this.initWysiwygs(textarea,'advanced','enabled');
		}.bind(this));

		//Basic wysiwyg editors
		$$('.wysiwygBasic').each(function(textarea){
			this.initWysiwygs(textarea,'basic','disabled');
		}.bind(this));
		
		//wysiwgPopups
		this.wysiwgPopups();
		
	}
									 
};//End csFunctions


window.addEvent('domready', csFunctions.init.bind(csFunctions));

