LOVEIOSController = new Class({

	initialize: function() {
		this.name = 'Ios';
		this.SetupBackgroundImages();
 	},

	SetupBackgroundImages : function() {
 
		this.Frame = $('ios_Background');
 		this.BG_WIDTH                   = 1024;                 // original width of cover
		this.BG_HEIGHT                  = 768;                  // original height of cover
		this.BG_ASPECT_RATIO            = this.BG_WIDTH / this.BG_HEIGHT;
		this.NUM_FEATURES                 = 5;                    // number of covers to load
 		this.imgWidth                   = this.BG_WIDTH;       // actual cover width
		this.imgHeight                  = this.BG_HEIGHT;      // actual cover height
   		this.imageOffsetX;                                     // how much to offset cover images (margin-left)
 		this.currentIndex               = 0;
 		this.imgURLs;                         // contains URLS to all cover images
		this.firstimageloaded;
 		$('ios_Background').setStyles({
			'width':  window.getSize().x,
			'height': window.getSize().y,
			'left': 0
		});
		
		this.imgURLs = new Array();
		this.imgURLs = featureplaylistBackgroundLowVersionIos;
		for (var i=0; i<this.imgURLs.length; i++) {
 			var newImageContainer = new Element('div.ios-imagesContainers');
			newImageContainer.hide();
			newImageContainer.inject('ios_Background');
  		}

		this.resizeImages();
 		// load first cover only
		this.loadImgAt(0);
  		iosSlideShowTimeout = null;
	 

	},
	

	loadImgAt: function($index) {
 
 		if ($$('.ios-imagesContainers img')[$index] == undefined) {
 			var img = Asset.image(this.imgURLs[$index].url, {
				'class': 'ios-images',
				onLoad: function(result) {
 					result.setStyles({
						'width': this.imgHeight,
						'height': this.imgWidth,
						'margin-left': this.imageOffsetX
					});
  					// inject img tag into container
					result.inject($$('.ios-imagesContainers')[$index], 'bottom');
					
					if(!this.firstimageloaded){
					 this.firstimageloaded = true;
					 Director.iosFirstImageDidLoadAtLaunchHandler();
					}
 					
				}.bind(this)
			});
		}
	},
	
	presentiosBackgroundGallery : function()
	{
 		$('ios_Background').view('show');
		$('Feature_Video').view('hide');
		$('videolines').view('show');
		$$('.ios-imagesContainers')[0].view('in');
 		// show current cover first
		var self = iosController;
		self.nextInSlideShow();
   
 		// Load remaining covers (if they haven't been loaded yet)
		for (var i=1; i<self.imgURLs.length; i++) {
			self.loadImgAt(i);
		}	
 	},
	
 
 
	
	
	nextInSlideShow: function() {
		var self = iosController;
		var i = self.currentIndex +1;
		if(i >= self.imgURLs.length) i = 0;
		if ($$('.ios-imagesContainers img')[i] != undefined){
 			var currentcover = $$('.ios-imagesContainers')[self.currentIndex]
			var nextcover = $$('.ios-imagesContainers')[i]
			currentcover.view('out');
			nextcover.view('in');
			self.currentIndex = i;
 		}
		
		iosSlideShowTimeout = setTimeout('iosController.nextInSlideShow()', 15000);
	
	},
	
	
	
	 
	recalculateDimensions : function() {
 
		// get screen aspect ratio
		var screenAspectRatio = window.getSize().x / window.getSize().y;
		var aspectRatio;
  		// determine screen orientation
		if (this.BG_ASPECT_RATIO > screenAspectRatio) {
			aspectRatio = this.BG_WIDTH / this.BG_HEIGHT;
			this.imgHeight = window.getSize().y * aspectRatio;
			this.imgWidth = window.getSize().y;
		} else {
			aspectRatio = this.BG_HEIGHT / this.BG_WIDTH;
			this.imgHeight = window.getSize().x;
			this.imgWidth = window.getSize().x * (aspectRatio);
		}

 		this.imageOffsetX = -(Math.abs(window.getSize().x - this.imgHeight) / 2);
	},

 
	
	
	resizeImages: function() {
 
		this.recalculateDimensions();

		$('ios_Background').setStyles({
			'width': window.getSize().x,
			'height': window.getSize().y,
			'left':0,
			'overflow':'hidden'
		});

		$$('.ios-imagesContainers').each(function(items, index) {
			items.setStyles({
				'width': window.getSize().x,
				'height': window.getSize().y,
				'overflow':'hidden' ,
				'left': 0 });
		});

		$$('.ios-images').setStyles({
			'width': this.imgHeight,
			'height': this.imgWidth,
			'margin-left': this.imageOffsetX
		});
	},




	directorDidRequestResize: function() {
		// Rescale all cover images loaded
		this.resizeImages();
   	},

 
	directorDidChangeVersionControl : function(version) {

	},
 

 

	closeScene: function() {
 		this.isHorizontallyScrolling = false;
 		this.resizeImages();
  	}
});
