/* Release 5.2 */

/*@FILE INFORMATION
----------------------------------------
Author:		United Airlines MileagePlus Team 2010 
File:		mp_classes_1.0.0.css 
Created:	4/12/10 8:23 PM
Updated:	4/12/10 8:23 PM

/*@END--------------------------------*/


//CREATE NAMESPACE
var mp = {};


//MILEAGE TIP
mp.MileageTip = function(/*array*/array, /*jquery*/jquery){
	this.array = array;
	this.jquery = jquery;
	this.initialize();
		
}
mp.MileageTip.prototype = {
	//PRIVATE
	initialize: function(){
		this.index = 0;
		this.jquery.html(this.getHtml());
	
	},
	//PRIVATE
	getHtml: function(){			
		return '<a href="' + this.array[this.index].linkUrl + '">' + this.array[this.index].linkText + '<\/a>';
	
	},
	//PUBLIC
	nextTip: function(){
		var $this = this;
		this.index = ++this.index % this.array.length;
		this.jquery.animate({opacity:0}, function(){ $(this).html($this.getHtml()).animate({opacity:1}) });
	
	},
	//PUBLIC
	setArray: function(array){
		this.array = array;
		this.index = -1;
		this.nextTip();
	
	}
	
}


//CAROUSEL
mp.Carousel = {
	//PUBLIC
	initialize: function(/*array*/array, /*jquery*/jquery){
		jquery.jcarousel({
			wrap: 'circular',
			itemVisibleInCallback: {onBeforeAnimation: visibleInListener},
			itemVisibleOutCallback: {onAfterAnimation: visibleOutListener}
		
		});
		function visibleInListener(carousel, item, i, state, evt){
			var index = carousel.index(i, array.length) - 1;
			var html = '<a href="' + array[index].linkUrl +'"><img src="' + array[index].imageSource + '" width="90" height="90" \/>' + array[index].linkText + '<\/>'
			carousel.add(i, html);
				
		}
		function visibleOutListener(carousel, item, i, state, evt){
			carousel.remove(i);
				
		}

	}
			
};


//TOGGLE CLASS
mp.Toggle = function(/*jquery*/jquery, /*string*/klass, /*function*/listener){
	this.jquery = jquery;
	this.klass = klass;
	this.listener = listener;
	this.initialize();

}
mp.Toggle.prototype = {
	//PRIVATE
	initialize: function(){
		var $this = this;
		this.index = 0;
		this.jquery.eq(this.index).toggleClass(this.klass);
		this.jquery.bind('click', function(){
			var $$this = $(this);
			var index = $$this.index();
			if(index != $this.index){
				$this.jquery.eq($this.index).toggleClass($this.klass);
				$this.index = index;
				$$this.toggleClass($this.klass);
				$this.listener($this.index);
														
			}
						
		});
	
	}

}


//PAGINATION
mp.Pagination = {
	//PUBLIC
	initialize: function(/*array*/array, /*jquery*/jquery){
		var l=array.length, i=0, f=document.createDocumentFragment(), li;
		do{
			li = document.createElement('li');	
			li.appendChild(document.createTextNode(i+1));
			f.appendChild(li);
					
		}while(++i < l);
		jquery.append(f);
				
	}
	
};


//SHELL
mp.Shell = {
	define: function(/*array*/elements, /*integer*/sections, /*integer*/index){
		var l = elements.length,			
		d = document,						
		f = d.createDocumentFragment(),		
		e = d.createElement('div'),			
		a = [],
		i = 0,
		w, x, y, z;							

		
		if(l){
		
			//::
			do{
				w = elements[i];
				f = f.cloneNode(false);
				while(w.hasChildNodes()){
					x = w.removeChild(w.firstChild);
					if(x.nodeType === 1) f.appendChild(x);
								
				}
				a.push(f);
			
			}while(++i < l);
			
			
			//::				
			i = 0;
			f = f.cloneNode(false);
			do{
				//Shell section number
				w = i+1;	
				
				//nth element 3
				x = e.cloneNode(false);
				x.className = ['s', w, 'n3 n3'].join('');
				
				//nth element 2
				y = e.cloneNode(false);
				y.className = ['s', w, 'n2 n2'].join('');
				y.appendChild(x);
				
				//nth element 1
				z = e.cloneNode(false);
				z.className = ['s', w, 'n1 n1'].join('');
				z.appendChild(y);
				
				//Append section to shell fragment
				f.appendChild(z);
						
			}while(++i < sections);


			//::
			i = l-1;
			w = index-1;
			do{
				//Clone shell fragment and all child nodes
				x = f.cloneNode(true);
				//Append extracted child nodes into corresponding shell section
				x.childNodes[w].firstChild.firstChild.appendChild(a[i]);
				//Append shell fragment
				elements[i].appendChild(x);	
								
			}while(i--);
		
		}

	}
		
};

//Global Popup
function openPopup(mbURL)
{   
var windowObjectReference = window.open(mbURL,"","resizable=1,fullscreen=1,scrollbars=1,status=1,toolbar=1,menubar=1,personalbar=1,location=1");   
} 

