Event.observe(document, 'dom:loaded', function() {
	if ($('thumbs')) Photo.init()
  if ($('downloadsWrapper')) Wall.init()
	if ($('tech_switcher')) Tech.init ()
	Pagings.init()
	PhoneShops.init()
	SwitchLanguage.init()
	MapEmbed.init()
	Startpage.init()
	Startpage.timer()
})

var Startpage = {
	init: function() {
		if ($('phoneBlack') && $('phoneRave') && $('buttonBlack') && $('buttonRave')) {
			$('buttonBlack').observe('click', this.switchToBlackStyle.bind(this))
			$('buttonRave').observe('click', this.switchToRaveStyle.bind(this))
			$('buttonMoscow').observe('click', this.switchToMoscowStyle.bind(this))
			$('buttonLove').observe('click', this.switchToLoveStyle.bind(this))
		}
	},
	timer: function(){
		if ($('phoneBlack') && $('phoneRave') && $('buttonBlack') && $('buttonRave')) {
			$('phoneBlack').timeout = setTimeout(function(){
				if ($('startpage').className == 'startpage love') {
					Startpage.switchToMoscow()
				} else if ($('startpage').className == 'startpage moscow') {
					Startpage.switchToBlack()
				} else if ($('startpage').className == 'startpage black') {
					Startpage.switchToRave()
				} else if ($('startpage').className == 'startpage rave') {
					Startpage.switchToLove()
				}
				Startpage.timer()
			}, 25000)
		}
	},
	switchToLoveStyle: function() {
		if ($('phoneBlack').timeout) clearTimeout($('phoneBlack').timeout)
		Startpage.switchToLove()
	},
	switchToMoscowStyle: function() {
		if ($('phoneBlack').timeout) clearTimeout($('phoneBlack').timeout)
		Startpage.switchToMoscow()
	},
	switchToBlackStyle: function() {
		if ($('phoneBlack').timeout) clearTimeout($('phoneBlack').timeout)
		Startpage.switchToBlack()
	},
	switchToRaveStyle: function() {
		if ($('phoneBlack').timeout) clearTimeout($('phoneBlack').timeout)
		Startpage.switchToRave()
	},
	switchToMoscow: function() {
		$('phoneMoscow').setStyle({display: 'block'})
		new Effect.Opacity($('phoneBlack'), {to: 0, duration: 0.2 })
		new Effect.Opacity($('phoneMoscow'), {to: 1, duration: 0.2 })
		new Effect.Opacity($('phoneLove'), {to: 0, duration: 0.2 })
		new Effect.Opacity($('phoneRave'), {to: 0, duration: 0.2, afterFinish: function(){
			$('phoneBlack').setStyle({display: 'none'})
			$('phoneRave').setStyle({display: 'none'})
			$('phoneLove').setStyle({display: 'none'})
		}})
		$('startpage').addClassName('moscow')
		$('startpage').removeClassName('black')
		$('startpage').removeClassName('love')
		$('startpage').removeClassName('rave')
		$('photoHandler').innerHTML = ''
	},
	switchToLove: function() {
		$('phoneLove').setStyle({display: 'block'})
		new Effect.Opacity($('phoneLove'), {to: 1, duration: 0.2, afterFinish: function(){
			$('phoneBlack').setStyle({display: 'none'})
			$('phoneRave').setStyle({display: 'none'})
			$('phoneMoscow').setStyle({display: 'none'})
		}})
		$('startpage').addClassName('love')
		$('startpage').removeClassName('black')
		$('startpage').removeClassName('rave')
		$('startpage').removeClassName('moscow')
		$('photoHandler').innerHTML = ''
	},
	switchToRave: function() {
		$('phoneRave').setStyle({display: 'block'})
		new Effect.Opacity($('phoneBlack'), {to: 0, duration: 0.2 })
		new Effect.Opacity($('phoneRave'), {to: 1, duration: 0.2 })
		new Effect.Opacity($('phoneLove'), {to: 0, duration: 0.2 })
		new Effect.Opacity($('phoneMoscow'), {to: 0, duration: 0.2, afterFinish: function(){
			$('phoneBlack').setStyle({display: 'none'})
			$('phoneMoscow').setStyle({display: 'none'})
			$('phoneLove').setStyle({display: 'none'})
		}})
		$('startpage').addClassName('rave')
		$('startpage').removeClassName('black')
		$('startpage').removeClassName('moscow')
		$('startpage').removeClassName('love')
		$('photoHandler').innerHTML = ''
	},
	switchToBlack: function() {
		$('phoneBlack').setStyle({display: 'block'})
		new Effect.Opacity($('phoneMoscow'), {to: 0, duration: 0.2 })
		new Effect.Opacity($('phoneRave'), {to: 0, duration: 0.2 })
		new Effect.Opacity($('phoneLove'), {to: 0, duration: 0.2 })
		new Effect.Opacity($('phoneBlack'), {to: 1, duration: 0.2, afterFinish: function(){
			$('phoneRave').setStyle({display: 'none'})
			$('phoneMoscow').setStyle({display: 'none'})
			$('phoneLove').setStyle({display: 'none'})
		}})
		$('startpage').removeClassName('rave')
		$('startpage').removeClassName('moscow')
		$('startpage').removeClassName('love')
		$('startpage').addClassName('black')
		$('photoHandler').innerHTML = ''
	}
}

var PhoneShops = {
	init: function() {
		if ($$('div.buy div.rightArrow') && $$('div.buy div.leftArrow') && $$('div.paging ul') && $('buyNow')) {
			$$('div.buy div.rightArrow')[0].observe('click', this.checkShops.bind(this))
			$$('div.buy div.leftArrow')[0].observe('click', this.checkShops.bind(this))
			this.paging = $$('div.paging ul')[0]
			this.shopsContainer = $$('div.buy div.right')[0]
		}
	},
	checkShops: function() {
		if (parseInt(this.paging.getStyle('left')) == '-455' && $$('div.buy div.rightArrow')[0].className != 'rightArrow disabledArrow') {
			this.shopsContainer.addClassName('m1')
			this.shopsContainer.removeClassName('m2')
			this.shopsContainer.removeClassName('m3')
		} else if ((parseInt(this.paging.getStyle('left')) == 0 || parseInt(this.paging.getStyle('left')) == '-910') && $$('div.buy div.leftArrow')[0].className != 'leftArrow disabledArrow' && $$('div.buy div.rightArrow')[0].className != 'rightArrow disabledArrow'){
			this.shopsContainer.addClassName('m2')
			this.shopsContainer.removeClassName('m1')
			this.shopsContainer.removeClassName('m3')
		} else if ( parseInt(this.paging.getStyle('left')) <= 0 && $$('div.buy div.leftArrow')[0].className != 'leftArrow disabledArrow'){
			this.shopsContainer.addClassName('m3')
			this.shopsContainer.removeClassName('m2')
			this.shopsContainer.removeClassName('m1')
		}
	}
}

var MapEmbed = {
	init: function() {
		this.body = $$('div.body')[0]
		$$('body')[0].insert({top: '<div class="mapZoom"><div class="container"></div></div>'})
		this.embedContainer = $$('div.mapZoom')[0]
		this.hideMap()
		this._hideMap = this.hideMap.bindAsEventListener(this)

		$$('div.mapEmbed').each(function(embed){
			var letter = embed.up('li').down('div.letter')
			var shopName = embed.up('li').down('h3')
			letter.addClassName('clickable')
			letter.mapSrc = embed.down('a.map').href
			letter.showMap = function(event) {
				event.stop()
				MapEmbed.showMap(this.mapSrc)
			}
			letter.observe('click', letter.showMap.bindAsEventListener(letter))
			shopName.addClassName('clickable')
			shopName.mapSrc = embed.down('a.map').href
			shopName.showMap = function(event) {
				event.stop()
				MapEmbed.showMap(this.mapSrc)
			}
			shopName.observe('click', shopName.showMap.bindAsEventListener(shopName))
		}.bind(this))
	},
	hideMap: function() {
		this.body.stopObserving('click', this._hideMap)
		this.body.setStyle({opacity: 1})
		this.body.removeClassName('clickable')
		this.embedContainer.setStyle({display: 'none'})
	},
	showMap: function(mapSrc) {
		this.embedContainer.childElements().invoke('remove')
		this.embedContainer.insert(this.generateMap(mapSrc))
		this.embedContainer.down('.close').observe('click', this._hideMap)
		new Effect.Opacity(this.body, {to: 0.2, duration: 0.5, afterFinish: function(){
			$$('div.mapZoom')[0].setStyle({display: 'block'})
		}})
		this.body.observe('click', this._hideMap)
		this.body.addClassName('clickable')
	},
	generateMap: function(src) {
		return '<div class="close"></div><iframe width="640" height="520" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="'+src+'"></iframe>'
	}
}

var Preloader = {
	preload: function(images) {
		$A(images).each(function(imageToPreload){
			var img = new Image()
			img.src = imageToPreload
		})
	}
}


var Pagings = {
	init: function() {
		$$('div.paging').each(function(paging){
			new Paging(paging)
		}.bind(this))
	}
}
var Paging = Class.create({
	initialize: function(element) {
		this.pagers = element.down('.pager').childElements()
		this.leftArrow = element.down('.leftArrow')
		this.rightArrow = element.down('.rightArrow')
		this.list = element.down('ul')

		this.stepWidth = this.getFullElementWidth(this.list.down('li'))
		this.currentOffset = this.list.getStyle('left') ? parseInt(this.list.getStyle('left')) : 0

		this.maxOffset = 0
		this.minOffset = -this.stepWidth*(this.list.childElements().size()-1)

		this.setCurrentPager()

		this.leftArrow.observe('click', this.scrollLeft.bind(this))
		this.rightArrow.observe('click', this.scrollRight.bind(this))

		this.pagers.each(function(pager){
			pager.observe('click', this.clickPager.bindAsEventListener(this))
		}.bind(this))

		this.disableDoubleClick(this.leftArrow)
		this.disableDoubleClick(this.rightArrow)

		this.checkArrows()
	},
	clickPager: function(event) {
		this.scrollToIndex(event.element().previousSiblings().size())
	},
	setCurrentPager: function() {
		this.pagers.each(function(p){ p.removeClassName('current') })
		if (this.pagers[this.currentIndex()]) this.pagers[this.currentIndex()].addClassName('current')
	},
	currentIndex: function() {
		return -this.currentOffset / this.stepWidth
	},
	disableDoubleClick: function(element) {
		element.observe('mousedown', function(e){e.stop()})
	},
	getFullElementWidth: function(el) {
		return (el.getWidth() + parseInt(el.getStyle('padding-left')) + parseInt(el.getStyle('padding-right')) + parseInt(el.getStyle('margin-left')) + parseInt(el.getStyle('margin-right')))
	},
	scrollLeft: function(){
		this.doScroll(this.stepWidth)
	},
	scrollRight: function(){
		this.doScroll(-this.stepWidth)
	},
	scrollToIndex: function(index) {
		this.doScroll((this.currentIndex() - index) * this.stepWidth)
	},
	doScroll: function(offset) {
		if (!this.scrollEffect || this.scrollEffect.state == 'finished') {
			this.currentOffset = this.offsetLimits(this.currentOffset + offset)
			// console.log(this.currentOffset + offset)
			if (this.scrollEffect) this.scrollEffect.cancel()
			this.scrollEffect = new Effect.Morph(this.list, {style: 'left: '+this.currentOffset+'px', duration: 0.3})
			this.setCurrentPager()
			this.checkArrows()
		}
	},
	offsetLimits: function(offset) {
		return Math.max(this.minOffset, Math.min(this.maxOffset, offset))
	},
	checkArrows: function() {
		this.rightArrow.removeClassName('disabledArrow')
		this.leftArrow.removeClassName('disabledArrow')
		if (this.currentIndex() == this.pagers.size()-1) this.rightArrow.addClassName('disabledArrow')
		if (this.currentIndex() == 0) this.leftArrow.addClassName('disabledArrow')
	}
})


var Photo = {
	init: function() {
		this.container = $('thumbsWrapper')
		this.thumbs = this.container.select('.photo')
		this.videosCheck = this.container.select('.video')
		this.photosCheck = this.container.select('.photo')
		
		if(!this.videosCheck.first()){
			$('videoLink').setStyle('color: #2e2e2e;')
		}
		if (!this.thumbs.first()){
			$('photoLink').setStyle('color: #2e2e2e;')
			
			this.thumbs = this.container.select('.video')
			this.currentEvent = $('videoLink')
			this.currentEvent.addClassName('unactiveLink')
			this.thumbs = this.container.select(".video")
			this.thumbs.each(function(video){
				video.setStyle('display: block')
			})

			this.setCurrentThumb(this.thumbs.first())

		}else{
			this.currentEvent = $('photoLink')
			this.currentEvent.addClassName('unactiveLink')
		}

		this.setCurrentThumb(this.thumbs.first())

		$('videoLink').observe('click', this.changeToVideos.bind(this))
		$('photoLink').observe('click', this.changeToPhotos.bind(this))
		$('leftArrow').observe('click', this.previousThumb.bind(this))
		$('rightArrow').observe('click', this.nextThumb.bind(this))
		$('leftArrow').addClassName('unactiveArrow')

		$('leftArrow').observe('mousedown', function(e){e.stop()})
		$('rightArrow').observe('mousedown', function(e){e.stop()})

		if (this.thumbs.size() == 1){
			$('rightArrow').addClassName('unactiveArrow')
		}
		
		for (i = 0; i < this.thumbs.size()/8; i++) {
			$('pageLinks').insert('<a class="page" href="#"></a> ')
		}
		
		this.pages = $('pageLinks').select('a')
		if (this.pages.size() == 1) $('pageLinks').hide()
		this.currentPage =this.pages.first()
		this.currentPage.addClassName('unactivePage')
		this.animation = true
		this.pages.each(function(page){
			page.observe('click', this.changePage.bind(this))
		}.bind(this))
		
		this.thumbs.each(function(li){
			li.photoPath = li.down('a').href
			Preloader.preload([li.photoPath])
			li.down('a').observe('click', this.pressedThumb.bind(this))
		}.bind(this))
		this.insertMedia()
	},
	setCurrentThumb: function(obj) {
		if (this.currentThumb) this.currentThumb.removeClassName('currentThumb')
		this.currentThumb = obj
		this.currentThumb.addClassName('currentThumb')
	},
	pressedThumb: function(event) {
		event.stop()
		this.setCurrentThumb(event.findElement('li'))
		this.checkArrows()
		this.insertMedia()
	},
	checkArrows: function() {
		$('leftArrow').removeClassName('unactiveArrow')
		$('rightArrow').removeClassName('unactiveArrow')
		if (this.currentThumb == this.thumbs.last()){
			$('rightArrow').addClassName('unactiveArrow')
		}
		if (this.currentThumb == this.thumbs.first()){
			$('leftArrow').addClassName('unactiveArrow')
		}
	},
	nextThumb: function(event) {
		event.stop()
		if (this.currentThumb != this.thumbs.last()){

			this.setCurrentThumb(this.thumbs[this.thumbs.indexOf(this.currentThumb) + 1])
			this.insertMedia()
			this.checkArrows()

			if (this.thumbs.indexOf(this.currentThumb) % 8 == 0) {
				this.currentPage.removeClassName('unactivePage')
				this.currentPage = this.pages[this.pages.indexOf(this.currentPage)+1]
				this.currentPage.addClassName('unactivePage')
				new Effect.Move($('thumbs'), { x: -870 , y: 0 }); return false;
			}
		}
	},
	previousThumb: function(event) {
		event.stop()
		if (this.currentThumb != this.thumbs.first()){

			this.setCurrentThumb(this.thumbs[this.thumbs.indexOf(this.currentThumb) - 1])
			this.insertMedia()
			this.checkArrows()

			if (this.thumbs.indexOf(this.currentThumb) % 8 == 7) {
				this.currentPage.removeClassName('unactivePage')
				this.currentPage = this.pages[this.pages.indexOf(this.currentPage)-1]
				this.currentPage.addClassName('unactivePage')
				new Effect.Move($('thumbs'), { x: 870 , y: 0 }); return false;
			}
		}
	},
	changePage: function(event)	{
		event.stop()
			if (this.animation == true){
			this.oldPage = this.currentPage
			this.oldPage.removeClassName('unactivePage')
			this.currentPage = event.findElement('a')
			this.currentPage.addClassName('unactivePage')

			this.setCurrentThumb(this.thumbs[this.pages.indexOf(this.currentPage)*8])

			this.checkArrows()

			this.moveValue = (this.pages.indexOf(this.oldPage) - this.pages.indexOf(this.currentPage))*870
			this.animation = false
			new Effect.Move($('thumbs'), { x: this.moveValue , y: 0,  afterFinish: function(){ this.animation = true }.bind(this)  }); return false;
		}
	},

	changeToVideos: function(event) {
		event.stop()
		if (this.currentEvent != $('videoLink') & this.videosCheck.first() != null){
			this.currentEvent.removeClassName('unactiveLink')
			this.currentEvent = $('videoLink')
			this.currentEvent.addClassName('unactiveLink')
			this.thumbs.each(function(photo) {
				photo.setStyle('display: none')
			})

			this.thumbs = this.container.select(".video")
			this.thumbs.each(function(video){
				video.setStyle('display: block')
			})

			this.setCurrentThumb(this.thumbs.first())

			$('thumbs').setStyle('left: 0;')
			$('leftArrow').addClassName('unactiveArrow')

			if (this.thumbs.size() == 1) {
				$('rightArrow').addClassName('unactiveArrow')
			} else {
				$('rightArrow').removeClassName('unactiveArrow')
			}

			$('pageLinks').select('a').each(function(pageLink){
				pageLink.remove()
			})

			for (i = 0; i < this.thumbs.size()/8; i++) {
				$('pageLinks').insert('<a class="page" href="#"></a> ')
			}
			this.pages = $('pageLinks').select('a')
			this.currentPage = this.pages.first()
			this.currentPage.addClassName('unactivePage')
			this.animation = true
			this.pages.each(function(page){
				page.observe('click', this.changePage.bind(this))
			}.bind(this))

			this.thumbs.each(function(li){
					li.photoPath = li.down('a').href
					li.down('a').observe('click', this.pressedThumb.bind(this))
				}.bind(this))
			this.insertMedia()
		}
	},

	insertMedia: function() {
		if (this.currentThumb.hasClassName("video")) {
			if (!this.currentThumb.down('a.hiddenLink') || !this.currentThumb.down('a.thumbnail').href ){
				$('sizeLinksContainer').hide()
			}else{
				$('sizeLinksContainer').show()
				$('large').observe('click', this.insertLargeVideo.bind(this))
				$('small').observe('click', this.insertSmallVideo.bind(this))
			}
			if (!this.currentThumb.down('a.thumbnail').href){
				this.insertSmallVideo()
			}else{
				this.insertLargeVideo()
			}
		} else {
			if ($('currentPhoto')) $('currentPhoto').remove()
			$('photoHandler').insert('<img id="currentPhoto" width="722" height="405" src="'+ this.currentThumb.photoPath +'" />')
		}
	},

	insertLargeVideo: function() {
		if ($('currentPhoto')) $('currentPhoto').remove()
		$('photoHandler').removeClassName('smallVideo')
		$('photoHandler').addClassName('largeVideo')
		$('photoHandler').insert({top: '<div id="currentPhoto"></div>'})
		swfobject.embedSWF("flash/videoplayer.swf", "currentPhoto", "640", "400", "9.0.0", null, {video: this.currentThumb.photoPath})
	},
	insertSmallVideo: function() {
		if ($('currentPhoto')) $('currentPhoto').remove()
		$('photoHandler').addClassName('smallVideo')
		$('photoHandler').removeClassName('largeVideo')
		$('photoHandler').insert({top: '<div id="currentPhoto"></div>'})
		swfobject.embedSWF("flash/videoplayer.swf", "currentPhoto", "320", "240", "9.0.0", null, {video: this.currentThumb.down('a.hiddenLink').href})
	},

	changeToPhotos: function(event){
		event.stop()
		if (this.currentEvent != $('photoLink') & this.photosCheck.first() != null){
			$('photoHandler').removeClassName('smallVideo')
			$('photoHandler').removeClassName('largeVideo')
			this.currentEvent.removeClassName('unactiveLink')
			this.currentEvent = $('photoLink')
			this.currentEvent.addClassName('unactiveLink')
			this.thumbs.each(function(photo){
				photo.setStyle('display: none')
			})

			this.thumbs = this.container.select('[class="photo"]')
			this.thumbs.each(function(photo){
				photo.setStyle('display: block')
			})

			this.setCurrentThumb(this.thumbs.first())

			$('thumbs').setStyle('left: 0;')
			$('leftArrow').addClassName('unactiveArrow')
			if (this.thumbs.size() == 1){
				$('rightArrow').addClassName('unactiveArrow')
			}else{
				$('rightArrow').removeClassName('unactiveArrow')
			}

			$('pageLinks').select('a').each(function(pageLink){
				pageLink.remove()
			})
			for (i = 0; i < this.thumbs.size()/8; i++) {
				$('pageLinks').insert('<a class="page" href="#"></a> ')
			}
			this.pages = $('pageLinks').select('a')
			this.currentPage =this.pages.first()
			this.currentPage.addClassName('unactivePage')
			this.animation = true
			this.pages.each(function(page){
				page.observe('click', this.changePage.bind(this))
			}.bind(this))

			this.thumbs.each(function(li){
				li.photoPath = li.down('a').href
				Preloader.preload([li.photoPath])
				li.down('a').observe('click', this.pressedThumb.bind(this))
			}.bind(this))

			this.insertMedia()
		}
	}
	
}


var Wall = {
	init: function() {
		$('leftArrow').addClassName('unactiveArrow')
		this.container = $('downloadsWrapper')
		this.walls = this.container.select(".wallpaper")
		this.audioCheck = this.container.select(".audio")
		if ( this.audioCheck.first() == null ){
			$('audioLink').setStyle('color: grey;')
		}
		$('leftArrow').observe('click', this.previousPage.bind(this))
		$('rightArrow').observe('click', this.nextPage.bind(this))
		$('audioLink').observe('click', this.changeToRingtones.bind(this))
		$('wallLink').observe('click', this.changeToWallpapers.bind(this))
		$('helpLink').observe('click', this.changeToHelp.bind(this))
		
		$('leftArrow').observe('mousedown', function(e){e.stop()})
		$('rightArrow').observe('mousedown', function(e){e.stop()})
		
		
		this.animation = true
		this.currentDownloadsType = $('wallLink')
		this.currentDownloadsType.addClassName('unactiveLink')
		for (i = 0; i < this.walls.size()/4; i++) {
			$('pageLinks').insert('<a class="page" href="#"></a> ')
		}
		$('pageLinks').setStyle('width:'+ $('pageLinks').getWidth() +'px;')
		this.pages = $('pageLinks').select('a')
		this.currentPage =this.pages.first()
		this.currentPage.addClassName('unactivePage')
		this.pages.each(function(page){
			page.observe('click', this.changePage.bind(this))
		}.bind(this))
		
		this.walls.each(function(li){
			li.wallPath = li.down('a').href
			Preloader.preload([li.wallPath])
			
			
		}.bind(this))
		
	},
	nextPage: function(event) {
		event.stop()
		$('leftArrow').removeClassName('unactiveArrow')
		if (this.currentPage != this.pages.last() & this.animation == true) {
			this.currentPage.removeClassName('unactivePage')
			this.currentPage = this.pages[this.pages.indexOf(this.currentPage)+1]
			this.currentPage.addClassName('unactivePage')
			if (this.currentPage == this.pages.last()) {
				$('rightArrow').addClassName('unactiveArrow')
			}
			this.animation = false
			new Effect.Move($('wallpapers'), { x: -830 , y: 0, afterFinish: function(){ this.animation = true }.bind(this) }); return false;
		}
	},
	previousPage: function(event) {
		event.stop()
		$('rightArrow').removeClassName('unactiveArrow')
		if (this.currentPage != this.pages.first() & this.animation == true) {
			this.currentPage.removeClassName('unactivePage')
			this.currentPage = this.pages[this.pages.indexOf(this.currentPage)-1]
			this.currentPage.addClassName('unactivePage')
			if (this.currentPage == this.pages.first()) {
				$('leftArrow').addClassName('unactiveArrow')
			}
			this.animation = false
			new Effect.Move($('wallpapers'), { x: 830 , y: 0, afterFinish: function(){ this.animation = true }.bind(this) }); return false; 
			
		}
	},	
	changePage: function(event)	{
		event.stop()
		if ( this.animation==true ){
			$('leftArrow').removeClassName('unactiveArrow')
			$('rightArrow').removeClassName('unactiveArrow')
			this.oldPage = this.currentPage
			this.currentPage.removeClassName('unactivePage')
			this.currentPage = event.findElement('a')
			this.currentPage.addClassName('unactivePage')
			this.moveValue = (this.pages.indexOf(this.oldPage) - this.pages.indexOf(this.currentPage))*830
			if (this.currentPage == this.pages.first()) {
				$('leftArrow').addClassName('unactiveArrow')
			}
			
			if (this.currentPage == this.pages.last()) {
				$('rightArrow').addClassName('unactiveArrow')
			}
			this.animation = false
			new Effect.Move($('wallpapers'), { x: this.moveValue , y: 0, afterFinish: function(){ this.animation = true }.bind(this) }); return false;
		}
		
	},
	changeToRingtones: function(event) {
		event.stop()
		if ( this.currentDownloadsType != $('audioLink') & this.audioCheck.first() != null ){
			$('downloadsTitle').setStyle("visibility: visible;")
			$('help').setStyle("display: none;")
			$('downloads').show()
			this.currentDownloadsType.removeClassName('unactiveLink')
			this.currentDownloadsType = $('audioLink')
			this.currentDownloadsType.addClassName('unactiveLink')
			$('leftArrow').setStyle('display: none')
			$('rightArrow').setStyle('display: none')
			$('pageLinks').select('a').each(function(pageLink){
				pageLink.remove()
			})

			this.walls.each(function(wall){
				wall.setStyle('display: none')
			})
		
			this.walls = this.container.select(".audio")
			this.walls.each(function(audio){
				audio.setStyle('display: block')
			})
			this.currentPage.removeClassName('currentPage')
			$('wallpapers').setStyle('left: 0; width: 930px;')
			$('downloadsWrapper').setStyle('width: 930px;')

		}
	},
	changeToWallpapers: function(event) {
		event.stop()
		if ( this.currentDownloadsType != $('wallLink')){
			$('downloadsTitle').setStyle("visibility: visible;")
			$('help').setStyle("display: none;")
			$('downloads').show()
			this.currentDownloadsType.removeClassName('unactiveLink')
			this.currentDownloadsType = $('wallLink')
			this.currentDownloadsType.addClassName('unactiveLink')
			$('leftArrow').setStyle('display: block')
			$('rightArrow').setStyle('display: block')

			this.walls.each(function(wall){
				wall.setStyle('display: none')
			})
		
			this.walls = this.container.select(".wallpaper")
			this.walls.each(function(wall){
				wall.setStyle('display: block')
			})
			this.currentPage.removeClassName('currentPage')
			$('wallpapers').setStyle('left: 0; width: 1000000px;')
			$('downloadsWrapper').setStyle('width: 790px;')
			for (i = 0; i < this.walls.size()/4; i++) {
				$('pageLinks').insert('<a class="page" href="#"></a> ')
			}
			$('pageLinks').setStyle('width:'+ $('pageLinks').getWidth() +'px;')
			this.pages = $('pageLinks').select('a')
			this.currentPage =this.pages.first()
			this.currentPage.addClassName('unactivePage')
			this.pages.each(function(page){
				page.observe('click', this.changePage.bind(this))
			}.bind(this))
			
		}
	},
	changeToHelp: function(event) {
		event.stop()
		if ( this.currentDownloadsType != $('helpLink')){
			this.currentDownloadsType.removeClassName('unactiveLink')
			this.currentDownloadsType = $('helpLink')
			this.currentDownloadsType.addClassName('unactiveLink')
			$('downloadsTitle').setStyle("visibility: hidden;")
			$('downloads').hide()
			$('help').setStyle("display: block;")
		}
	}
}
var Tech = {
		init: function () {
			$('spec_3g').hide()
			$('switch3gs').observe('click',function(){
				$('switch3gs').addClassName('active3gs')
				$('switch3g').removeClassName('active3g')
				$('spec_3g').hide()
				$('spec_3gs').show()
				$('spec_arrow').setStyle('left: 380px !important;')
			})
			$('switch3g').observe('click',function(){
				$('switch3g').addClassName('active3g')
				$('switch3gs').removeClassName('active3gs')
				$('spec_3gs').hide()
				$('spec_3g').show()
				$('spec_arrow').setStyle('left: 580px !important;')
			})
		}
}

var SwitchLanguage = {
	init: function () {
		switcher = $('switchLang')
		langContainer = $('allLanguages')
		contentBody = $('body')
		if (switcher) {
			switcher.observe('click', this.showLanguages.bind(this))
			document.observe('click', this.hideLanguages.bind(this))
		}
	},
	showLanguages: function() {
		if (contentBody) {
			new Effect.Opacity(contentBody, {to: 0.2, duration: 0.5, afterFinish: function(){
				$('allLanguages').setStyle({display: 'block'})
			}})
		}
	},
	hideLanguages: function(e) {
		element = e.element()
		if (element != langContainer && element != langContainer.down('h2') || element == langContainer.down('.close')) {
			if (langContainer.getStyle('display') == 'block') {
				langContainer.setStyle({display: 'none'})
				new Effect.Opacity(contentBody, {to: 1, duration: 0.5})
			}
		}
	}
}