jQuery(document).ready(
 function(){
	flipImg=function(){
		var src=this.src;
		var a=src.split('.');
		var ext=a.pop();
		var b=a.join('.').split('/');
		var file=b.pop();
		var path=b.join('/');
		if((/^\d+$/).test(file)){
			this.src=path+'/'+file+'b.'+ext;
		}
		else if((/^\d+b$/).test(file)){
			this.src=path+'/'+file.replace(/b$/,'')+'.'+ext;
		}
	}
	
	productDetailsOnImg=function(){
		var src=this.src;
		var a=src.split('.');
		var ext=a.pop();
		var b=a.join('.').split('/');
		var file=b.pop();
		var dir=b.pop();
		var id=file.replace(/b$/,'');
		var path=b.join('/')+'/'+dir;
		if((/^\d+$/).test(id) && (/^40g?$/).test(dir)){
			var onDomReady = function(){
				jQuery('#jqm img').each(function(){
				 preloadImgB.apply(this);
				});
				
				jQuery('#jqm img').mouseover(function(){
				 flipImg.apply(this);
				});
				
				jQuery('#jqm img').mouseout(function(){
				 flipImg.apply(this);
				});
			};
			jQuery('#jqm').jqm({
				ajax:'http://'+location.host+'/components/com_arany/ajax_product_details.php?id='+id,
				modal:true,
				toTop:true,
				onLoad:onDomReady
			});
			jQuery('#jqm').jqmShow();
			jQuery('#jqm').jqmAddClose('.jqmOverlay');
			
		}
	}
	
	preloadImgB=function(){
		var src=this.src;
		var a=src.split('.');
		var ext=a.pop();
		var b=a.join('.').split('/');
		var file=b.pop();
		var path=b.join('/');
		if((/^\d+$/).test(file)){
			var preimg=new Image(1,1);
			preimg.src=path+'/'+file+'b.'+ext;
		}
	}
	
	jQuery('img').each(function(){
	 preloadImgB.apply(this);
	});
	
	jQuery('img').mouseover(function(){
	 flipImg.apply(this);
	});
	
	jQuery('img').mouseout(function(){
	 flipImg.apply(this);
	});
	
	jQuery('img').mouseup(function(){
	 productDetailsOnImg.apply(this);
	});
	
 }
);