//used on product group and find result pages
//uses div with id "jqm-loading" and an inner div in this
//changes url to the popup page with no menu etc
$(function(){
	var loadhref = function(jqmHash){
		$('#jqm-loading').css('height','');
		$("body").addClass("lightbox");
		$('p.jqmClose').show();
		jqmHash.w.show();
		$('ul#imagerotator').cycle('pause'); // pause animating banner
	};
	
	var loaded = function(jqmHash){
	/*
		$('p.jqmClose').hide();
		$('#jqm-loading').animate({height:'600px'},'slow',function(){
			$(this).css('height','');
			$("body").addClass("lightbox");
			$('p.jqmClose').show();
		});
		*/
		/*
		$('#jqm-loading').css('height','');
		$("body").addClass("lightbox");
		$('p.jqmClose').show();
		*/
	};
	
	var closemodal = function(jqmHash){
		$("body").removeClass("lightbox");
		$('#jqm-loading object').remove(); // replacing flash directly crashes ie6
		jqmHash.w.find('div').html('<p class="loading">Loading&hellip;</p>');
		jqmHash.o.remove();
		jqmHash.w.hide();
		$('ul#imagerotator').cycle('resume'); // resume cycling banner
	};
	
	
	// Populate jqm attribute with ajax url
	$('a.popup').each(function(){
		$(this).attr('jqm',$(this).attr('href').replace(/MediaDetail/i,'MediaDetailPopup'))
	}).click(function(){
		return false; // Prevent default action of clicking link
	});	
	
	// Assign browser specific modal popup behaviour to links
	var thisClass = 'jqmOverlay';
	if($.browser.mozilla){
		thisClass = 'ffOverlay'; // avoids mac firefox bug with flash and opacity
	}
	
	$('#jqm-loading')
		.jqm({
			overlayClass: thisClass, 
			zIndex: 10002, 
			trigger: 'a.popup',
			ajax: '@jqm', // ajax url from link attribute set above
			onShow: loadhref,
			onHide: closemodal,
			onLoad: loaded,
			target: 'div'
		});
});


