var PopVid = new Class({
	Implements: [Options, Events],
	options: {
		bar: false
	},
	initialize: function(options){
		var self = this;
		this.setOptions(options);
		
		if( $$('popup-wrap').length > 0 )
		{
			$$('popup-wrap').destroy();
		}
		
		$$('a.open-video').addEvent('click', function(){
			self.CreatePopup( this.get('rel') );
			
		});
		
	},
	CreatePopup: function(video){
		var self = this;
		var Popup = new Element('div', { 'class':'popup-wrap', 'id': '' } );
		var Video = new Element('div', { 'class':'video-wrap', 'id': 'video-container' } ).inject(Popup);
		var Close = new Element('div', { 'class':'popup-close', 'html': 'Close Window' } ).inject(Popup);
		
		Popup.setStyle('opacity', 0);
		Popup.inject( $(document.body) );
		
		var WindowSize = window.getSize();
		var PopupSize = Popup.getSize();
		
		//console.log( PopupSize );
		
		Popup.setStyles({
			'top': (WindowSize.y/2)-(PopupSize.y/2),
			'left': (WindowSize.x/2)-(PopupSize.x/2)
		});
		
		Popup.fade('in');
		
		(function(){
			
			flowplayer('video-container', '/js/flowplayer-3.1.5.swf', {
				clip: { 
					url: '/media/movies/'+video, 
					autoPlay: true,
					scaling: 'fit',
					autoBuffering: true 
				}
			}); 
			
		}).delay(500);
		
		Close.addEvent('click', function(){
			Video.destroy();
			Popup.fade('out');
			(function(){
				Popup.destroy();
			}).delay(500);
		});
		
	}
});

window.addEvent('load', function(){
	$$('body.site_15 #Nav ul li a').each(function(item){
		var text = item.get('html');
		if( text == 'Iceland' )
			item.destroy();
	});
	
	$$('body.site_16 #Nav ul li a').each(function(item){
		var text = item.get('html');
		if( text == 'Iceland' )
			item.destroy();
	});
});

window.addEvent('load', function(){
	
	function rotateBanner($startat)
	{
		UmsagnirRotateNum++;
		
		var Item = $('Item' + UmsagnirRotateNum);
		var ItemLastNum = (UmsagnirRotateNum-1);
		
		if( ItemLastNum <= 0 )
		{
			ItemLastNum = $$('#RotBanner .item').length;
		}
		
		var ItemLast = $('Item' + ItemLastNum);
		
		var ItemFx = new Fx.Morph( Item, {duration:5000, wait:false, transition: Fx.Transitions.Expo.easeInOut});
		var ItemLastFx = new Fx.Morph( ItemLast, {duration:5000, wait:false, transition: Fx.Transitions.Expo.easeInOut});
		
		ItemLastFx.start({
			'opacity': 0
		});
		
		(function()
		{
			ItemFx.start({
				'opacity': 1
			});
		}).delay(50);
		
		
		if( UmsagnirRotateNum >= $$('#RotBanner .item').length )
		{
			UmsagnirRotateNum = 0;
		}
	}
	
	if( Browser.Engine.trident != true )
	{
		
		$$('#Icon .icon').setStyle('opacity', 0.5);
		
		$$('#Icon .icon').each(function(element){
		
			element.addEvent('mouseenter', function(){
				element.set('tween', {duration: 100});
				element.tween('opacity', 1);
			});
			element.addEvent('mouseleave', function(){
				element.set('tween', {duration: 600});
				element.tween('opacity', 0.5);
			});
		});
	}
	
	
	if( $('button-wrap') )
	{
		// info@adventures.is
		if( $('book-side-panel') )
		{
			if( $(document.body).hasClass('lang-is') )
				var button_text = 'Bóka þessa ferð';
			else if( $(document.body).hasClass('lang-de') )
				var button_text = 'Tour online buchen';
			else if( $(document.body).hasClass('lang-fr') )
				var button_text = 'Reserver';
			else if( $(document.body).hasClass('lang-es') )
				var button_text = 'Reserva esta Tour';
			else
				var button_text = 'Book this tour';
			
			var BookButton = new Element('a', { 'class': 'book-this-tour', 'html': button_text })
			
			BookButton.addEvent('click', function(){
				var myFx = new Fx.Scroll(window, { 'duration': 1000, 'link': 'cancel', 'transition': Fx.Transitions.Quad.easeInOut }).toElement( $('book-side-panel') );
				
				var childs = $('book-side-panel').getChildren('.inner-wrap');
				var innerFx = new Fx.Morph(childs[0], { 'duration': 2000, 'link': 'cancel', 'transition': Fx.Transitions.Circ.easeOut  } );
				
				if( $(document.body).hasClass('site_15') || $(document.body).hasClass('site_16') )
					var BorderColor = '#ed1c24';
				else
					var BorderColor = '#2ea6d7';
				
				(function(){
					innerFx.start({
						'border-color': [BorderColor,'#F2F2F2']
					});
				}).delay(1250);
				
				(function(){
					innerFx.start({
						'border-color': [BorderColor,'#F2F2F2']
					});
				}).delay(1750);
			});
			
		}
		else
		{
			var PageTitle = $$('.Headline h1');
			
			if( PageTitle.length == 0 )
			{
				var title = '';
			}
			else
			{
				var title = PageTitle[0].get('html');
			}
			
			if( $(document.body).hasClass('site_14') )
			{
				var href = 'mailto:info@aventuresenislande.fr?subject=From aventuresensilande.fr: ';
				var lang = 'fr';
			}
			else if( $(document.body).hasClass('site_4') )
			{
				var href = 'http://www.arktischeabenteuer.de/Buchungsanfrage/';
				var lang = 'de';
			}
			else if( $(document.body).hasClass('site_2') )
			{
				var href = 'mailto:info@explore.is?subject=From explore.is: ';
				var lang = 'en';
			}
			else if( $(document.body).hasClass('site_19') )
			{
				var href = 'mailto:info@northexplorers.is?subject=From northexplorers.is: ';
				var lang = 'is';
			}
			else if( $(document.body).hasClass('site_21') )
			{
				var href = 'mailto:info@northexplorers.is?subject=From northexplorers.com: ';
				var lang = 'en';
			}
			else if( $(document.body).hasClass('site_45') )
			{
				var href = 'mailto:travel@discover-the-world.co.uk?subject=From icelandadventuretours.co.uk: ';
				var lang = 'en';
			}
			else if( $(document.body).hasClass('site_28') )
			{
				var href = 'mailto:france@glacierguides.is?subject=From glacierguides.fr: ';
				var lang = 'fr';
			}
			else if( $(document.body).hasClass('site_42') )
			{
				var href = 'mailto:info@arcticadventures.fi?subject=From arcticadventures.fi: ';
				var lang = 'fi';
			}
			else
			{
				var href = 'mailto:info@adventures.is?subject=From Adventures.is: ';
				var lang = 'en';
			}
			
			if( $(document.body).hasClass('lang-is') )
				var button_text = 'Senda fyrirspurn';
			else if( $(document.body).hasClass('lang-de') )
				var button_text = 'Buchung anfragen';
			else if( $(document.body).hasClass('lang-fr') )
				var button_text = 'Demande de reservation';
			else if( $(document.body).hasClass('lang-fi') )
				var button_text = 'L&Auml;het&Auml; varauspyynt&Ouml;';
			else
			
				var button_text = 'Send Booking Request';
			
			var BookButton = new Element('a', { 'href': href+title , 'class': 'book-this-tour email '+ lang, 'html': button_text })
		}
		
		if(!document.body.hasClass('site_7')){
			BookButton.inject( $('button-wrap') );
		}
	}
	
	
	/*
	 *	Flash Video Popup
	 */
	
	var vid = new PopVid();
	
	/*
	 *	Booking Confirm popup
	 */
	
	if( $('tour-popup-wrap') )
	{
		var WinSize = window.getScrollSize();
		var ViewSize = window.getSize();
		var PopupSize = $('tour-popup-wrap').getSize();
		
		
		$('overlay').setStyles({
			'height': WinSize.y,
			'width': WinSize.x,
			'opacity': 0
		});
		
		$('tour-popup-wrap').setStyles({
			'top': (ViewSize.y/2)-(PopupSize.y/2),
			'left': (ViewSize.x/2)-(PopupSize.x/2),
			'opacity': 0
		});
		
		$('overlay').fade('0.5');
		$('tour-popup-wrap').fade('1');
		
		window.addEvent('resize', function(){
			var WinSize = window.getScrollSize();
			var ViewSize = window.getSize();
			var PopupSize = $('tour-popup-wrap').getSize();
			
			$('overlay').setStyles({
				'height': WinSize.y,
				'width': ViewSize.x
			});
			
			$('tour-popup-wrap').setStyles({
				'top': (ViewSize.y/2)-(PopupSize.y/2),
				'left': (ViewSize.x/2)-(PopupSize.x/2)
			});
			
		});
		
	}
	
	
	/*
	if( $('pickup-check') && ( $('pickup-check').getStyle('display') != 'none' ) && $('pickup-dropdown') )
	{
		var Check = $('pickup-check').getChildren('input');
		var Dropdown = $('pickup-dropdown').getChildren('select');
		
		if( Check[0].checked )
		{
			Dropdown[0].set('disabled','');
		}
		else
		{
			Dropdown[0].set('disabled','disabled');
			$$('#pickup-dropdown select option').set('selected','');
			$$('#pickup-dropdown select option:first-child').set('selected','selected');
		}
		
		Check[0].addEvent('click', function(){
			
			if( Check[0].checked )
			{
				Dropdown[0].set('disabled','');
			}
			else
			{
				Dropdown[0].set('disabled','disabled');
				$$('#pickup-dropdown select option').set('selected','');
				$$('#pickup-dropdown select option:first-child').set('selected','selected');
			}
			
		});
		
		
	}
	
	if( $('book-side-panel') )
	{
		var rate = $('price-rate').get('html');
		var priceIsk = $('price-isk').get('html');
		var priceIsk = priceIsk.toInt();
		var priceEur = $('price-eur').get('html');
		
		var count = $$('#book-side-panel .item.number input');
		
		calculate();
		
		$$(count).addEvent('keyup', function(){
			calculate();
		});
		
		$$('#book-side-panel .item.check.valueadd input').addEvent('click', function(){
			calculate();
		});
		
		$$('#book-side-panel .button input').addEvent('click', function(e){
			//var myFx = new Fx.Scroll(window, { 'duration': 1000, 'link': 'cancel', 'transition': Fx.Transitions.Quad.easeInOut }).toElement( $('book-side-panel') );
			var pos = $('book-side-panel').getPosition();
			window.scrollTo( pos.x, pos.y );
		});
		
	}
	
	function isInteger(s) {
	  return (s.toString().search(/^-?[0-9]+$/) == 0);
	}
	
	function calculate()
	{
		var count = $$('#book-side-panel .item.number input');
		var count = count[0].get('value');
		var count = count.toInt();
		var total = 0;
		
		$$('#book-side-panel .item.check.valueadd').each(function(item){
			
			if( item.getStyle('display') != 'none' )
			{
				var childs = item.getChildren();
				
				if( childs[2] )
				{
					var price = childs[2].get('html');
					var price = price.split(' ');
					var price = price[0].toInt();
					
					if( childs[0].checked )
						total = total + price;
				}
			}
			
		});
		//console.log( total );
		var total_single_isk = (priceIsk+total).round();
		var total_single_eur = ((priceIsk+total)/ rate ).round(2);
		var total_isk = ( ( (priceIsk+total)  ) * count );
		var total_eur = ( ( (priceIsk+total) / rate ) * count );

		//if( total_isk == '' || total_isk == 0 || total_isk == null || total_isk == 'undefinded' )
		if( isInteger( total_isk ) )
		{
			
			var total_isk = total_isk.round();
			var total_eur = total_eur.round(2);
		}
		else
		{
			var total_isk = 0;
			var total_eur = 0;
			
		}
		
		//console.log( total_single_isk );
		$('price-isk').set('html', total_single_isk );
		$('price-isk-total').set('html', total_isk );
		$('price-eur').set('html', total_eur );
		$('price-eur-single').set('html', total_single_eur );
		
		$('price-isk-total').highlight();
		$('price-eur-single').highlight();
		$('price-eur').highlight();
		$('price-isk').highlight();
	}
	*/
});































