window.addEvent('domready', function(){

	

	if($$('.content-top-slider')[0]){

		load_slider('.content-top-slider',415);

		slidergroups['.content-top-slider'].render();

	}

});


	var slider = new Class ({	

		initialize: function(id,h) {

			this.id = id;

			this.slider = $$(id)[0];

			this.slidesholder = $$(id + ' ul')[0];

			this.slidesholder.id = 'slideholder'+slidergroups.length;

			this.slidesholder.setStyle('overflow','hidden');

			this.slides = $$(id + ' li');

			this.rightarrowimg = 'templates/beyondthebeach/images/slides/arrow-right.png';

			this.leftarrowimg = 'templates/beyondthebeach/images/slides/arrow-left.png';

			if(h==393){

				this.rightarrowlocation = {'right':'14px','top':'170px'};

				this.leftarrowlocation = {'left':'14px','top':'170px'};

			}

			else {

				this.rightarrowlocation = {'left':'110px','top':'350px'};

				this.leftarrowlocation = {'left':'65px','top':'350px'};

			}

			/*this.dotsicon = 'templates/images/icons/slide-counter.png';

			this.dotscurrent = 'templates/images/icons/slide-current.png';

			this.dotslocation = {'left':'24px','bottom':'15px'};

			this.dotspacing = 20;

			this.dotstyle = {'bottom':0, 'position':'absolute'};*/

			this.width = 1116;

			this.height = h;

			//this.dots = Array();

			this.lastslide = 'a';

			this.videovisible = false;

		},

		render: function(){

			//this.dotlist = new Element('div', {'class':'dots'}).setStyles({'position':'absolute', 'z-index':'30', 'cursor':'pointer'}).setStyles(this.dotslocation).inject(this.slider);

			this.slidesholder.inject(this.slideswrapper = new Element('div', {'class':'wrapper'}).setStyles({'height':this.height+'px','width':this.width+'px','overflow':'hidden','position':'relative'}).inject(this.slider));

			for(var x = 0; x < this.slides.length; x++){

				this.slides[x].id = 'slide'+x;

				this.slides[x].count = x;

				this.slides[x].popup = this.slides[x].getElements('a.video-popup')

				if(this.slides[x].popup.length > 0){

					this.slides[x].popup = this.slides[x].popup[0];

					if(!document.iPad){

						this.slides[x].popup.href = 'javascript:void(0);';

						/*this.slides[x].popup.addEvent('mouseup', this.showVideo.bindAsEventListener(this));

						

						this.slides[x].vid = this.slides[x].getElements('.brightpop-video')[0];

						this.slides[x].vid.id = 'vidoverlay'+x;

						this.slides[x].vid.setStyles({'display':'block', 'opacity':'0'});

						this.slides[x].vid.effect = new Fx.Style(this.slides[x].vid.id, 'opacity', {duration:500});

						

						this.slides[x].overlay = this.slides[x].getElements('.brightpop-video-overlay');

						this.slides[x].overlay = this.slides[x].overlay[0];

						this.slides[x].overlay.id = 'overlay'+x;

						this.slides[x].overlay.addEvent('mouseup', this.hideVideo.bindAsEventListener(this));

						this.slides[x].overlay.setStyles({'display':'block', 'opacity':'0'});

						this.slides[x].overlay.effect = new Fx.Style(this.slides[x].overlay.id, 'opacity', {duration:500});*/

					}

				}

				

				this.slides[x].effect = new Fx.Style(this.slides[x].id, 'opacity', {duration:500});

				/*this.dots[x] = new Element('img');

				if(x == 0){

					this.dots[x].src = this.dotscurrent;

					this.slides[x].setStyles({'opacity':'1'});

				}else{

					this.dots[x].src = this.dotsicon;

					this.slides[x].setStyles({'opacity':'0'});

				}

				this.dots[x].addClass('png');

				this.dots[x].setStyles (this.dotstyle);

				this.dots[x].setStyle('left',((x) * this.dotspacing) + 'px');

				this.dots[x].count = x;

				this.dots[x].addEvent("click", function(e, x){this.slide(this.currentslide*-1 + x);}.bindAsEventListener(this,x));;

				this.dots[x].inject(this.dotlist);

				this.dots[x].effect = new Fx.Style(this.slides[x].id, 'opacity', {duration:500});*/

			}

			this.rightarrow = new Element('img', {'src':this.rightarrowimg}).addClass('png').setStyles({'position':'absolute', 'cursor':'pointer','z-index':10}).setStyles(this.rightarrowlocation).inject(this.slideswrapper).addEvent("click", function(){this.slide(1);}.bindAsEventListener(this));

			this.leftarrow = new Element('img', {'src':this.leftarrowimg}).addClass('png').setStyles({'position':'absolute', 'cursor':'pointer','z-index':10}).setStyles(this.leftarrowlocation).inject(this.slideswrapper).addEvent("click", function(){this.slide(-1);}.bindAsEventListener(this));;

			this.timer = setTimeout('slidergroups["'+this.id+'"].slide(1)',5000);

			this.currentslide = 0;
				this.slides[0].setStyle('z-index', '3');

		},

		slide: function(count){

			/*if(this.videovisible){

				this.hideVideo();

			}*/

			this.slides[this.currentslide].effect.stop();

			clearTimeout(this.timer);

			/*this.dots[this.currentslide].src = this.dotsicon;

			if(window.ie6){

				this.dots[this.currentslide].runtimeStyle.behavior="none";

				if(this.dots[this.currentslide].nodeName == "IMG" && this.dots[this.currentslide].src.toLowerCase().indexOf('.png')>-1){

					this.dots[this.currentslide].runtimeStyle.backgroundImage = "none";

					this.dots[this.currentslide].runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.dots[this.currentslide].src + "', sizingMethod='image')";

					this.dots[this.currentslide].src = "/templates/images/transparent.gif";

				}else{

					if(this.dots[this.currentslide].origBg = this.dots[this.currentslide].origBg){

						this.dots[this.currentslide].origBg;

					}else{

						this.dots[this.currentslide].currentStyle.backgroundImage.toString().replace('url("','').replace('")','');

						this.dots[this.currentslide].runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.dots[this.currentslide].origBg + "', sizingMethod='crop')";

						this.dots[this.currentslide].runtimeStyle.backgroundImage = "none";

					}

				}

			}*/

			tmploc1 = this.currentslide * this.width * -1;

			if(this.lastslide != 'a'){
                
				this.slides[this.lastslide].setStyle('z-index', '1');

			}

			this.slides[this.currentslide].setStyle('z-index', '2');

			this.lastslide = this.currentslide;

			this.currentslide = this.currentslide + count;

			

			if(this.currentslide < 0){

				this.currentslide = this.currentslide + this.slides.length;

			}else if(this.currentslide >= this.slides.length){

				this.currentslide = this.currentslide - this.slides.length;

			}
			
		

			/*this.dots[this.currentslide].src = this.dotscurrent;

			if(window.ie6){

				this.dots[this.currentslide].runtimeStyle.behavior="none";

				if(this.dots[this.currentslide].nodeName == "IMG" && this.dots[this.currentslide].src.toLowerCase().indexOf('.png')>-1){

					this.dots[this.currentslide].runtimeStyle.backgroundImage = "none";

					this.dots[this.currentslide].runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.dots[this.currentslide].src + "', sizingMethod='image')";

					this.dots[this.currentslide].src = "/templates/images/transparent.gif";

				}else{

					if(this.dots[this.currentslide].origBg = this.dots[this.currentslide].origBg){

						this.dots[this.currentslide].origBg;

					}else{

						this.dots[this.currentslide].currentStyle.backgroundImage.toString().replace('url("','').replace('")','');

						this.dots[this.currentslide].runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.dots[this.currentslide].origBg + "', sizingMethod='crop')";

						this.dots[this.currentslide].runtimeStyle.backgroundImage = "none";

					}

				}

			}*/

			//tmploc2 = this.currentslide * this.width * -1;

			/*if(count < 0){*/

				this.slides[this.currentslide].setStyle('opacity', 0);

				this.slides[this.currentslide].setStyle('z-index', '3');


				this.slides[this.currentslide].effect.start(0, 1);

			/*}else{

				this.slides[this.currentslide].setStyle('left', this.width);

				this.slides[this.currentslide].setStyle('z-index', '3');

				this.slides[this.currentslide].effect.start(this.width,0);

			}*/

			//this.slidemove.start(tmploc1,tmploc2);

			//this.slidesholder.setStyle('left',tmploc2+'px');

			

			this.timer = setTimeout('slidergroups["'+this.id+'"].slide(1)',5000);

		}

	});

	

	var slidergroups = Array();

 

 	function load_slider(id,h){

		slidergroups[id] = new slider(id,h);

	}
