/**
 * Module Group: AI AL AT
 * Controller JavaScript
 */

var C4GTI = C4GTI || {};
C4GTI.AT = C4GTI.AT || {};

C4GTI.AT.Model = C4GTI.AT.Model || {};
C4GTI.AT.View = C4GTI.AT.View || {};
C4GTI.AT.Controller = C4GTI.AT.Controller || {};

/* Data and state storage */
C4GTI.AT.Model = ( function($) {
	
	var _config = {
		"modulesIDs":["moduleID-AI04"],
		"moduleID":"moduleID-AL07"
	};
	
	return {
		getConfig:function() {
			return _config;
		}
			
	};

})(jQuery);

C4GTI.AT.View = ( function($) {

	var Model = C4GTI.AT.Model;
	var Controller = C4GTI.AT.Controller;
	_updateAL07 = function(args) {
		$("."+args + " .linklist li a.more").each(function() {
			if($(this).text().match(/Buy/i)) {
				$(this).html("<span>"+$(this).text()+"</span>");
				$(this).removeClass("more");
				$(this).addClass("buylink");
			}
		})
		
	};
	
	_update = function(args) {
		
		for(var moduleID in args) {
			if (typeof args[moduleID] != "function") {
				
				$("."+args[moduleID]).each(function() {
					
					var imageObj = $(".openbox img",this);
					if (imageObj.length > 0) {
						var imageSrc = imageObj.attr("src");
						var imageAlt = imageObj.attr("alt");
						var imageMain = imageSrc.replace(/_A4|_A3/, '');
						$(".image", this).html("<a href='" + imageMain + "' title='" + imageAlt + "' rel='lightbox'>" +
						"<img src='" +
						imageSrc +
						"' alt='" +
						imageAlt +
						"' />" +
						"<span>&nbsp;</span>" +
						"</a>");
						$(this).videoBox(this, true);
					}
				});
				
			}
			
		}
	};
	
	return {
		update: function(args){
			return _update(args);
		},
		updateAL07: function(args){
			return _updateAL07(args);
		}
	};

})(jQuery);

C4GTI.AT.Controller = ( function($) {

	var View = C4GTI.AT.View;
	var Model= C4GTI.AT.Model;
	_init = function() {
		
		View.update(Model.getConfig().modulesIDs);	
		View.updateAL07(Model.getConfig().moduleID);	
	};	
	return {
		init:function(){
			return _init();
		}
	};

})(jQuery);

$(document).ready(function() {
	if("AT" in C4GTI) {
		C4GTI.AT.Controller.init();
	}
});



