/**
 * 
 * @param {String} $deck
 * @param {String} $thumb
 * @param {String} $packContainer
 * @classDescription Class to manage interface of OMO product Pack view 
 */
var PackView = {
	_thumbs:'',
	_deck:'',
	_packContainer:'',
	_packContent:'',
	_active:0,
	//functions
	init:function($deck,$thumb,$packContainer,$packContent){
		this._packContent = jQuery('.pack-image-full');
		
		//deck inicialization
		this._deck = jQuery($deck);
		this._deck
			//add function to onload trigger
			.load(function () {
				PackView._packContent.hide();
				jQuery(this).fadeIn();
				jQuery(this).parent().find(".ampliar").fadeIn();
				
			})
			//if there was an error loading the image, react accordingly
			.error(function () {
				alert("Imagem não encontrada!");
			});
			
		this._deck.loadDeck = function($src){			
			jQuery(this).hide();
			jQuery(this).attr('src', $src);
			jQuery(this).click(function(){
				PackView._packContainer.loadPack(PackView._thumbs[PackView._active].param.full);
			});
			/*jQuery(this).parent().find(".ampliar").click(function(){
				PackView._packContainer.loadPack(PackView._thumbs[PackView._active].param.full);
			});*/
		};
		
		//pack draggable inicialization
		this._packContainer = jQuery($packContainer);
		
		jQuery(this._packContainer).draggable({scroll: false });
		
		this._packContainer
			//add function to onload trigger
			.load(function () {
				PackView._packContent.fadeIn().css({
					top:'-30%',
					left:'-30%',
					width: 'auto',
					height: 'auto'
				});
				
			})
			//if there was an error loading the image, react accordingly
			.error(function () {
				alert("Imagem não encontrada!\n"+jQuery(this).attr('src'));
			});
		
		this._packContainer.loadPack = function($full){
			PackView._packContent.hide();
			PackView._deck.hide().parent().find(".ampliar").hide();
			jQuery(this).attr('src', $full);
		};
		
		//setup thumbs variables
		this._thumbs = jQuery($thumb);
		
		for(i = 0; i < this._thumbs.length; i++){
			this._thumbs[i].param = {
				large:jQuery(this._thumbs[i]).find('.large').text(),
				full:jQuery(this._thumbs[i]).find('.full').text(),
				order:jQuery(this._thumbs[i]).find('.order').text()
			};
			
			jQuery(this._thumbs[i]).click(function(){				
				PackView._active = this.param.order;
				//PackView._deck.loadDeck(this.param.large,this.param.full);
				PackView._packContainer.loadPack(PackView._thumbs[PackView._active].param.full);
				return false;
			});
		}
		
		//this._deck.loadDeck(this._thumbs[this._active].param.full);
		PackView._packContainer.loadPack(PackView._thumbs[PackView._active].param.full);
		
		jQuery('.close-box').click(function(){
			tb_remove();
		});
	},
	open : function(n){
		tb_show('', '#TB_inline?height=500&amp;width=650&amp;inlineId=packViewWidget&amp;modal=true')
		PackView._packContainer.loadPack(PackView._thumbs[ n ].param.full);
		$('#TB_overlay').height( $('.main-wrapper').height() )
	}
};