/**
 * @author Lewis Dyer
 */
var myModule = function(){

    var options;
    var IMAGEDROP = '.products_right';
    var IMAGELIST = '.products_left';
    var SELECTED_item = 'selected';
    var NOTSELECTED_item = 'notselected';
    var defaultimg = 'product04';
    var imagelst = {};
    
    //"private" method:
    var startevents = function(){
		
        $(IMAGELIST + ' ul li a').hover(function(){
        
            var nodes, id, index;
            
            nodes = $(IMAGELIST + ' ul li a.' + SELECTED_item);
            $.each(nodes, function(){
                $(this).removeClass(SELECTED_item);
                $(this).addClass(NOTSELECTED_item);
            });
            
            $(this).removeClass('notselected').addClass('selected');
            
            
            //change image
            id = $(this).attr('id').toString();
            index = id.split('_');
            id = options.prefix+index[2]+'_div';
            
            nodes = $(IMAGEDROP + ' div');
            $.each(nodes, function(){
                $(this).css('display', 'none')
            });
            
            $.each(nodes, function(){
                if ($(this).attr('id') === id) {
                    $(this).css('display', 'block');
                    //$(this).show('slow');	
                }
            });
        });
    };
    return {
        init: function(opt){
            options = opt; // bind options
            var imageslst = [];
            jQuery.each(opt.images_ary, function(){
                imageslst.push(this.toString());
            });
            
			$.preload(imageslst, {
                base: options.folder,
                ext: options.ext,
                onComplete: function(data){
  					var img = '<img src="' + data.image + '" />';
					$('#'+data.original+'_div').children('a').append(img);
					if (data.original !== defaultimg) {
                        $('#'+data.original+'_div').css('display','none');
                    }
				},
                onFinish: function(){
                    startevents();
                }
            });
            
        }
        
    };
}(); // the parens here cause the anonymous function to execute and return



